|
@@ -139,6 +139,31 @@ class DockerImage:
|
|
|
sys.stderr.write('{}\n'.format(shlex_join(params)))
|
|
|
subprocess.run(params, check=True)
|
|
|
|
|
|
+class FuseMount:
|
|
|
+
|
|
|
+ def __init__(self, cmd, path, cd=False):
|
|
|
+ self._mount_arg_patterns = cmd
|
|
|
+ self._mount_path = path
|
|
|
+ self._cd = cd
|
|
|
+
|
|
|
+ def __enter__(self):
|
|
|
+ import shlex
|
|
|
+ mount_args = [a.format(mp=shlex.quote(self._mount_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_path)
|
|
|
+ return self._mount_path
|
|
|
+
|
|
|
+ def __exit__(self, exc_type, exc_value, traceback):
|
|
|
+ umount_args = ['fusermount', '-u', '-z', self._mount_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 StdoutTee:
|
|
|
|
|
|
def __init__(self, sink):
|