Spotter-VM/build/usr/bin/lxcbuild

45 lines
1.4 KiB
Plaintext
Raw Normal View History

2019-09-20 10:13:41 +02:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
2019-09-20 15:43:01 +02:00
import os
2019-09-20 10:13:41 +02:00
import sys
from lxcbuild.app import App
from lxcbuild.image import Image
parser = argparse.ArgumentParser(description='VM application builder and packager')
parser.add_argument('-f', '--force', action='store_true', help='Force rebuild already built package')
parser.add_argument('buildpath', help='Either specific "lxcfile" or "meta" file or a directory containing one')
if len(sys.argv) < 2:
parser.print_usage()
sys.exit(1)
args = parser.parse_args()
buildpath = os.path.realpath(args.buildpath)
if os.path.isfile(buildpath):
basename = os.path.basename(buildpath)
if basename == 'lxcfile' or basename.endswith('.lxcfile'):
image = Image(buildpath)
image.build_and_pack(args.force)
elif basename == 'meta' or basename.endswith('.meta'):
app = App(buildpath)
app.build_and_pack()
else:
print('Unknown file {} given, expected "lxcfile" or "meta"'.format(buildpath))
sys.exit(1)
else:
valid_dir = False
lxcfile = os.path.join(buildpath, 'lxcfile')
meta = os.path.join(buildpath, 'meta')
if os.path.exists(lxcfile):
valid_dir = True
image = Image(lxcfile)
image.build_and_pack(args.force)
if os.path.exists(meta):
valid_dir = True
2019-09-20 15:43:01 +02:00
app = App(meta)
2019-09-20 10:13:41 +02:00
app.pack()
if not valid_dir:
print('Directory {} doesn\'t contain anything to build, skipping'.format(buildpath))