Improved logging, comments, and fixed undefined shell variable error.

This commit is contained in:
Cody Shepherd 2018-10-16 14:50:14 -07:00
parent becac6ac09
commit 3c3be06f27
No known key found for this signature in database
GPG Key ID: 0DB7E5F05C3FAB5F
3 changed files with 15 additions and 9 deletions

View File

@ -551,7 +551,7 @@ fi
# '--initramfs none' produces different manifest names. # '--initramfs none' produces different manifest names.
if [ -e "binary/$INITFS/filesystem.packages" ]; then if [ -e "binary/$INITFS/filesystem.packages" ]; then
/build/config/snap_seed_parse ${CHROOT_ROOT} >> "binary/${INITFS}/filesystem.packages" /build/config/snap_seed_parse "chroot/" >> "binary/${INITFS}/filesystem.packages"
ln "binary/$INITFS/filesystem.packages" "$PREFIX.manifest" ln "binary/$INITFS/filesystem.packages" "$PREFIX.manifest"
chmod 644 "$PREFIX.manifest" chmod 644 "$PREFIX.manifest"
fi fi

View File

@ -46,9 +46,12 @@ create_empty_disk_image() {
create_manifest() { create_manifest() {
local chroot_root=${1} local chroot_root=${1}
local target_file=${2} local target_file=${2}
(echo "create_manifest chroot_root: ${chroot_root}")
dpkg-query --show --admindir="${chroot_root}/var/lib/dpkg" > ${target_file} dpkg-query --show --admindir="${chroot_root}/var/lib/dpkg" > ${target_file}
(>&2 echo "create_manifest chroot_root: ${chroot_root}") (echo "create_manifest call to dpkg-query finished.")
/build/config/snap_seed_parse "${chroot_root}" >> ${target_file} /build/config/snap_seed_parse "${chroot_root}" >> ${target_file}
(echo "create_manifest call to snap_seed_parse finished.")
(echo "create_manifest finished")
} }
make_ext4_partition() { make_ext4_partition() {

View File

@ -20,30 +20,33 @@ log("Parsing seed.yaml")
CHROOT_ROOT = sys.argv[1] if len(sys.argv) > 1 and len(sys.argv[1]) > 0 \ CHROOT_ROOT = sys.argv[1] if len(sys.argv) > 1 and len(sys.argv[1]) > 0 \
else '' else ''
'''The chroot rooth path should be passed in by the caller''' '''The chroot rooth path should be passed in by the caller'''
log("CHROOT_ROOT: {}".format(CHROOT_ROOT))
log("CHROOT_ROOT: {}".format(CHROOT_ROOT))
if len(CHROOT_ROOT) > 0 and CHROOT_ROOT[-1] == '/': if len(CHROOT_ROOT) > 0 and CHROOT_ROOT[-1] == '/':
CHROOT_ROOT = CHROOT_ROOT[:-1] CHROOT_ROOT = CHROOT_ROOT[:-1]
'''Trim any trailing slashes for correct appending'''
YAML_PATH = CHROOT_ROOT + '/var/lib/snapd/seed/seed.yaml' YAML_PATH = CHROOT_ROOT + '/var/lib/snapd/seed/seed.yaml'
'''This is where we expect to find the seed.yaml file''' '''This is where we expect to find the seed.yaml file'''
LINE_PREFIX = 'snap:' LINE_PREFIX = 'snap:'
'''Snaps are prepended with this string in the manifest''' '''Snaps are prepended with this string in the manifest'''
log("yaml path: {}".format(YAML_PATH)) log("yaml path: {}".format(YAML_PATH))
if not os.path.isfile(YAML_PATH): if not os.path.isfile(YAML_PATH):
log("yaml path not found.") '''Exit gracefully and issue a warning if seeded snaps not found'''
exit(1) log("WARNING: yaml path not found; no seeded snaps found.")
exit(0)
else: else:
log("yaml path found.") log("yaml path found.")
# Open the seed.yaml and ingest its contents
with open(YAML_PATH, 'r') as fh: with open(YAML_PATH, 'r') as fh:
'''Open the seed.yaml and ingest its contents'''
yaml_lines = yaml.load(fh)['snaps'] yaml_lines = yaml.load(fh)['snaps']
to_write = '' to_write = ''
# Loop over dict items, generating one manifest line from each
# triplet
for item in yaml_lines: for item in yaml_lines:
'''Loop over dict items, generating one manifest line from each triplet'''
filestring = item['file'] filestring = item['file']
revision = filestring[filestring.rindex('_')+1:] revision = filestring[filestring.rindex('_')+1:]
revision = re.sub(r'[^0-9]', '', revision) revision = re.sub(r'[^0-9]', '', revision)
@ -53,5 +56,5 @@ for item in yaml_lines:
revision, revision,
) )
# write accumulated text to stdout for redirection
print(to_write.strip('\n')) print(to_write.strip('\n'))
'''write accumulated text to stdout for redirection'''