Skip to content

Commit

Permalink
implement fs unmount
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 10, 2023
1 parent d0387aa commit 6bfc48d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
29 changes: 18 additions & 11 deletions rose/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,17 +17,17 @@ 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(),
)

if verbose:
logging.getLogger().setLevel(logging.DEBUG)

# Migrate the database on every command invocation.
migrate_database(clickctx.obj.config)
migrate_database(cc.obj.config)


@cli.group()
Expand All @@ -37,28 +37,35 @@ 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()
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__":
Expand Down
8 changes: 7 additions & 1 deletion rose/virtualfs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import subprocess

import fuse

from rose.foundation.conf import Config
Expand All @@ -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)])

0 comments on commit 6bfc48d

Please sign in to comment.