39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import sys
|
|
|
|
from .builder import Builder, ImageExistsError, ImageNotFoundError
|
|
from .packer import Packer, PackageExistsError
|
|
|
|
class Image:
|
|
def __init__(self, lxcfile):
|
|
self.name = None
|
|
self.path = None
|
|
self.conf = {}
|
|
self.lxcfile = lxcfile
|
|
self.build_dir = os.path.dirname(lxcfile)
|
|
|
|
def build_and_pack(self, force=False):
|
|
self.conf['build'] = True
|
|
try:
|
|
builder = Builder()
|
|
builder.build(self, force)
|
|
# In case of successful build, packaging needs to be forced to prevent outdated packages
|
|
force = True
|
|
except ImageExistsError as e:
|
|
print('Image {} already exists, skipping build tasks'.format(e))
|
|
except ImageNotFoundError as e:
|
|
print('Image {} not found, can\'t build {}'.format(e, self.name))
|
|
builder.clean()
|
|
sys.exit(1)
|
|
except:
|
|
builder.clean()
|
|
raise
|
|
try:
|
|
packer = Packer()
|
|
packer.pack_image(self, force)
|
|
except PackageExistsError as e:
|
|
print('Package {} already exists, skipping packaging tasks'.format(e))
|
|
del self.conf['build']
|