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):
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
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):
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")