|
@@ -30,6 +30,7 @@ $PROMPT = ''.join([
|
|
|
$RIGHT_PROMPT = '{gitstatus}{env_name: {}}'
|
|
|
$XONSH_APPEND_NEWLINE = True
|
|
|
|
|
|
+import contextlib
|
|
|
import datetime as dt
|
|
|
import io
|
|
|
import os
|
|
@@ -139,43 +140,6 @@ class DockerImage:
|
|
|
sys.stderr.write('{}\n'.format(shlex_join(params)))
|
|
|
subprocess.run(params, check=True)
|
|
|
|
|
|
-class FuseMount:
|
|
|
-
|
|
|
- def __init__(self, mount_arg_patterns, mount_point_path, cd=False):
|
|
|
- self._mount_arg_patterns = mount_arg_patterns
|
|
|
- self._mount_point_path = mount_point_path
|
|
|
- self._cd = cd
|
|
|
-
|
|
|
- def __enter__(self):
|
|
|
- import shlex
|
|
|
- mount_args = [a.format(mp=shlex.quote(self._mount_point_path))
|
|
|
- for a in self._mount_arg_patterns]
|
|
|
- sys.stderr.write('{}\n'.format(shlex_join(mount_args)))
|
|
|
- subprocess.check_call(mount_args)
|
|
|
- if self._cd:
|
|
|
- self._previous_work_dir_path = os.getcwd()
|
|
|
- os.chdir(self._mount_point_path)
|
|
|
- return self._mount_point_path
|
|
|
-
|
|
|
- def __exit__(self, exc_type, exc_value, traceback):
|
|
|
- umount_args = ['fusermount', '-u', '-z', self._mount_point_path]
|
|
|
- sys.stderr.write('{}\n'.format(shlex_join(umount_args)))
|
|
|
- subprocess.check_call(umount_args)
|
|
|
- if self._cd:
|
|
|
- os.chdir(self._previous_work_dir_path)
|
|
|
-
|
|
|
-class EncFSMount(FuseMount):
|
|
|
-
|
|
|
- def __init__(self, root_dir_path, mount_point_path, cd=False, extpass=None):
|
|
|
- mount_arg_patterns = ['encfs', root_dir_path, mount_point_path]
|
|
|
- if extpass:
|
|
|
- mount_arg_patterns.extend(['--extpass', shlex_join(extpass)])
|
|
|
- super().__init__(
|
|
|
- mount_arg_patterns=mount_arg_patterns,
|
|
|
- mount_point_path=mount_point_path,
|
|
|
- cd=cd,
|
|
|
- )
|
|
|
-
|
|
|
class StdoutTee:
|
|
|
|
|
|
def __init__(self, sink):
|
|
@@ -207,6 +171,15 @@ class StdoutTee:
|
|
|
os.close(self._write_fd)
|
|
|
self._thread.join()
|
|
|
|
|
|
+@contextlib.contextmanager
|
|
|
+def chdir(path):
|
|
|
+ previous = os.getcwd()
|
|
|
+ try:
|
|
|
+ os.chdir(path)
|
|
|
+ yield path
|
|
|
+ finally:
|
|
|
+ os.chdir(previous)
|
|
|
+
|
|
|
def dpkg_listfiles(pkg_name):
|
|
|
assert isinstance(pkg_name, str)
|
|
|
paths = $(dpkg --listfiles @(pkg_name)).split('\n')[:-1]
|
|
@@ -233,6 +206,29 @@ def dpkg_which(cmd):
|
|
|
assert len(matches) == 1
|
|
|
return matches[0]
|
|
|
|
|
|
+@contextlib.contextmanager
|
|
|
+def encfs_mount(root_dir_path, mount_point_path, extpass=None):
|
|
|
+ mount_arg_patterns = ['encfs', root_dir_path, mount_point_path]
|
|
|
+ if extpass:
|
|
|
+ mount_arg_patterns.extend(['--extpass', shlex_join(extpass)])
|
|
|
+ with fuse_mount(mount_arg_patterns=mount_arg_patterns,
|
|
|
+ mount_point_path=mount_point_path):
|
|
|
+ yield mount_point_path
|
|
|
+
|
|
|
+@contextlib.contextmanager
|
|
|
+def fuse_mount(mount_arg_patterns, mount_point_path):
|
|
|
+ import shlex
|
|
|
+ mount_args = [a.format(mp=shlex.quote(mount_point_path))
|
|
|
+ for a in mount_arg_patterns]
|
|
|
+ sys.stderr.write('{}\n'.format(shlex_join(mount_args)))
|
|
|
+ subprocess.check_call(mount_args)
|
|
|
+ try:
|
|
|
+ yield mount_point_path
|
|
|
+ finally:
|
|
|
+ umount_args = ['fusermount', '-u', '-z', mount_point_path]
|
|
|
+ sys.stderr.write('{}\n'.format(shlex_join(umount_args)))
|
|
|
+ subprocess.check_call(umount_args)
|
|
|
+
|
|
|
def gpg_decrypt(path, verify=False):
|
|
|
import gpg
|
|
|
with gpg.Context() as gpg_ctx:
|