Branch 'liveusb-creator-gtk' - BaseLiveUSB/__init__.py

Muayyad Alsadi alsadi at fedoraproject.org
Sat Nov 22 00:49:15 UTC 2008


 BaseLiveUSB/__init__.py |   58 ++++++++++++++++++++++++++++++------------------
 1 file changed, 37 insertions(+), 21 deletions(-)

New commits:
commit d7bc14866525c8e776aceaec708b34312b2efa41
Author: alsadi <alsadi at pc1.localdomain>
Date:   Sat Nov 22 02:42:42 2008 +0200

    Abstract progress handling
    
    run() should loop on the steps and calling the functions
    each step has an estimated duration percent of overall progress
    then each step method should call __progress() passing it the partial progress
    and it will automatically calculate the overall progress

diff --git a/BaseLiveUSB/__init__.py b/BaseLiveUSB/__init__.py
index 59f1669..103b58d 100644
--- a/BaseLiveUSB/__init__.py
+++ b/BaseLiveUSB/__init__.py
@@ -44,6 +44,8 @@ class LiveUSBCreator():
     self.__target_mnt_orig=None	# original target partition mount point (if it was mounted)
     self.__progress_cb=None
     self.__mbr='/usr/lib/syslinux/mbr.bin' # should be moved away to bootloader class
+    self.__steps=[]		# [['stepname',function,duration_percent,begining_percent],...]
+    self.__current_step=-1	# current step 
     # passing preexec_fn=self.__setsid to popen makes
     # subprocesses to continue even when parent is closed
     self.__setsid = getattr(os, 'setsid', None)
@@ -51,6 +53,39 @@ class LiveUSBCreator():
     
     # TODO: self.target_disk is documented to be mount point while it's used as the target disk (not partition) # DONE
     # TODO: this mean that is should be renamed to remove that ambiguity # DONE
+  def __fill_steps_begining(self):
+    ssum=0
+    for i,j in enumerate(self.__steps):
+      self.steps[i][3]=ssum
+      ssum+=j[2]
+  def set_progress_cb(cb=None):
+    """set the funtion to be called when some progress is to be shown to the user,
+cb will be passed with a string, a progress percent or -1 if the value of the progress is unknown"""
+    self.__progress_cb=cb
+
+  def __progress(self,p):
+    if not self.__progress_cb: return
+    if self.__current_step<0: self.__progress_cb(max(min(p,100),0), 'Working')
+    else:
+      step=self.__steps[self.__current_step]
+      self.__progress_cb(max(min(p*step[2]+step[3],100),0),step[0])
+  def verify_iso_md5(self):
+    """Verify the ISO md5sum.
+    At the moment this is Linux specific, until we port checkisomd5 to Windows."""
+    self.log.info(_('Verifying ISO MD5 checksum'))
+    cmd='checkisomd5 --gauge "%s"' % self.iso_fn
+    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+      stderr=subprocess.PIPE, shell=True)
+    l='0'
+    p=0
+    while(l):
+      l=proc.stdout.readline()
+      try: i=int(l.strip())
+      except ValueError: pass
+      else: p=i
+      self.__progress(p)
+    return proc.wait()==0
+
   def target_have_liveos(self):
     """return true if target partition already seems to have a LiveOS"""
     if not self.target_mnt: raise LiveUSBError('TargetNotMounted')
@@ -72,28 +107,14 @@ class LiveUSBCreator():
     device = device or self.target_mnt
     stat = os.statvfs(device)
     return stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
+
   def get_iso_bytes(self):
     """return number of bytes in the source iso (works even if the iso is a device file)"""
     f=open(self.iso_fn,'rb')
     f.seek(0,2); r=f.tell()
     f.close()
     return r
-  def verify_iso_md5(self):
-    """Verify the ISO md5sum.
-    At the moment this is Linux specific, until we port checkisomd5 to Windows."""
-    self.log.info(_('Verifying ISO MD5 checksum'))
-    cmd='checkisomd5 --gauge "%s"' % self.iso_fn
-    proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-      stderr=subprocess.PIPE, shell=True)
-    l='0'
-    p=0
-    while(l):
-      l=proc.stdout.readline()
-      try: i=int(l.strip())
-      except ValueError: pass
-      else: p=i
-      self.__partial_progress(p)
-    return proc.wait()==0
+
   def validate(self):
     """return None if all options are valid or return a reason for being invalid"""
     if self.target_fs_type not in ('vfat','msdos','ext2','ext3'): return 'BadTargetFS'
@@ -150,11 +171,6 @@ class LiveUSBCreator():
                              "command: `%s`\nA more detailed error log has "
                              "been written to 'liveusb-creator.log'" % cmd)
     return proc
-    
-  def set_progress_cb(cb=None):
-    """set the funtion to be called when some progress is to be shown to the user,
-cb will be passed with a string, a progress percent or -1 if the value of the progress is unknown"""
-    self.__progress_cb=cb
 
   def is_blank_mbr(self):
     """Return whether the MBR is empty or not."""




More information about the liveusb-creator mailing list