Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementation for archiving a pack file #138

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ repos:
rev: 21.12b0
hooks:
- id: black
additional_dependencies: ['click<8.1']

- repo: https://github.com/PyCQA/pylint
rev: v2.12.2
Expand Down
88 changes: 88 additions & 0 deletions disk_objectstore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,91 @@ def optimize(
container.clean_storage(vacuum=vacuum)
size = sum(f.stat().st_size for f in dostore.path.glob("**/*") if f.is_file())
click.echo(f"Final container size: {round(size/1000, 2)} Mb")


@main.group("archive")
def archive():
"""
Interface for managing archived packs.

An archived pack is essentially an ZIP file and will no longer be considered for writing new
data. Once an pack is archived, it can be moved to other locations, for example, networked storages.
"""


@archive.command("list")
@pass_dostore
def archive_list(dosstore: ContainerContext):
"""List all archives in the container"""

with dosstore.container as container:
location = container.get_archive_locations()
click.echo(json.dumps(location, indent=2))


@archive.command("update-location")
@click.argument("pack_id")
@click.argument("new_location")
@click.option("--force", help="Skip checks if passed", is_flag=True, default=False)
@pass_dostore
def archive_update_location(
dosstore: ContainerContext, pack_id: str, new_location: str, force: bool
):
"""
Update the location of archive files

NOTE: relative path is interpreted as relative to the root folder of the container.
"""

with dosstore.container as container:
container._update_archive_location( # pylint: disable=protected-access
pack_id, new_location, force
)
click.echo(f"Updated location of pack {pack_id} to {new_location}")


@archive.command("create")
@click.argument("pack_id")
@click.option(
"--validate/--no-validate",
show_default=True,
help="Validate the created archive or not.",
)
@click.option(
"--trim-names/--no-trim-names",
show_default=True,
help="Trim the filenames in the archive, reduce storage overheads.",
)
@pass_dostore
def archive_create(
dosstore: ContainerContext, pack_id: str, validate: bool, trim_names: bool
):
"""Turn the pack_id into an archive pack"""
with dosstore.container as container:
archives = container.get_archived_pack_ids(return_str=True)
if pack_id in archives:
raise click.Abort(f"Pack {pack_id} is already archived!")
container.archive_pack(
pack_id, run_read_test=validate, trim_filenames=trim_names
)
location = container.get_archive_locations()[pack_id]
click.echo(f"Successfully archvied pack {pack_id} at {location}")


@archive.command("extract")
@click.argument("archive_path")
@click.argument("destination", type=click.Path(exists=False))
@pass_dostore
def archive_extract(
dosstore: ContainerContext,
archive_path: str,
destination: str,
):
"""
Extract an existing archive and renames the files in the destination folder
the same that used for the loose objects, so that they can be imported into a another container.
"""

with dosstore.container as container:
container.lossen_archive(archive_path, destination)
click.echo(f"Objects from {archive_path} have been extracted to {destination}")
Loading