diff --git a/rose/__main__.py b/rose/__main__.py index 1fc4c09..d360f87 100644 --- a/rose/__main__.py +++ b/rose/__main__.py @@ -6,7 +6,7 @@ from rose.cache.database import migrate_database from rose.cache.update import update_cache_for_all_releases from rose.foundation.conf import Config -from rose.virtualfs import start_virtualfs +from rose.virtualfs import mount_virtualfs, unmount_virtualfs @dataclass @@ -17,9 +17,9 @@ class Context: @click.group() @click.option("--verbose", "-v", is_flag=True) @click.pass_context -def cli(clickctx: click.Context, verbose: bool) -> None: +def cli(cc: click.Context, verbose: bool) -> None: """A filesystem-driven music library manager.""" - clickctx.obj = Context( + cc.obj = Context( config=Config.read(), ) @@ -27,7 +27,7 @@ def cli(clickctx: click.Context, verbose: bool) -> None: logging.getLogger().setLevel(logging.DEBUG) # Migrate the database on every command invocation. - migrate_database(clickctx.obj.config) + migrate_database(cc.obj.config) @cli.group() @@ -37,16 +37,16 @@ def cache() -> None: @cache.command() @click.pass_obj -def refresh(c: Context) -> None: +def refresh(ctx: Context) -> None: """Refresh the cached data from disk.""" - update_cache_for_all_releases(c.config) + update_cache_for_all_releases(ctx.config) @cache.command() @click.pass_obj -def clear(c: Context) -> None: +def clear(ctx: Context) -> None: """Clear the cache; empty the database.""" - c.config.cache_database_path.unlink() + ctx.config.cache_database_path.unlink() @cli.group() @@ -54,11 +54,18 @@ def fs() -> None: """Manage the virtual library.""" -@cli.command() +@fs.command() @click.pass_obj -def mount(c: Context) -> None: +def mount(ctx: Context) -> None: """Mount the virtual library.""" - start_virtualfs(c.config) + mount_virtualfs(ctx.config) + + +@fs.command() +@click.pass_obj +def unmount(ctx: Context) -> None: + """Unmount the virtual library.""" + unmount_virtualfs(ctx.config) if __name__ == "__main__": diff --git a/rose/virtualfs/__init__.py b/rose/virtualfs/__init__.py index 7e16271..e135fc4 100644 --- a/rose/virtualfs/__init__.py +++ b/rose/virtualfs/__init__.py @@ -1,3 +1,5 @@ +import subprocess + import fuse from rose.foundation.conf import Config @@ -9,7 +11,11 @@ class VirtualFS(fuse.Fuse): pass -def start_virtualfs(c: Config): +def mount_virtualfs(c: Config) -> None: server = VirtualFS() server.parse([str(c.fuse_mount_dir)]) server.main() + + +def unmount_virtualfs(c: Config) -> None: + subprocess.run(["umount", str(c.fuse_mount_dir)])