Merge lp:~sinzui/juju-release-tools/rewrite-devel into lp:juju-release-tools

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 208
Proposed branch: lp:~sinzui/juju-release-tools/rewrite-devel
Merge into: lp:juju-release-tools
Diff against target: 73 lines (+69/-0)
1 file modified
copy_stream.py (+69/-0)
To merge this branch: bzr merge lp:~sinzui/juju-release-tools/rewrite-devel
Reviewer Review Type Date Requested Status
Aaron Bentley (community) Approve
Review via email: mp+268079@code.launchpad.net

Description of the change

Copy the released simple streams stanza to devel to do mixed juju testing.

I offer this script without tests as a means to unblock CI for a few weeks. I have already run this like so
    ../juju-release-tools/copy_stream.py -v ./index2.json released devel
then republished streams. All the substrate tests are passing.

I intend to update the two jobs that publish testing and weekly streams to run this between assemble-streams and publish-public-tools.

To post a comment you must log in.
Revision history for this message
Aaron Bentley (abentley) wrote :

Looks reasonable. A few nitpicks that needn't block landing:
- It would be nice to use a longer variable name for the opened file, rather than 'f'.
- It would be nice if the main function was compatible with the setup.py console_scripts entry point, i.e. no mandatory parameters.
- Maybe it should error if the to_key is already present? (Or does that break your workflow?)

review: Approve
209. By Curtis Hovey

Raise an error when the to_key is already defined.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'copy_stream.py'
2--- copy_stream.py 1970-01-01 00:00:00 +0000
3+++ copy_stream.py 2015-08-14 14:16:38 +0000
4@@ -0,0 +1,69 @@
5+#!/usr/bin/python
6+
7+from __future__ import print_function
8+
9+from argparse import ArgumentParser
10+import json
11+import os
12+import sys
13+import traceback
14+
15+
16+STREAM_KEY_TEMPLATE = 'com.ubuntu.juju:{}:tools'
17+
18+
19+def copy(location, from_stream, to_stream, dry_run=False, verbose=False):
20+ with open(location, 'r') as index_file:
21+ index = json.load(index_file)
22+ from_key = STREAM_KEY_TEMPLATE.format(from_stream)
23+ to_key = STREAM_KEY_TEMPLATE.format(to_stream)
24+ if to_key in index['index']:
25+ raise ValueError('{} is already defined in {}'.format(
26+ to_key, location))
27+ stanza = dict(index['index'][from_key])
28+ index['index'][to_key] = stanza
29+ if verbose:
30+ product_path = stanza['path']
31+ print('copied {} with {} to {}'.format(
32+ from_stream, product_path, to_stream))
33+ if not dry_run:
34+ with open(location, 'w') as index_file:
35+ json.dump(index, index_file, indent=4)
36+
37+
38+def parse_args(args=None):
39+ """Return the argument parser for this program."""
40+ parser = ArgumentParser("Copy simple stream stanzas.")
41+ parser.add_argument(
42+ '-d', '--dry-run', action="store_true", default=False,
43+ help='Do not make changes.')
44+ parser.add_argument(
45+ '-v', '--verbose', action="store_true", default=False,
46+ help='Increase verbosity.')
47+ parser.add_argument(
48+ 'location', type=os.path.expanduser,
49+ help='The path to the index2.json')
50+ parser.add_argument('from_stream', help='The agent-stream to copy.')
51+ parser.add_argument('to_stream', help='The agent-stream to create.')
52+ return parser.parse_args(args)
53+
54+
55+def main(argv=None):
56+ """Copy simple stream stanzas."""
57+ args = parse_args(argv)
58+ try:
59+ copy(
60+ args.location, args.from_stream, args.to_stream,
61+ dry_run=args.dry_run, verbose=args.verbose)
62+ except Exception as e:
63+ print(e)
64+ if args.verbose:
65+ traceback.print_tb(sys.exc_info()[2])
66+ return 2
67+ if args.verbose:
68+ print("Done.")
69+ return 0
70+
71+
72+if __name__ == '__main__':
73+ sys.exit(main(sys.argv[1:]))

Subscribers

People subscribed via source and target branches