From c89d4eed5640f89dea8caafc1d8c1ec21dddf729 Mon Sep 17 00:00:00 2001 From: Alexander Lutsai Date: Sat, 19 Jun 2021 14:51:28 +0300 Subject: [PATCH] update for older version of lsblk and update documentation --- README.md | 8 ++++++-- menu.py | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8a5d571..23818e7 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/menu.py b/menu.py index a9f0707..950bdf2 100644 --- a/menu.py +++ b/menu.py @@ -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__":