Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/cli.py
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | def fuse(ctx, config_file): | ||||
import pprint | import pprint | ||||
from swh.core import config | from swh.core import config | ||||
if not config_file: | if not config_file: | ||||
config_file = DEFAULT_CONFIG_PATH | config_file = DEFAULT_CONFIG_PATH | ||||
try: | try: | ||||
logging.info(f"Loading configuration from: {config_file}") | logging.info("Loading configuration from: %s", config_file) | ||||
conf = config.read_raw_config(config.config_basepath(config_file)) | conf = config.read_raw_config(config.config_basepath(config_file)) | ||||
if not conf: | if not conf: | ||||
raise ValueError(f"Cannot parse configuration file: {config_file}") | raise ValueError(f"Cannot parse configuration file: {config_file}") | ||||
if config_file == DEFAULT_CONFIG_PATH: | if config_file == DEFAULT_CONFIG_PATH: | ||||
try: | try: | ||||
conf = conf["swh"]["fuse"] | conf = conf["swh"]["fuse"] | ||||
except KeyError: | except KeyError: | ||||
pass | pass | ||||
# recursive merge not done by config.read | # recursive merge not done by config.read | ||||
conf = config.merge_configs(DEFAULT_CONFIG, conf) | conf = config.merge_configs(DEFAULT_CONFIG, conf) | ||||
except Exception as err: | except Exception as err: | ||||
logging.warning(f"Using default configuration (cannot load custom one: {err})") | logging.warning("Using default configuration (cannot load custom one: %s)", err) | ||||
conf = DEFAULT_CONFIG | conf = DEFAULT_CONFIG | ||||
logging.info(f"Read configuration: \n{pprint.pformat(conf)}") | logging.info("Read configuration: \n%s", pprint.pformat(conf)) | ||||
ctx.ensure_object(dict) | ctx.ensure_object(dict) | ||||
ctx.obj["config"] = conf | ctx.obj["config"] = conf | ||||
@fuse.command(name="mount") | @fuse.command(name="mount") | ||||
@click.argument( | @click.argument( | ||||
"path", | "path", | ||||
required=True, | required=True, | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | def umount(ctx, path): | ||||
""" | """ | ||||
import logging | import logging | ||||
import subprocess | import subprocess | ||||
try: | try: | ||||
subprocess.run(["fusermount", "-u", path], check=True) | subprocess.run(["fusermount", "-u", path], check=True) | ||||
except subprocess.CalledProcessError as err: | except subprocess.CalledProcessError as err: | ||||
logging.error( | logging.error( | ||||
f"cannot unmount virtual file system: " | "cannot unmount virtual file system: '%s' returned exit status %d", | ||||
f"\"{' '.join(err.cmd)}\" returned exit status {err.returncode}" | " ".join(err.cmd), | ||||
err.returncode, | |||||
) | ) | ||||
ctx.exit(1) | ctx.exit(1) | ||||
@fuse.command() | @fuse.command() | ||||
@click.pass_context | @click.pass_context | ||||
def clean(ctx): | def clean(ctx): | ||||
"""Clean on-disk cache(s). | """Clean on-disk cache(s). | ||||
Show All 12 Lines |