Add some useful prompt
authorShuangquan Zhou <shuangquan.zhou@intel.com>
Tue, 16 Aug 2011 08:47:35 +0000 (16:47 +0800)
committerShuangquan Zhou <shuangquan.zhou@intel.com>
Tue, 16 Aug 2011 08:47:35 +0000 (16:47 +0800)
mic/utils/fs_related.py
plugins/imager/loop_plugin.py
plugins/imager/raw_plugin.py

index 8936c52..cdcd124 100644 (file)
@@ -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):
index 37b3227..c3c5f42 100644 (file)
@@ -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
 
index 2453ca3..97f0313 100644 (file)
@@ -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")