aboutsummaryrefslogtreecommitdiffstats
path: root/lib/raw_format.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/raw_format.py')
-rwxr-xr-xlib/raw_format.py40
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/raw_format.py b/lib/raw_format.py
index bf57ba5..6dc6d91 100755
--- a/lib/raw_format.py
+++ b/lib/raw_format.py
@@ -27,7 +27,8 @@ import getopt
from subprocess import call
-sys.path.append('/usr/lib/isodumper')
+sys.path.append("/usr/lib/isodumper")
+
def raw_format(device_path, fstype, volume_label, uid, gid):
import parted
@@ -38,7 +39,7 @@ def raw_format(device_path, fstype, volume_label, uid, gid):
device = parted.getDevice(device_path)
# Create a default partition set up
- disk = parted.freshDisk(device, 'msdos')
+ disk = parted.freshDisk(device, "msdos")
try:
disk.commit()
except:
@@ -72,7 +73,9 @@ def raw_format(device_path, fstype, volume_label, uid, gid):
fs = parted.FileSystem(type=_fstype, geometry=geometry)
# Create partition
- partition = parted.Partition(disk=disk, type=parted.PARTITION_NORMAL, geometry=geometry, fs=fs)
+ partition = parted.Partition(
+ disk=disk, type=parted.PARTITION_NORMAL, geometry=geometry, fs=fs
+ )
constraint = parted.Constraint(exactGeom=geometry)
disk.addPartition(partition=partition, constraint=constraint)
disk.commit()
@@ -85,15 +88,27 @@ def raw_format(device_path, fstype, volume_label, uid, gid):
elif fstype == "ntfs":
call(["mkntfs", "-f", "-L", volume_label, partition.path])
elif fstype == "ext4":
- call(["mkfs.ext4", "-E", "root_owner=%s:%s" % (uid, gid), "-L", volume_label, partition.path])
+ call(
+ [
+ "mkfs.ext4",
+ "-E",
+ "root_owner=%s:%s" % (uid, gid),
+ "-L",
+ volume_label,
+ partition.path,
+ ]
+ )
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")
@@ -101,13 +116,16 @@ 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")
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(
+ '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
@@ -125,9 +143,9 @@ 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)