~codyshepherd/livecd-rootfs/ubuntu-core-dev-snaps-manifest

« back to all changes in this revision

Viewing changes to live-build/snap-seed-parse.py

  • Committer: Steve Langasek
  • Date: 2018-10-26 05:08:45 UTC
  • mfrom: (1705.1.2 livecd-rootfs)
  • Revision ID: steve.langasek@canonical.com-20181026050845-zh4tpvu47qqrm6qp
MergeĀ lp:~codyshepherd/livecd-rootfs/snaps-manifest

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
 
 
3
"""
 
4
Usage: snap-seed-parse ${chroot_dir} > somefile.manifest
 
5
 
 
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.
 
8
"""
 
9
 
 
10
import re
 
11
import sys
 
12
import yaml
 
13
import os.path
 
14
 
 
15
 
 
16
def log(msg):
 
17
    sys.stderr.write("snap-seed-parse: {}\n".format(msg))
 
18
 
 
19
 
 
20
log("Parsing seed.yaml")
 
21
 
 
22
CHROOT_ROOT = sys.argv[1] if len(sys.argv) > 1 and len(sys.argv[1]) > 0 \
 
23
                          else ''
 
24
 
 
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]
 
29
 
 
30
# This is where we expect to find the seed.yaml file
 
31
YAML_PATH = CHROOT_ROOT + '/var/lib/snapd/seed/seed.yaml'
 
32
 
 
33
# Snaps are prepended with this string in the manifest
 
34
LINE_PREFIX = 'snap:'
 
35
 
 
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.")
 
39
    exit(0)
 
40
else:
 
41
    log("yaml path found.")
 
42
 
 
43
with open(YAML_PATH, 'r') as fh:
 
44
    yaml_lines = yaml.safe_load(fh)['snaps']
 
45
 
 
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,
 
53
                                        item['name'],
 
54
                                        item['channel'],
 
55
                                        revision,
 
56
                                        ))