Calendar: remove past event
[tails/test.git] / bin / idf-content
blobdbdf32868780fd7cd7a5f229158db4e017e6ea7a
1 #! /usr/bin/python3
3 import hashlib
4 import io
5 import json
6 import sys
8 from pathlib import Path, PurePath
10 def sha256_file(filename):
11     sha256 = hashlib.sha256()
12     with io.open(filename, mode="rb") as fd:
13         content = fd.read()
14         sha256.update(content)
15     return sha256.hexdigest()
17 def to_json(data):
18     return json.dumps(data, indent=4, sort_keys=True)
20 def target_file_url(channel, filename):
21     basename = PurePath(filename).name
22     return '%(baseurl)s/%(channel)s/%(subdir)s/%(basename)s' % {
23         'baseurl':  'http://dl.amnesia.boum.org/tails',
24         'channel':  channel,
25         'subdir':   PurePath(basename).stem,
26         'basename': basename,
27     }
29 def idf_content(build_target, channel, product_name, version, img, iso):
30     return to_json({
31         'build_target':  build_target,
32         'channel':       channel,
33         'product-name':  product_name,
34         'installations': [{
35             'version': version,
36             'installation-paths': [
37                 {
38                     'type': 'img',
39                     'target-files': [{
40                         'url':    target_file_url(channel, img),
41                         'sha256': sha256_file(img),
42                         'size':   Path(img).stat().st_size,
43                     }],
44                 },
45                 {
46                     'type': 'iso',
47                     'target-files': [{
48                         'url':    target_file_url(channel, iso),
49                         'sha256': sha256_file(iso),
50                         'size':   Path(iso).stat().st_size,
51                     }],
52                 },
53             ],
54         }],
55     })
57 if __name__ == '__main__':
58     import argparse
59     parser = argparse.ArgumentParser()
60     parser.add_argument('--build-target', dest='build_target', default='amd64')
61     parser.add_argument('--channel', default='stable')
62     parser.add_argument('--product-name', dest='product_name', default='Tails')
63     parser.add_argument('--version', default=None, required=True,
64                         help='Version of Tails .')
65     parser.add_argument('--img', default=None, required=True,
66                         help='Path to the USB image.')
67     parser.add_argument('--iso', default=None, required=True,
68                         help='Path to the ISO file.')
69     args = parser.parse_args()
71     print(idf_content(build_target=args.build_target,
72                       channel=args.channel,
73                       product_name=args.product_name,
74                       version=args.version,
75                       img=args.img,
76                       iso=args.iso))