aboutsummaryrefslogtreecommitdiffstats
path: root/lib/raw_format.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/raw_format.py')
-rwxr-xr-xlib/raw_format.py81
1 files changed, 41 insertions, 40 deletions
diff --git a/lib/raw_format.py b/lib/raw_format.py
index 54e7bcb..b3bdb42 100755
--- a/lib/raw_format.py
+++ b/lib/raw_format.py
@@ -22,42 +22,44 @@
#
# Author isodumper software= papoteur <papoteur@mageialinux-online.org>
-import os, sys
+import sys
import getopt
from subprocess import call
sys.path.append('/usr/lib/isodumper')
+
def do_umount(target):
- mounts = get_mounted(target)
- if mounts:
- print('Unmounting all partitions of '+target+':')
- for mount in mounts:
- 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))
- sys.exit(6)
- else:
- if retcode == 0:
- print(mount[0]+' successfully unmounted')
- else:
- print('Error, umount '+mount[0]+' returned '+str(retcode))
- sys.exit(6)
- except OSError as e:
- print('Execution failed: '+str(e))
+ mounts = get_mounted(target)
+ if mounts:
+ print('Unmounting all partitions of ' + target + ':')
+ for mount in mounts:
+ 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))
sys.exit(6)
+ else:
+ if retcode == 0:
+ print(mount[0] + ' successfully unmounted')
+ else:
+ print('Error, umount ' + mount[0] + ' returned ' + str(retcode))
+ sys.exit(6)
+ except OSError as e:
+ print('Execution failed: ' + str(e))
+ sys.exit(6)
def get_mounted(target):
- try:
- 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 !')
- sys.exit(6)
+ try:
+ 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 !')
+ sys.exit(6)
+
def raw_format(device_path, fstype, volume_label, uid, gid):
import parted
@@ -79,17 +81,17 @@ def raw_format(device_path, fstype, volume_label, uid, gid):
regions = disk.getFreeSpaceRegions()
if len(regions) > 0:
- #print "Build partition"
+ # print "Build partition"
# Define size
start = parted.sizeToSectors(1, "MiB", device.sectorSize)
- #print "start %s" % start
+ # print "start %s" % start
end = device.getLength() - start - 1024
- #print end
+ # print end
# Alignment
- #cylinder = device.endSectorToCylinder(end)
- #end = device.endCylinderToSector(cylinder)
- #print end
+ # cylinder = device.endSectorToCylinder(end)
+ # end = device.endCylinderToSector(cylinder)
+ # print end
try:
geometry = parted.Geometry(device=device, start=start, end=end)
except:
@@ -120,13 +122,11 @@ def raw_format(device_path, fstype, volume_label, uid, gid):
sys.exit(0)
-
-
-
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="])
+ opts, args = getopt.getopt(sys.argv[1:], "hd:f:l:u:g:",
+ ["help", "device=", "filesystem=", "label=", "uid=", "gid="])
except getopt.error as msg:
print(msg)
print("for help use --help")
@@ -134,7 +134,7 @@ def main():
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("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")
@@ -145,7 +145,7 @@ def main():
elif o in ("-d"):
device = a
elif o in ("-f"):
- if a not in [ "fat32","exfat", "ntfs", "ext4" ]:
+ if a not in ["fat32", "exfat", "ntfs", "ext4"]:
print("Specify fat32, exfat, ntfs or ext4")
sys.exit(3)
fstype = a
@@ -158,11 +158,12 @@ def main():
argc = len(sys.argv)
if argc < 11:
- print("Too few arguments")
- print("for help use --help")
- exit(2)
+ print("Too few arguments")
+ print("for help use --help")
+ exit(2)
raw_format(device, fstype, label, uid, gid)
+
if __name__ == "__main__":
main()