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
|
|
|
|
2019-10-05 22:26:54 +02:00
|
|
|
from .apppacker import AppPacker
|
|
|
|
from .imagebuilder import ImageNotFoundError
|
2019-09-20 10:13:41 +02:00
|
|
|
|
|
|
|
class App:
|
2019-10-05 22:26:54 +02:00
|
|
|
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)
|
|
|
|
|
2019-10-05 22:26:54 +02:00
|
|
|
def pack(self, metafile):
|
|
|
|
self.load_metafile(metafile)
|
|
|
|
packer = AppPacker(self)
|
2019-09-20 15:43:01 +02:00
|
|
|
try:
|
2019-10-05 22:26:54 +02:00
|
|
|
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)
|
2019-10-05 22:26:54 +02:00
|
|
|
|
|
|
|
def remove(self):
|
|
|
|
packer = AppPacker(self)
|
|
|
|
packer.remove()
|