Allow scratch builds with dir as argument

This commit is contained in:
Disassembler 2019-10-05 23:09:30 +02:00
parent 93cc9f435b
commit 466a83e407
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
3 changed files with 22 additions and 17 deletions

View File

@ -20,7 +20,7 @@ if len(sys.argv) < 2:
sys.exit(1)
args = parser.parse_args()
def build_and_pack_image(args, path):
def build_and_pack_image(path, args):
image = Image()
image.force_build = args.force or args.scratch
image.scratch_build = args.scratch
@ -44,7 +44,7 @@ else:
if os.path.isfile(buildpath):
basename = os.path.basename(buildpath)
if basename == 'lxcfile' or basename.endswith('.lxcfile'):
build_and_pack_image(args, buildpath)
build_and_pack_image(buildpath, args)
# Compose files needs to be ignored when performing scratch builds
elif not args.scratch and basename == 'meta':
pack_app(buildpath)
@ -54,16 +54,21 @@ else:
# If the buildpath is a directory, build as much as possible, unless scratch build was requested, in which case don't build anything
else:
if args.scratch:
print('Please specify an lxcfile for scratch build')
sys.exit(1)
valid_dir = False
for entry in os.scandir(buildpath):
if entry.is_file() and (entry.name == 'lxcfile' or entry.name.endswith('.lxcfile')):
lxcfile = os.path.join(buildpath, 'lxcfile')
if os.path.exists(lxcfile):
build_and_pack_image(lxcfile, args)
else:
print('Please specify an lxcfile for scratch build')
sys.exit(1)
else:
valid_dir = False
for entry in os.scandir(buildpath):
if entry.is_file() and (entry.name == 'lxcfile' or entry.name.endswith('.lxcfile')):
valid_dir = True
build_and_pack_image(entry.path, args)
meta = os.path.join(buildpath, 'meta')
if os.path.exists(meta):
valid_dir = True
build_and_pack_image(args, entry.path)
meta = os.path.join(buildpath, 'meta')
if os.path.exists(meta):
valid_dir = True
pack_app(meta)
if not valid_dir:
print('Directory {} doesn\'t contain anything to build, skipping'.format(buildpath))
pack_app(meta)
if not valid_dir:
print('Directory {} doesn\'t contain anything to build, skipping'.format(buildpath))

View File

@ -47,7 +47,7 @@ class AppPacker(Packer):
def register(self):
# Register package in global repository metadata file
print('Registering package', self.app.name)
print('Registering application package', self.app.name)
self.packages['apps'][self.app.name] = self.app.conf.copy()
self.packages['apps'][self.app.name]['size'] = self.tar_size
self.packages['apps'][self.app.name]['pkgsize'] = self.xz_size

View File

@ -40,13 +40,13 @@ class ImagePacker(Packer):
def create_archive(self):
# Create archive
print('Archiving', self.image.name)
print('Archiving image', self.image.name)
subprocess.run(['tar', '--xattrs', '-cpf', self.tar_path, self.image.name], cwd=LXC_STORAGE_DIR)
self.compress_archive()
def register(self):
# Register image in global repository metadata file
print('Registering package', self.image.name)
print('Registering image package', self.image.name)
self.packages['images'][self.image.name] = self.image.conf.copy()
self.packages['images'][self.image.name]['size'] = self.tar_size
self.packages['images'][self.image.name]['pkgsize'] = self.xz_size