From bd9473705e2618e49f56ded81d0aa1a3f5c2afa6 Mon Sep 17 00:00:00 2001 From: Shuangquan Zhou Date: Tue, 16 Aug 2011 16:47:35 +0800 Subject: [PATCH] Add some useful prompt --- mic/utils/fs_related.py | 15 +++++++++------ plugins/imager/loop_plugin.py | 1 + plugins/imager/raw_plugin.py | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index 8936c52..cdcd124 100644 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -44,12 +44,10 @@ def terminal_width(fd=1): return 80 def truncate_url(url, width): - if len(url) > width: - return os.path.basename(url)[0:width] - return url + return os.path.basename(url)[0:width] class TextProgress(object): - def __init__(self, totalnum): + def __init__(self, totalnum = None): self.total = totalnum self.counter = 1 def start(self, filename, url, *args, **kwargs): @@ -57,9 +55,12 @@ class TextProgress(object): self.termwidth = terminal_width() if sys.stdout.isatty(): sys.stdout.write("\r%-*s" % (self.termwidth, " ")) - sys.stdout.write("\rRetrieving %s (%d|%d)" % (truncate_url(self.url, self.termwidth - 21), self.counter, self.total)) + if self.total is None: + sys.stdout.write("\rRetrieving %s" % truncate_url(self.url, self.termwidth - 11)) + else: + sys.stdout.write("\rRetrieving %s (%d|%d)" % (truncate_url(self.url, self.termwidth - 21), self.counter, self.total)) else: - sys.stdout.write("Retrieving %s (%d|%d)" % (truncate_url(self.url, self.termwidth - 21), self.counter, self.total)) + sys.stdout.write("Retrieving %s" % truncate_url(self.url, self.termwidth - 11)) sys.stdout.flush() def update(self, *args): pass @@ -926,6 +927,8 @@ def load_module(module): def myurlgrab(url, filename, proxies, progress_obj = None): g = URLGrabber() + if progress_obj is None: + progress_obj = TextProgress() if url.startswith("file:///"): file = url.replace("file://", "") if not os.path.exists(file): diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index 37b3227..c3c5f42 100644 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -89,6 +89,7 @@ class LoopPlugin(ImagerPlugin): @classmethod def do_unpack(cls, srcimg): image = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "meego.img") + print "Copying file system..." shutil.copyfile(srcimg, image) return image diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 2453ca3..97f0313 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -171,6 +171,7 @@ class RawPlugin(ImagerPlugin): image = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "meego.img") ddcmd = misc.find_binary_path("dd") args = [ ddcmd, "if=%s" % srcloop.partitions[0]['device'], "of=%s" % image ] + print "dd image..." rc = subprocess.call(args) if rc != 0: raise CreatorError("Failed to dd") -- 2.34.1