Merge lp:~mvo/ubuntu-system-image/json-output into lp:~registry/ubuntu-system-image/client

Proposed by Michael Vogt
Status: Rejected
Rejected by: Barry Warsaw
Proposed branch: lp:~mvo/ubuntu-system-image/json-output
Merge into: lp:~registry/ubuntu-system-image/client
Diff against target: 73 lines (+17/-2)
3 files modified
systemimage/config.py (+2/-0)
systemimage/download.py (+6/-1)
systemimage/main.py (+9/-1)
To merge this branch: bzr merge lp:~mvo/ubuntu-system-image/json-output
Reviewer Review Type Date Requested Status
Registry Administrators Pending
Review via email: mp+251226@code.launchpad.net

Description of the change

This branch implements --json-ouput as described in bug #1423622.

Note that I did not test this yet, I have a bit of difficulties with
that. When I run "tox" on trunk I get all sorts of errors on my vivid
box that look unrelated. I also could not find a debian/ packaging
branch to test for real. Pointers appreciated :) I'm happy to do more
serious testing once I figured the testsuite and the debian/ dir out.

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

I'd love to know what problems you had with tox. Be sure you have all the build dependencies though: `sudo apt-get build-dep system-image` should install them all (except for the new pycurl dependencies w/3.0, but I bet you already have those)

Normally, the packaging branch is here: bzr+ssh://bazaar.launchpad.net/~ubuntu-managed-branches/ubuntu-system-image/system-image/

But I am working on an mp for that to build si 3.0: bzr+ssh://bazaar.launchpad.net/~barry/ubuntu-system-image/citrain30beta/

Yeah, it's kind of schizophrenic and we should probably merge the debian/ into trunk, but hysterical raisins are so delicious!

Revision history for this message
Barry Warsaw (barry) wrote :

It's a nice simple branch (without the testing :) but I wonder if we'd ever want other formats of stdout progress, and whether we should extend the existing callback mechanism to implement this.

Right now, DownloadManagerBase takes a single callback function. What if instead we could register multiple callback functions and then _do_callback() would call each in turn? It would have to make sure that errors in one callback don't affect the others of course. But then it would just be a matter of implementing the JSON-to-stdout callback and adding it to the normal downloader callback stack.

The other thought I had was about the cli u/i. Maybe `--progress=json` would be translated into adding the JSON callback to the downloader stack. Or maybe `--progress=jsonv1` just to future proof us against possible different JSON contents?

main.py already adds a single callback function (e.g. differently depending on whether verbosity == 1 or not, though that should probably be verbosity >= 1). If state.downloader.callback were a list, it could just append to it instead of assigning to it. We could even allow for `--progress=dots` and `--progress=debuglog` to handle the current cases.

Revision history for this message
Barry Warsaw (barry) wrote :

Oh yeah, and don't forget the PPA! https://launchpad.net/~barry/+archive/ubuntu/systemimage

You can always grab the packages from there and test those (I'll be sure to upload a new version once this feature lands).

Revision history for this message
Barry Warsaw (barry) wrote :

Unmerged revisions

318. By Michael Vogt

minimal implementation of --json-output

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'systemimage/config.py'
2--- systemimage/config.py 2015-02-13 21:44:50 +0000
3+++ systemimage/config.py 2015-02-27 09:33:32 +0000
4@@ -72,6 +72,8 @@
5 # This is used to plumb command line arguments from the main() to
6 # other parts of the system.
7 self.skip_gpg_verification = False
8+ # json output when using the cli
9+ self.json_output = False
10 # Cache.
11 self._device = None
12 self._build_number = None
13
14=== modified file 'systemimage/download.py'
15--- systemimage/download.py 2015-02-13 21:44:50 +0000
16+++ systemimage/download.py 2015-02-27 09:33:32 +0000
17@@ -36,7 +36,6 @@
18 except ImportError: # pragma: no cover
19 pycurl = None
20
21-
22 log = logging.getLogger('systemimage')
23
24
25@@ -133,6 +132,12 @@
26 self.callback(self.received, self.total)
27 except:
28 log.exception('Exception in progress callback')
29+ from systemimage.config import config
30+ if config.json_output:
31+ print(json.dumps({
32+ "type": "progress",
33+ "now": self.received,
34+ "total": self.total}))
35
36 def cancel(self):
37 """Cancel any current downloads."""
38
39=== modified file 'systemimage/main.py'
40--- systemimage/main.py 2015-02-09 18:46:24 +0000
41+++ systemimage/main.py 2015-02-27 09:33:32 +0000
42@@ -141,6 +141,9 @@
43 help="""Delete the key and its value. It is a no-op
44 if the key does not exist. Multiple
45 --del arguments can be given.""")
46+ parser.add_argument('--json-output',
47+ default=False, action='store_true',
48+ help="""Show json progress/error output on stdout.""")
49 # Hidden system-image-cli only feature for testing purposes. LP: #1333414
50 parser.add_argument('--skip-gpg-verification',
51 default=False, action='store_true',
52@@ -160,6 +163,9 @@
53 Your upgrades are INSECURE.""", file=sys.stderr)
54 config.skip_gpg_verification = True
55
56+ # store the json_output choice
57+ config.json_output = args.json_output
58+
59 # Perform factory and production resets.
60 if args.factory_reset:
61 factory_reset()
62@@ -347,8 +353,10 @@
63 list(state)
64 except KeyboardInterrupt: # pragma: no cover
65 return 0
66- except Exception:
67+ except Exception as e:
68 log.exception('system-image-cli exception')
69+ if config.json_output:
70+ print(json.dumps({"type": "error", "msg": str(e)}))
71 return 1
72 else:
73 return 0

Subscribers

People subscribed via source and target branches