Merge lp:~zyga/lava-dashboard-tool/better-pull into lp:lava-dashboard-tool/linaro-11.05

Proposed by Zygmunt Krynicki
Status: Merged
Merged at revision: 133
Proposed branch: lp:~zyga/lava-dashboard-tool/better-pull
Merge into: lp:lava-dashboard-tool/linaro-11.05
Diff against target: 90 lines (+53/-7)
1 file modified
launch_control_tool/commands/dashboard.py (+53/-7)
To merge this branch: bzr merge lp:~zyga/lava-dashboard-tool/better-pull
Reviewer Review Type Date Requested Status
Dave Pigott Pending
Linaro Validation Team Pending
Review via email: mp+59360@code.launchpad.net

Description of the change

Better UI and features for pull. See commit messages for more.

To post a comment you must log in.
142. By Zygmunt Krynicki

Treat 0 bytes and None bytes the same

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launch_control_tool/commands/dashboard.py'
2--- launch_control_tool/commands/dashboard.py 2011-04-11 08:28:43 +0000
3+++ launch_control_tool/commands/dashboard.py 2011-04-28 12:29:37 +0000
4@@ -317,7 +317,7 @@
5 default_dashboard_url = os.getenv("DASHBOARD_URL")
6 if default_dashboard_url:
7 group.add_argument("--dashboard-url",
8- metavar="URL", help="URL of your validation dashboard",
9+ metavar="URL", help="URL of your validation dashboard (%(default)s)",
10 default=default_dashboard_url)
11 else:
12 group.add_argument("--dashboard-url", required=True,
13@@ -707,25 +707,71 @@
14 def register_arguments(cls, parser):
15 group = super(pull, cls).register_arguments(parser)
16 group.add_argument("--remote-dashboard-url", required=True,
17- metavar="REMOTE_URL", help="URL of the remote validation dashboard")
18+ metavar="URL", help="URL of the remote validation dashboard")
19+ group.add_argument("STREAM", nargs="*", help="Streams to pull from (all by default)")
20+
21+ @staticmethod
22+ def _filesizeformat(num_bytes):
23+ """
24+ Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
25+ 102 num_bytes, etc).
26+ """
27+ try:
28+ num_bytes = float(num_bytes)
29+ except (TypeError,ValueError,UnicodeDecodeError):
30+ return "%(size)d byte", "%(size)d num_bytes" % {'size': 0}
31+
32+ filesize_number_format = lambda value: "%0.2f" % (round(value, 1),)
33+
34+ if num_bytes < 1024:
35+ return "%(size)d bytes" % {'size': num_bytes}
36+ if num_bytes < 1024 * 1024:
37+ return "%s KB" % filesize_number_format(num_bytes / 1024)
38+ if num_bytes < 1024 * 1024 * 1024:
39+ return "%s MB" % filesize_number_format(num_bytes / (1024 * 1024))
40+ return "%s GB" % filesize_number_format(num_bytes / (1024 * 1024 * 1024))
41
42 def invoke_remote(self):
43 self._check_server_version(self.server, "0.3.0.candidate.9")
44 print "Checking local and remote streams"
45 remote = self.remote_server.streams()
46+ if self.args.STREAM:
47+ # Check that all requested streams are available remotely
48+ requested_set = frozenset(self.args.STREAM)
49+ remote_set = frozenset((stream["pathname"] for stream in remote))
50+ unavailable_set = requested_set - remote_set
51+ if unavailable_set:
52+ print >>sys.stderr, "Remote stream not found: %s" % ", ".join(unavailable_set)
53+ return -1
54+ # Limit to requested streams if necessary
55+ remote = [stream for stream in remote if stream["pathname"] in requested_set]
56 local = self.server.streams()
57 missing_pathnames = set([stream["pathname"] for stream in remote]) - set([stream["pathname"] for stream in local])
58 for stream in remote:
59+ local_bundles = [bundle for bundle in self.server.bundles(stream["pathname"])]
60+ remote_bundles = [bundle for bundle in self.remote_server.bundles(stream["pathname"])]
61+ missing_bundles = set((bundle["content_sha1"] for bundle in remote_bundles)) - set((bundle["content_sha1"] for bundle in local_bundles))
62+ try:
63+ missing_bytes = sum((bundle["content_size"] for bundle in remote_bundles if bundle["content_sha1"] in missing_bundles))
64+ except KeyError as ex:
65+ # Older servers did not return content_size so this part is optional
66+ missing_bytes = None
67+ if missing_bytes:
68+ print "Stream %s needs update (%s)" % (stream["pathname"], self._filesizeformat(missing_bytes))
69+ elif missing_bundles:
70+ print "Stream %s needs update" % (stream["pathname"],)
71+ else:
72+ print "Stream %s is up to date" % (stream["pathname"],)
73 if stream["pathname"] in missing_pathnames:
74- print "Creating missing stream %s" % stream["pathname"]
75 self.server.make_stream(stream["pathname"], stream["name"])
76- local_bundles = [bundle["content_sha1"] for bundle in self.server.bundles(stream["pathname"])]
77- remote_bundles = [bundle["content_sha1"] for bundle in self.remote_server.bundles(stream["pathname"])]
78- missing_bundles = set(remote_bundles) - set(local_bundles)
79 for content_sha1 in missing_bundles:
80- print "Pulling bundle %s" % content_sha1
81+ print "Getting %s" % (content_sha1,),
82+ sys.stdout.flush()
83 data = self.remote_server.get(content_sha1)
84+ print "got %s, storing" % (self._filesizeformat(len(data["content"]))),
85+ sys.stdout.flush()
86 self.server.put(data["content"], data["content_filename"], stream["pathname"])
87+ print "done"
88
89
90 class data_views(ExperimentalCommandMixIn, XMLRPCCommand):

Subscribers

People subscribed via source and target branches

to all changes: