4
Usage: snap-seed-parse ${chroot_dir} > somefile.manifest
6
This script looks for a seed.yaml path in the given root directory, parsing
7
it and printing generated manifest lines to stdout for easy redirection.
17
sys.stderr.write("snap-seed-parse: {}\n".format(msg))
20
log("Parsing seed.yaml")
22
CHROOT_ROOT = sys.argv[1] if len(sys.argv) > 1 and len(sys.argv[1]) > 0 \
25
# Trim any trailing slashes for correct appending
26
log("CHROOT_ROOT: {}".format(CHROOT_ROOT))
27
if len(CHROOT_ROOT) > 0 and CHROOT_ROOT[-1] == '/':
28
CHROOT_ROOT = CHROOT_ROOT[:-1]
30
# This is where we expect to find the seed.yaml file
31
YAML_PATH = CHROOT_ROOT + '/var/lib/snapd/seed/seed.yaml'
33
# Snaps are prepended with this string in the manifest
36
log("yaml path: {}".format(YAML_PATH))
37
if not os.path.isfile(YAML_PATH):
38
log("WARNING: yaml path not found; no seeded snaps found.")
41
log("yaml path found.")
43
with open(YAML_PATH, 'r') as fh:
44
yaml_lines = yaml.safe_load(fh)['snaps']
46
# Loop over dict items, outputting one manifest line from each triplet
47
for item in yaml_lines:
48
filestring = item['file']
49
# Pull the revision number off the file name
50
revision = filestring[filestring.rindex('_')+1:]
51
revision = re.sub(r'[^0-9]', '', revision)
52
print("{}{}\t{}\t{}".format(LINE_PREFIX,