Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mount() and umount() commands. #1

Merged
merged 1 commit into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion shlib/__init__.py
Expand Up @@ -10,7 +10,7 @@
set_prefs,

# filesystem utilities
cp, mv, rm, ln, touch, mkdir, cd, cwd, chmod, ls, lsd, lsf,
cp, mv, rm, ln, touch, mkdir, mount, umount, is_mounted, cd, cwd, chmod, ls, lsd, lsf,

# path expansion utilities
leaves, cartesian_product, brace_expand,
Expand Down
23 changes: 23 additions & 0 deletions shlib/shlib.py
Expand Up @@ -236,6 +236,29 @@ def mkdir(*paths):
if err.errno != errno.EEXIST or path.is_file():
raise

# mount/umount {{{2
class mount:

def __init__(self, path):
self.path = to_path(path)
self.mounted_externally = is_mounted(self.path)

if not self.mounted_externally:
Run(['mount', self.path])

def __enter__(self):
pass

def __exit__(self, exc_type, exc_value, exc_traceback):
if not self.mounted_externally:
umount(self.path)

def umount(path):
Run(['umount', path])

def is_mounted(path):
return Run(['mountpoint', '-q', path], '0,1').status == 0

# cd {{{2
class cd:
def __init__(self, path):
Expand Down