|
|
@ -1,26 +1,35 @@
|
|
|
|
#!/usr/bin/python3
|
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Usage: snap-seed-parse ${chroot_dir} > somefile.manifest
|
|
|
|
Usage: snap-seed-parse [${chroot_dir}] <output file>
|
|
|
|
|
|
|
|
|
|
|
|
This script looks for a seed.yaml path in the given root directory, parsing
|
|
|
|
This script looks for a seed.yaml path in the given root directory, parsing
|
|
|
|
it and printing generated manifest lines to stdout for easy redirection.
|
|
|
|
it and appending the parsed lines to the given output file.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The $chroot_dir argument is optional and will default to the empty string.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
import os.path
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
import yaml
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def log(msg):
|
|
|
|
def log(msg):
|
|
|
|
sys.stderr.write("snap-seed-parse: {}\n".format(msg))
|
|
|
|
print("snap-seed-parse: {}".format(msg))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("Parsing seed.yaml")
|
|
|
|
log("Parsing seed.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
CHROOT_ROOT = sys.argv[1] if len(sys.argv) > 1 and len(sys.argv[1]) > 0 \
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
else ''
|
|
|
|
parser.add_argument('chroot', nargs='?', default='',
|
|
|
|
|
|
|
|
help='root dir for the chroot from which to generate the '
|
|
|
|
|
|
|
|
'manifest')
|
|
|
|
|
|
|
|
parser.add_argument('file', help='Output manifest to this file')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ARGS = parser.parse_args()
|
|
|
|
|
|
|
|
CHROOT_ROOT = ARGS.chroot
|
|
|
|
|
|
|
|
FNAME = ARGS.file
|
|
|
|
|
|
|
|
|
|
|
|
# Trim any trailing slashes for correct appending
|
|
|
|
# Trim any trailing slashes for correct appending
|
|
|
|
log("CHROOT_ROOT: {}".format(CHROOT_ROOT))
|
|
|
|
log("CHROOT_ROOT: {}".format(CHROOT_ROOT))
|
|
|
@ -43,14 +52,17 @@ else:
|
|
|
|
with open(YAML_PATH, 'r') as fh:
|
|
|
|
with open(YAML_PATH, 'r') as fh:
|
|
|
|
yaml_lines = yaml.safe_load(fh)['snaps']
|
|
|
|
yaml_lines = yaml.safe_load(fh)['snaps']
|
|
|
|
|
|
|
|
|
|
|
|
# Loop over dict items, outputting one manifest line from each triplet
|
|
|
|
log('Writing manifest to {}'.format(FNAME))
|
|
|
|
for item in yaml_lines:
|
|
|
|
|
|
|
|
filestring = item['file']
|
|
|
|
with open(FNAME, 'a+') as fh:
|
|
|
|
# Pull the revision number off the file name
|
|
|
|
for item in yaml_lines:
|
|
|
|
revision = filestring[filestring.rindex('_')+1:]
|
|
|
|
filestring = item['file']
|
|
|
|
revision = re.sub(r'[^0-9]', '', revision)
|
|
|
|
# Pull the revision number off the file name
|
|
|
|
print("{}{}\t{}\t{}".format(LINE_PREFIX,
|
|
|
|
revision = filestring[filestring.rindex('_')+1:]
|
|
|
|
item['name'],
|
|
|
|
revision = re.sub(r'[^0-9]', '', revision)
|
|
|
|
item['channel'],
|
|
|
|
fh.write("{}{}\t{}\t{}\n".format(LINE_PREFIX,
|
|
|
|
revision,
|
|
|
|
item['name'],
|
|
|
|
))
|
|
|
|
item['channel'],
|
|
|
|
|
|
|
|
revision,
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
log('Manifest output finished.')
|
|
|
|