-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFreeBSD-USB-Quick-Formatter.py
78 lines (60 loc) · 3.02 KB
/
FreeBSD-USB-Quick-Formatter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import subprocess
import tkinter
from tkinter import ttk
from tkinter import messagebox
#empty list for drives
drives = list()
root = tkinter.Tk()
root.title("USB Quick Formatter")
root.geometry("400x400")
style = ttk.Style()
style.theme_use("clam")
def addDrives():
for i in os.listdir("/dev"):
if i[:2] == "da" and not "p" in i and not "s" in i:
drives.append(i)
def run():
if drivesCombo.get() != "": #checks if a drive is selected
drive = "/dev/" + drivesCombo.get()
if formatCombo.get() == "Ext4":
formatcmd = "sudo umount " + drive + "* ; " + "sudo gpart destroy -F " + drive + " ; " + "sudo gpart create -s gpt " + drive + " && " + "sudo gpart add -t linux-data " + drive + " && sleep 5 && " + "sudo mke2fs -t ext4 " + drive + "p1"
elif formatCombo.get() == "FAT32":
formatcmd = "sudo umount " + drive + "* ; " + "sudo gpart destroy -F " + drive + " ; " + "sudo gpart create -s mbr " + drive + " && " + "sudo gpart add -t fat32 " + drive + " && sleep 5 && " + "sudo newfs_msdos -F 32 " + drive + "s1"
elif formatCombo.get() == "NTFS":
formatcmd = "sudo umount " + drive + "* ; " + "sudo gpart destroy -F " + drive + " ; " + "sudo gpart create -s mbr " + drive + " && " + "sudo gpart add -t ntfs " + drive + " && sleep 5 && " + "sudo mkntfs --quick " + drive + "s1"
elif formatCombo.get() == "UFS":
formatcmd = "sudo umount " + drive + "* ; " + "sudo gpart destroy -F " + drive + " ; " + "sudo gpart create -s gpt " + drive + " && " + "sudo gpart add -t freebsd-ufs " + drive + " && sleep 5 && " + "sudo newfs " + drive + "p1"
cmd = "xterm -hold -e '" + formatcmd + " && echo Done. You can close the window." + "'"
confirmation = tkinter.messagebox.askquestion("Confirmation", "Command: " + formatcmd)
if confirmation == "yes":
subprocess.call(cmd, shell=True)
def refresh():
drives.clear()
addDrives()
drivesCombo.configure(values=drives)
def driveInfo():
subprocess.call("xterm -sb -hold -e 'geom disk list'", shell=True)
addDrives()
drivesLabel = tkinter.Label(root, text="Drives:", font=("", 10))
drivesCombo = ttk.Combobox(root, values=drives, state="readonly", font=("", 10))
drivesButton = ttk.Button(root, command=driveInfo, text="Show Drives Info")
formatLabel = tkinter.Label(root, text="Format:", font=("", 10))
formatCombo = ttk.Combobox(root, values=("FAT32", "UFS", "NTFS", "Ext4"), state="readonly", font=("", 10))
formatCombo.current(0)
refreshButton = ttk.Button(root, command=refresh, text="Refresh")
runButton = ttk.Button(root, command=run, text="Run")
tkinter.Label(root, font=("", 6)).pack() #empty line workaround
tkinter.Label(root, font=("", 8)).pack()
drivesLabel.pack()
drivesCombo.pack()
tkinter.Label(root, font=("", 8)).pack()
formatLabel.pack()
formatCombo.pack()
tkinter.Label(root, font=("", 28)).pack()
refreshButton.pack()
tkinter.Label(root, font=("", 8)).pack()
drivesButton.pack()
tkinter.Label(root, font=("", 8)).pack()
runButton.pack()
root.mainloop()