Spotter-VM/build/usr/lib/python3.6/lxcbuild/app.py

37 lines
953 B
Python
Raw Normal View History

2019-09-20 10:13:41 +02:00
# -*- coding: utf-8 -*-
2019-09-20 15:43:01 +02:00
import json
2019-09-20 10:13:41 +02:00
import os
2019-09-20 15:43:01 +02:00
import sys
2019-09-20 10:13:41 +02:00
from .apppacker import AppPacker
from .imagebuilder import ImageNotFoundError
2019-09-20 10:13:41 +02:00
class App:
def __init__(self):
self.name = None
self.conf = {}
self.build_dir = None
def load_metafile(self, metafile):
2019-09-20 10:13:41 +02:00
self.build_dir = os.path.dirname(metafile)
2019-09-20 15:43:01 +02:00
if os.path.basename(metafile) == 'meta':
self.name = os.path.basename(self.build_dir)
else:
self.name = os.path.splitext(metafile)[0]
2019-09-20 10:13:41 +02:00
with open(metafile, 'r') as f:
self.conf = json.load(f)
def pack(self, metafile):
self.load_metafile(metafile)
packer = AppPacker(self)
2019-09-20 15:43:01 +02:00
try:
packer.pack()
2019-09-20 15:43:01 +02:00
except ImageNotFoundError as e:
print('Image {} not found, can\'t pack {}'.format(e, self.name))
sys.exit(1)
def remove(self):
packer = AppPacker(self)
packer.remove()