update for older version of lsblk and update documentation

This commit is contained in:
Alexander Lutsai 2021-06-19 14:51:28 +03:00
parent 2fa1218ca0
commit c89d4eed56
2 changed files with 21 additions and 9 deletions

View file

@ -4,9 +4,9 @@ This script draws menu to mount and unmount partitions using udisksctl and ncurs
![Screenshot](screenshot.png)
# Requirements
- python3
- python3.8 or newer
- udisks2 (for udisksctl)
- lsblk
- lsblk 2.3 or newer
# How to install
Firstly you need to clone this repo to ranger config directory
@ -36,3 +36,7 @@ Enter in ranger `:mount`, than will be shown menu. In this menu you can press:
- `e` to unmount all partitions of selected partition's drive
- `p` to power off selected the selected partition's drive (also called safely remove). It can be done only when all partitions of the drive are unmounted
- `ENTER` to open selected mountpoint in current tab of the ranger
# Troubles
If there is trouble with permissions, then you need to create group `storage` and add your user to it. Then you need to update your Polkit or PolicyKit permissions like it shown [here: https://github.com/coldfix/udiskie/wiki/Permissions](https://github.com/coldfix/udiskie/wiki/Permissions)

22
menu.py
View file

@ -154,7 +154,7 @@ class ChoosePartition:
if blk is None:
return
for part in blk['children']:
self.unmount(part['path'])
self.unmount(part)
def select(self):
sel = None
@ -179,15 +179,15 @@ class ChoosePartition:
elif x == ord('m'):
sel = self._get_part_by_partn()
if sel is not None:
self.mount(sel['path'])
self.mount(sel)
elif x == ord('u'):
sel = self._get_part_by_partn()
if sel is not None:
self.unmount(sel['path'])
self.unmount(sel)
elif x == ord('p'):
sel_drive = self._get_drive_by_partn()
if sel_drive is not None:
self.poweroff(sel_drive['path'])
self.poweroff(sel_drive)
elif x == ord('g') or x == ord('r'):
self._read_partitions()
curses.endwin()
@ -207,14 +207,22 @@ class ChoosePartition:
self.message = cmd + " error: " + r + str(e)
self._read_partitions()
def get_drive_path(self, drive):
if 'path' not in drive:
drive['path'] = '/dev/' + drive['kname']
return drive['path']
def unmount(self, dev):
self._udisk_mount_unmount("unmount", dev)
p = self.get_drive_path(dev)
self._udisk_mount_unmount("unmount", p)
def poweroff(self, dev):
self._udisk_mount_unmount("power-off", dev)
p = self.get_drive_path(dev)
self._udisk_mount_unmount("power-off", p)
def mount(self, dev):
self._udisk_mount_unmount("mount", dev)
p = self.get_drive_path(dev)
self._udisk_mount_unmount("mount", p)
if __name__ == "__main__":