Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/cli.py
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | with ExitStack() as stack: | ||||
"root": {"level": ctx.obj["log_level"], "handlers": ["syslog"],}, | "root": {"level": ctx.obj["log_level"], "handlers": ["syslog"],}, | ||||
} | } | ||||
) | ) | ||||
asyncio.run(fuse.main(swhids, path, ctx.obj["config"])) | asyncio.run(fuse.main(swhids, path, ctx.obj["config"])) | ||||
@fuse.command() | @fuse.command() | ||||
@click.argument( | |||||
"path", | |||||
required=True, | |||||
metavar="PATH", | |||||
type=click.Path(exists=True, dir_okay=True, file_okay=False), | |||||
) | |||||
@click.pass_context | |||||
def umount(ctx, path): | |||||
"""Unmount a mounted virtual file system. | |||||
Note: this is equivalent to ``fusermount -u PATH``, which can be used to unmount any | |||||
FUSE-based virtual file system. See ``man fusermount3``. | |||||
""" | |||||
import subprocess | |||||
try: | |||||
subprocess.run(["fusermount", "-u", path], check=True) | |||||
except subprocess.CalledProcessError as err: | |||||
logging.error( | |||||
f"cannot unmount virtual file system: " | |||||
f"\"{' '.join(err.cmd)}\" returned exit status {err.returncode}" | |||||
) | |||||
ctx.exit(1) | |||||
@fuse.command() | |||||
@click.pass_context | @click.pass_context | ||||
def clean(ctx): | def clean(ctx): | ||||
"""Clean on-disk cache(s). | """Clean on-disk cache(s). | ||||
""" | """ | ||||
def rm_cache(conf, cache_name): | def rm_cache(conf, cache_name): | ||||
try: | try: | ||||
conf["cache"][cache_name]["path"].unlink(missing_ok=True) | conf["cache"][cache_name]["path"].unlink(missing_ok=True) | ||||
except KeyError: | except KeyError: | ||||
pass | pass | ||||
conf = ctx.obj["config"] | conf = ctx.obj["config"] | ||||
for cache_name in ["blob", "metadata"]: | for cache_name in ["blob", "metadata"]: | ||||
rm_cache(conf, cache_name) | rm_cache(conf, cache_name) |