mirror of
https://github.com/SL-RU/ranger_udisk_menu.git
synced 2024-11-10 12:34:07 +01:00
many fixes
This commit is contained in:
parent
47df672c59
commit
c0623bd310
83
menu.py
83
menu.py
@ -16,7 +16,10 @@ class ChoosePartition:
|
|||||||
screen = None
|
screen = None
|
||||||
selected_partn = 1
|
selected_partn = 1
|
||||||
partn = 1
|
partn = 1
|
||||||
|
help_message = [("Press 'm' to mount, " +
|
||||||
|
"'u' to unmount, " +
|
||||||
|
"'g' to refresh"),
|
||||||
|
" and 'e' to unmount the whole drive"]
|
||||||
message = ""
|
message = ""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -57,12 +60,47 @@ class ChoosePartition:
|
|||||||
return part
|
return part
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _select_print_part(self, part, is_selected, i):
|
||||||
|
if not ('mountpoint' in part and
|
||||||
|
'name' in part and
|
||||||
|
'size' in part):
|
||||||
|
raise Exception('Wrong lsblk json format.' +
|
||||||
|
'No mountpoint, name or size in the partition')
|
||||||
|
label = ""
|
||||||
|
label_fields = ['label', 'partlabel', 'parttypename', 'fstype']
|
||||||
|
for f in label_fields:
|
||||||
|
if f not in part:
|
||||||
|
continue
|
||||||
|
if part[f] is not None:
|
||||||
|
label = part[f]
|
||||||
|
break
|
||||||
|
|
||||||
|
mp = "Not mounted"
|
||||||
|
if part['mountpoint'] is not None:
|
||||||
|
mp = part['mountpoint']
|
||||||
|
|
||||||
|
s = "{name:<12} {size:<8} {label:<16} {mp}".format(
|
||||||
|
name=part['name'] if part['name'] is not None else "None",
|
||||||
|
label=label if label is not None else "None",
|
||||||
|
size=part['size'] if part['size'] is not None else "None",
|
||||||
|
mp=mp
|
||||||
|
)
|
||||||
|
self.screen.addstr(2 + i, 4, s, curses.color_pair(is_selected))
|
||||||
|
|
||||||
|
def _select_print_block_device(self, bd, i):
|
||||||
|
if 'model' not in bd or 'size' not in bd or 'name' not in bd:
|
||||||
|
raise Exception('Wrong lsblk json format. ' +
|
||||||
|
'No model, size or name in blockdevice')
|
||||||
|
|
||||||
|
model = bd['model'] if bd['model'] is not None else ""
|
||||||
|
size = bd['size'] if bd['size'] is not None else ""
|
||||||
|
self.screen.addstr(2 + i, 2, bd['name'] + " " + model + " " + size)
|
||||||
|
|
||||||
def _select_print(self, x):
|
def _select_print(self, x):
|
||||||
self.screen.clear()
|
self.screen.clear()
|
||||||
self.screen.border(0)
|
self.screen.border(0)
|
||||||
self.screen.addstr(
|
self.screen.addstr(1, 2, self.help_message[0])
|
||||||
2, 2,
|
self.screen.addstr(2, 2, self.help_message[1])
|
||||||
"Press 'm' to mount and 'u' to unmount and 'e' to unmount the whole drive")
|
|
||||||
|
|
||||||
partn = 0
|
partn = 0
|
||||||
i = 0
|
i = 0
|
||||||
@ -70,41 +108,20 @@ class ChoosePartition:
|
|||||||
raise Exception('Wrong lsblk json format. No field "blockdevices"')
|
raise Exception('Wrong lsblk json format. No field "blockdevices"')
|
||||||
for bd in self.blkinfo['blockdevices']:
|
for bd in self.blkinfo['blockdevices']:
|
||||||
i += 1
|
i += 1
|
||||||
if 'model' not in bd or 'size' not in bd or 'name' not in bd:
|
bd_selected = False
|
||||||
raise Exception(
|
bd_i = i
|
||||||
'Wrong lsblk json format. No model, size or name in the blockdevice')
|
self._select_print_block_device(bd, bd_i)
|
||||||
model = bd['model'] if bd['model'] is not None else ""
|
|
||||||
size = bd['size'] if bd['size'] is not None else ""
|
|
||||||
self.screen.addstr(2 + i, 2, bd['name'] + " " + model + " " + size)
|
|
||||||
if 'children' not in bd:
|
if 'children' not in bd:
|
||||||
continue
|
continue
|
||||||
for part in bd['children']:
|
for part in bd['children']:
|
||||||
i += 1
|
i += 1
|
||||||
partn += 1
|
partn += 1
|
||||||
is_selected = 0 if self.selected_partn != partn else 1
|
is_selected = 0 if self.selected_partn != partn else 1
|
||||||
lab = ""
|
if is_selected:
|
||||||
if 'label' not in part and part['label'] is not None:
|
bd_selected = True
|
||||||
lab = part['label']
|
self._select_print_part(part, is_selected, i)
|
||||||
elif 'partlabel' not in part and part['partlabel'] is not None:
|
if bd_selected:
|
||||||
lab = part['partlabel']
|
self.screen.addstr(2 + bd_i, 1, ">")
|
||||||
elif 'parttypename' not in part and part['parttypename'] is not None:
|
|
||||||
lab = part['parttypename']
|
|
||||||
elif 'fstype' not in part and part['fstype'] is not None:
|
|
||||||
lab = part['fstype']
|
|
||||||
|
|
||||||
if 'mountpoint' not in part:
|
|
||||||
raise Exception('Wrong lsblk json format. No mountpoint')
|
|
||||||
mp = part['mountpoint'] if part['mountpoint'] is not None else "Not mounted"
|
|
||||||
|
|
||||||
s = "{name:<12} {size:<8} {label:<16} {mp}".format(
|
|
||||||
name=part['name'] if part['name'] is not None else "None",
|
|
||||||
label=lab if lab is not None else "None",
|
|
||||||
size=part['size'] if part['size'] is not None else "None",
|
|
||||||
mp=mp
|
|
||||||
)
|
|
||||||
self.screen.addstr(2 + i, 4, s, curses.color_pair(is_selected))
|
|
||||||
self.screen.refresh()
|
|
||||||
|
|
||||||
self.screen.addstr(2 + i + 2, 4, self.message)
|
self.screen.addstr(2 + i + 2, 4, self.message)
|
||||||
|
|
||||||
def _eject_all(self):
|
def _eject_all(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user