diff options
-rw-r--r-- | lib/isodumper.py | 29 | ||||
-rwxr-xr-x | lib/raw_format.py | 46 |
2 files changed, 38 insertions, 37 deletions
diff --git a/lib/isodumper.py b/lib/isodumper.py index 55b1193..ee1c8bc 100644 --- a/lib/isodumper.py +++ b/lib/isodumper.py @@ -27,9 +27,10 @@ # ensure we're using the latest build, if called from our build environment import sys +import imp sys.path.insert(0,'../../../build/swig/python') -reload(sys) +imp.reload(sys) sys.setdefaultencoding("utf-8") ########### # imports # @@ -108,7 +109,7 @@ class UDisks2(object): devs = self.bus.get_object('org.freedesktop.UDisks2', '/org/freedesktop/UDisks2/block_devices') xml = devs.Introspect(dbus_interface='org.freedesktop.DBus.Introspectable') - for dev in re.finditer(r'name=[\'"](.+?)[\'"]', type(u'')(xml)): + for dev in re.finditer(r'name=[\'"](.+?)[\'"]', type('')(xml)): bd = self.bus.get_object('org.freedesktop.UDisks2', '/org/freedesktop/UDisks2/block_devices/%s2'%dev.group(1)) try: @@ -130,10 +131,10 @@ class UDisks2(object): re_drive = re.compile('(?P<path>.*?/drives/(?P<id>.*))') re_block = re.compile('(?P<path>.*?/block_devices/(?P<id>.*))') devs= [m.groupdict() for m in - [re_drive.match(path) for path in objects.keys()] + [re_drive.match(path) for path in list(objects.keys())] if m] blocks = [m.groupdict() for m in - [re_block.match(path) for path in objects.keys()] + [re_block.match(path) for path in list(objects.keys())] if m] list=[] @@ -165,11 +166,11 @@ class UDisks2(object): 'options':','.join(mount_options) }, dbus_interface=self.FILESYSTEM) - return unicode(r) + return str(r) except: # May be already mounted, check mp = self.node_mountpoint(str(device_node_path)) - print mp, sys.exc_info()[0] + print(mp, sys.exc_info()[0]) if mp is None: raise ValueError(sys.exc_info()[0]) return mp @@ -454,7 +455,7 @@ class IsoDumper(object): message = _('Error, umount ')+mount[0]+_(' returned ')+str(retcode) self.logger(message) self.emergency(message) - except OSError, e: + except OSError as e: message = _('Execution failed: ')+str(e) self.logger(message) self.emergency(message) @@ -490,7 +491,7 @@ class IsoDumper(object): self.progress.setEnabled() self.progress.setLabel(_('Writing ')+source.split('/')[-1]+_(' to ')+target.split('/')[-1]) self.logger(_('Executing copy from ')+source+_(' to ')+target) - steps=range(0, b+1, b/100) + steps=list(range(0, b+1, b/100)) steps.append(b) indice=1 written=0 @@ -498,7 +499,7 @@ class IsoDumper(object): while ncuts <= 100: bs=bs/2 ncuts=b/bs - for i in xrange(0,ncuts+1): + for i in range(0,ncuts+1): try: buf=ifc.read(bs) except: @@ -543,7 +544,7 @@ class IsoDumper(object): self.progress.setEnabled() self.progress.setLabel(_('Checking ')+target.split('/')[-1]) self.progress.setValue(0) - steps=range(0, b+1, b/100) + steps=list(range(0, b+1, b/100)) steps.append(b) indice=0 checked=0 @@ -552,7 +553,7 @@ class IsoDumper(object): ncuts=b/1024 try: with open(target, 'rb') as f: - for x in xrange(0,ncuts): + for x in range(0,ncuts): block = f.read(1024) sha1func.update(block) md5func.update(block) @@ -685,7 +686,7 @@ class IsoDumper(object): logfile.write(self.logview.logText()) logfile.close() - print self.logview.logText() + print(self.logview.logText()) def logger(self, text): self.logview.appendLines(text+"\n") @@ -698,7 +699,7 @@ class IsoDumper(object): # self.chooser.set_tooltip_text(self.img_name) def help_dialog(self): - print "Help 2" + print("Help 2") info = Info(_("IsoDumper"),0,_("Mageia IsoDumper\n\ ----------------\n\ This GUI program is primarily for safely writing a bootable ISO image to a USB flash drive, an operation devious & potentially hazardous when done by hand. As a bonus, it can also back up the entire previous contents of the flash drive onto the hard disc, and restore the flash drive to its previous state subsequently. It gives also a feature for formatting the USB device.\n\ @@ -958,7 +959,7 @@ The fields of the main window are as follows:\n\ pass try: if event.widget() == self.helpbt: - print "help" + print("help") self.help_dialog() except: pass diff --git a/lib/raw_format.py b/lib/raw_format.py index 84ca8c7..00b1f97 100755 --- a/lib/raw_format.py +++ b/lib/raw_format.py @@ -31,22 +31,22 @@ sys.path.append('/usr/lib/isodumper') def do_umount(target): mounts = get_mounted(target) if mounts: - print 'Unmounting all partitions of '+target+':' + print('Unmounting all partitions of '+target+':') for mount in mounts: - print 'Trying to unmount '+mount[0]+'...' + print('Trying to unmount '+mount[0]+'...') try: retcode = call('umount '+mount[0], shell=True) if retcode < 0: - print 'Error, umount '+mount[0]+' was terminated by signal '+str(retcode) + print('Error, umount '+mount[0]+' was terminated by signal '+str(retcode)) sys.exit(6) else: if retcode == 0: - print mount[0]+' successfully unmounted' + print(mount[0]+' successfully unmounted') else: - print 'Error, umount '+mount[0]+' returned '+str(retcode) + print('Error, umount '+mount[0]+' returned '+str(retcode)) sys.exit(6) - except OSError, e: - print 'Execution failed: '+str(e) + except OSError as e: + print('Execution failed: '+str(e)) sys.exit(6) @@ -55,7 +55,7 @@ def get_mounted(target): lines = [line.strip("\n").split(" ") for line in open ("/etc/mtab", "r").readlines()] return [mount for mount in lines if mount[0].startswith(target)] except: - print 'Could not read mtab !' + print('Could not read mtab !') sys.exit(6) def raw_format(device_path, fstype, volume_label, uid, gid): @@ -73,7 +73,7 @@ def raw_format(device_path, fstype, volume_label, uid, gid): disk.commit() except: # Unable to write the new partition - print "Can't create partition. The device could be read-only." + print("Can't create partition. The device could be read-only.") sys.exit(5) regions = disk.getFreeSpaceRegions() @@ -92,7 +92,7 @@ def raw_format(device_path, fstype, volume_label, uid, gid): try: geometry = parted.Geometry(device=device, start=start, end=end) except: - print "Geometry error - Can't create partition" + print("Geometry error - Can't create partition") sys.exit(5) # fstype @@ -121,26 +121,26 @@ def main(): # parse command line options try: opts, args = getopt.getopt(sys.argv[1:], "hd:f:l:u:g:", ["help", "device=","filesystem=","label=","uid=","gid="]) - except getopt.error, msg: - print msg - print "for help use --help" + except getopt.error as msg: + print(msg) + print("for help use --help") sys.exit(2) for o, a in opts: if o in ("-h", "--help"): - print "Usage: %s -d device -f filesystem -l volume_label\n" % sys.argv[0] - print "-d|--device : device path" - print "-f|--filesystem : filesystem\n" - print "-l|--label : volume label\n" - print "-u|--uid : uid of user\n" - print "-g|--gid : gid of user\n" - print "Example : %s -d /dev/sdj -f fat32 -l \"USB Stick\" -u 1000 -g 1000" % sys.argv[0] + print("Usage: %s -d device -f filesystem -l volume_label\n" % sys.argv[0]) + print("-d|--device : device path") + print("-f|--filesystem : filesystem\n") + print("-l|--label : volume label\n") + print("-u|--uid : uid of user\n") + print("-g|--gid : gid of user\n") + print("Example : %s -d /dev/sdj -f fat32 -l \"USB Stick\" -u 1000 -g 1000" % sys.argv[0]) sys.exit(0) elif o in ("-d"): device = a elif o in ("-f"): if a not in [ "fat32", "ntfs", "ext4" ]: - print "Specify fat32, ntfs or ext4" + print("Specify fat32, ntfs or ext4") sys.exit(3) fstype = a elif o in ("-l"): @@ -152,8 +152,8 @@ def main(): argc = len(sys.argv) if argc < 11: - print "Too few arguments" - print "for help use --help" + print("Too few arguments") + print("for help use --help") exit(2) raw_format(device, fstype, label, uid, gid) |