Merge lp:~ted/snapcraft/status into lp:~snappy-dev/snapcraft/core

Proposed by Ted Gould
Status: Needs review
Proposed branch: lp:~ted/snapcraft/status
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 57 lines (+18/-2)
3 files modified
snapcraft/cmds.py (+7/-0)
snapcraft/main.py (+3/-0)
snapcraft/plugin.py (+8/-2)
To merge this branch: bzr merge lp:~ted/snapcraft/status
Reviewer Review Type Date Requested Status
Leo Arias (community) Needs Fixing
Review via email: mp+267864@code.launchpad.net

Commit message

Add status command to query parts

Description of the change

Small 'status' command to find the state of the parts. Working with snapcraft and kept feeling I needed this to figure out what was going on.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

Please use logger.info instead of print.
Also for consistency it would be nice if you use single quotes. The code in snapcraft uses single and double quotes, so it would be nice to start changing this practice.

You didn't change this line, but you probably should:

47 except Exception:

I think that what you want to catch in there is the OSError.

And you are missing the tests in this branch. At least for some states it should be easy to write the tests. For some you might need to fake the state, which shouldn't be hard either. Ping me if you need a hand here.

review: Needs Fixing

Unmerged revisions

133. By Ted Gould

Fix tests'

132. By Ted Gould

Add a small status command to get the status of parts

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/cmds.py'
2--- snapcraft/cmds.py 2015-08-05 14:38:33 +0000
3+++ snapcraft/cmds.py 2015-08-12 19:00:32 +0000
4@@ -53,6 +53,13 @@
5 sys.exit(0)
6
7
8+def status(args):
9+ config = snapcraft.yaml.Config()
10+ print("status:")
11+ for part in config.all_parts:
12+ print(" {0}: {1}".format(part.plugin_name, part.state()))
13+
14+
15 def shell(args):
16 config = snapcraft.yaml.Config()
17 common.env = config.stage_env()
18
19=== modified file 'snapcraft/main.py'
20--- snapcraft/main.py 2015-07-30 14:45:01 +0000
21+++ snapcraft/main.py 2015-08-12 19:00:32 +0000
22@@ -45,6 +45,9 @@
23 parser.add_argument('userCommand', nargs=argparse.REMAINDER, metavar='cmd', help='optional command to run inside staging environment')
24 parser.set_defaults(func=snapcraft.cmds.shell)
25
26+ parser = subparsers.add_parser('status', help='print status of parts', parents=[cmd_parser])
27+ parser.set_defaults(func=snapcraft.cmds.status)
28+
29 parser = subparsers.add_parser('run', help='run snap in kvm', add_help=False)
30 parser.set_defaults(func=snapcraft.cmds.run)
31
32
33=== modified file 'snapcraft/plugin.py'
34--- snapcraft/plugin.py 2015-08-05 14:25:54 +0000
35+++ snapcraft/plugin.py 2015-08-12 19:00:32 +0000
36@@ -141,13 +141,19 @@
37 def notify_stage(self, stage, hint=''):
38 logger.info(stage + " " + self.part_names[0] + hint)
39
40- def is_dirty(self, stage):
41+ def state(self):
42 try:
43 with open(self.statefile, 'r') as f:
44 lastStep = f.read()
45- return common.COMMAND_ORDER.index(stage) > common.COMMAND_ORDER.index(lastStep)
46+ return lastStep
47 except Exception:
48+ return 'init'
49+
50+ def is_dirty(self, stage):
51+ state = self.state()
52+ if state is 'init':
53 return True
54+ return common.COMMAND_ORDER.index(stage) > common.COMMAND_ORDER.index(state)
55
56 def should_stage_run(self, stage, force):
57 if not force and not self.is_dirty(stage):

Subscribers

People subscribed via source and target branches

to all changes: