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
=== modified file 'launch_control_tool/commands/dashboard.py'
--- launch_control_tool/commands/dashboard.py 2011-04-11 08:28:43 +0000
+++ launch_control_tool/commands/dashboard.py 2011-04-28 12:29:37 +0000
@@ -317,7 +317,7 @@
317 default_dashboard_url = os.getenv("DASHBOARD_URL")317 default_dashboard_url = os.getenv("DASHBOARD_URL")
318 if default_dashboard_url:318 if default_dashboard_url:
319 group.add_argument("--dashboard-url",319 group.add_argument("--dashboard-url",
320 metavar="URL", help="URL of your validation dashboard",320 metavar="URL", help="URL of your validation dashboard (%(default)s)",
321 default=default_dashboard_url)321 default=default_dashboard_url)
322 else:322 else:
323 group.add_argument("--dashboard-url", required=True,323 group.add_argument("--dashboard-url", required=True,
@@ -707,25 +707,71 @@
707 def register_arguments(cls, parser):707 def register_arguments(cls, parser):
708 group = super(pull, cls).register_arguments(parser)708 group = super(pull, cls).register_arguments(parser)
709 group.add_argument("--remote-dashboard-url", required=True,709 group.add_argument("--remote-dashboard-url", required=True,
710 metavar="REMOTE_URL", help="URL of the remote validation dashboard")710 metavar="URL", help="URL of the remote validation dashboard")
711 group.add_argument("STREAM", nargs="*", help="Streams to pull from (all by default)")
712
713 @staticmethod
714 def _filesizeformat(num_bytes):
715 """
716 Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB,
717 102 num_bytes, etc).
718 """
719 try:
720 num_bytes = float(num_bytes)
721 except (TypeError,ValueError,UnicodeDecodeError):
722 return "%(size)d byte", "%(size)d num_bytes" % {'size': 0}
723
724 filesize_number_format = lambda value: "%0.2f" % (round(value, 1),)
725
726 if num_bytes < 1024:
727 return "%(size)d bytes" % {'size': num_bytes}
728 if num_bytes < 1024 * 1024:
729 return "%s KB" % filesize_number_format(num_bytes / 1024)
730 if num_bytes < 1024 * 1024 * 1024:
731 return "%s MB" % filesize_number_format(num_bytes / (1024 * 1024))
732 return "%s GB" % filesize_number_format(num_bytes / (1024 * 1024 * 1024))
711733
712 def invoke_remote(self):734 def invoke_remote(self):
713 self._check_server_version(self.server, "0.3.0.candidate.9")735 self._check_server_version(self.server, "0.3.0.candidate.9")
714 print "Checking local and remote streams"736 print "Checking local and remote streams"
715 remote = self.remote_server.streams()737 remote = self.remote_server.streams()
738 if self.args.STREAM:
739 # Check that all requested streams are available remotely
740 requested_set = frozenset(self.args.STREAM)
741 remote_set = frozenset((stream["pathname"] for stream in remote))
742 unavailable_set = requested_set - remote_set
743 if unavailable_set:
744 print >>sys.stderr, "Remote stream not found: %s" % ", ".join(unavailable_set)
745 return -1
746 # Limit to requested streams if necessary
747 remote = [stream for stream in remote if stream["pathname"] in requested_set]
716 local = self.server.streams()748 local = self.server.streams()
717 missing_pathnames = set([stream["pathname"] for stream in remote]) - set([stream["pathname"] for stream in local])749 missing_pathnames = set([stream["pathname"] for stream in remote]) - set([stream["pathname"] for stream in local])
718 for stream in remote:750 for stream in remote:
751 local_bundles = [bundle for bundle in self.server.bundles(stream["pathname"])]
752 remote_bundles = [bundle for bundle in self.remote_server.bundles(stream["pathname"])]
753 missing_bundles = set((bundle["content_sha1"] for bundle in remote_bundles)) - set((bundle["content_sha1"] for bundle in local_bundles))
754 try:
755 missing_bytes = sum((bundle["content_size"] for bundle in remote_bundles if bundle["content_sha1"] in missing_bundles))
756 except KeyError as ex:
757 # Older servers did not return content_size so this part is optional
758 missing_bytes = None
759 if missing_bytes:
760 print "Stream %s needs update (%s)" % (stream["pathname"], self._filesizeformat(missing_bytes))
761 elif missing_bundles:
762 print "Stream %s needs update" % (stream["pathname"],)
763 else:
764 print "Stream %s is up to date" % (stream["pathname"],)
719 if stream["pathname"] in missing_pathnames:765 if stream["pathname"] in missing_pathnames:
720 print "Creating missing stream %s" % stream["pathname"]
721 self.server.make_stream(stream["pathname"], stream["name"])766 self.server.make_stream(stream["pathname"], stream["name"])
722 local_bundles = [bundle["content_sha1"] for bundle in self.server.bundles(stream["pathname"])]
723 remote_bundles = [bundle["content_sha1"] for bundle in self.remote_server.bundles(stream["pathname"])]
724 missing_bundles = set(remote_bundles) - set(local_bundles)
725 for content_sha1 in missing_bundles:767 for content_sha1 in missing_bundles:
726 print "Pulling bundle %s" % content_sha1768 print "Getting %s" % (content_sha1,),
769 sys.stdout.flush()
727 data = self.remote_server.get(content_sha1)770 data = self.remote_server.get(content_sha1)
771 print "got %s, storing" % (self._filesizeformat(len(data["content"]))),
772 sys.stdout.flush()
728 self.server.put(data["content"], data["content_filename"], stream["pathname"])773 self.server.put(data["content"], data["content_filename"], stream["pathname"])
774 print "done"
729775
730776
731class data_views(ExperimentalCommandMixIn, XMLRPCCommand):777class data_views(ExperimentalCommandMixIn, XMLRPCCommand):

Subscribers

People subscribed via source and target branches

to all changes: