aboutsummaryrefslogtreecommitdiffstats
path: root/lib/raw_format.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/raw_format.py')
-rwxr-xr-xlib/raw_format.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/lib/raw_format.py b/lib/raw_format.py
index b634470..0cce0e9 100755
--- a/lib/raw_format.py
+++ b/lib/raw_format.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
#
# imported from project Mintstick, by Clement Lefebvre
# https://github.com/linuxmint/mintstick/
@@ -24,7 +24,7 @@
import os, sys
import getopt
-import parted
+
from subprocess import call
sys.path.append('/usr/lib/isodumper')
@@ -32,22 +32,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)
@@ -56,11 +56,11 @@ 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):
-
+ import parted
do_umount(device_path)
# First erase MBR and partition table , if any
@@ -74,7 +74,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()
@@ -93,7 +93,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
@@ -122,26 +122,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"):
@@ -153,8 +153,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)