Skip to content

Commit

Permalink
Commit changes to continue.
Browse files Browse the repository at this point in the history
  • Loading branch information
GeigerJ2 committed Feb 10, 2025
1 parent 42e76ce commit de8f92f
Show file tree
Hide file tree
Showing 11 changed files with 553 additions and 256 deletions.
71 changes: 49 additions & 22 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,37 +273,57 @@ def profile_delete(force, delete_data, profiles):

@verdi_profile.command('mirror')
@options.PATH()
@options.DRY_RUN()
@options.OVERWRITE()
# @options.INCREMENTAL()
@options.DUMP_PROCESSES()
@options.DEDUPLICATE()
@options.GROUPS()
@options.ORGANIZE_BY_GROUPS()
# @options.DEDUPLICATE()
# @click.option(
# '--check-dirs/--no-check-dirs',
# default=False,
# show_default=True,
# help='Check for existence of dump directories. Otherwise, incremental mirroring is only evaluated from the log.')
@click.option(
'--symlink-duplicates/--no-symlink-duplicates',
default=True,
show_default=True,
help='Symlink data if the same node is contained in multiple groups.')
@click.option(
'--delete-missing/--no-delete-missing',
default=False,
show_default=True,
help="If a previously dumped node is deleted from AiiDA's DB, also delete the corresponding dump directory.")
@click.option(
'--extra-calc-dirs/--no-extra-calc-dirs',
default=False,
show_default=True,
help='If a top-level process calls sub-processes, create a designated directory only for the top-level process.')
@options.INCLUDE_INPUTS()
@options.INCLUDE_OUTPUTS()
@options.INCLUDE_ATTRIBUTES()
@options.INCLUDE_EXTRAS()
@options.FLAT()
@options.DUMP_CONFIG_FILE()
@options.GROUPS()
@options.ORGANIZE_BY_GROUPS()
@options.DRY_RUN()
@click.pass_context
def profile_mirror(
ctx,
path,
overwrite,
organize_by_groups,
dry_run,
overwrite,
dump_processes,
deduplicate,
groups,
organize_by_groups,
symlink_duplicates,
delete_missing,
extra_calc_dirs,
# check_dirs,
include_inputs,
include_outputs,
include_attributes,
include_extras,
flat,
dump_config_file,
groups,
):
"""Dump all data in an AiiDA profile's storage to disk."""
"""Dump all data in an AiiDA profile's storage to disk in a human-readable directory tree."""

import json
from datetime import datetime
Expand All @@ -313,6 +333,7 @@ def profile_mirror(
from aiida.tools.dumping.base import BaseDumper
from aiida.tools.dumping.logger import DumpLogger
from aiida.tools.dumping.utils import prepare_dump_path
from aiida.tools.dumping.config import ProfileDumpConfig

profile = ctx.obj['profile']

Expand All @@ -321,7 +342,7 @@ def profile_mirror(
if path is None:
path = Path.cwd() / f'{profile.name}-mirror'

echo.echo_report(f'Mirroring data of profile `{profile.name}`at path: `{path}`.')
echo.echo_report(f'Mirroring data of profile `{profile.name}` at path: `{path}`.')

SAFEGUARD_FILE: str = '.verdi_profile_mirror' # noqa: N806
safeguard_file_path: Path = path / SAFEGUARD_FILE
Expand All @@ -336,8 +357,6 @@ def profile_mirror(
except FileExistsError as exc:
echo.echo_critical(str(exc))

breakpoint()

try:
with safeguard_file_path.open('r') as fhandle:
last_dump_time = datetime.fromisoformat(fhandle.readlines()[-1].strip().split()[-1]).astimezone()
Expand All @@ -346,9 +365,10 @@ def profile_mirror(

if dry_run:
node_counts = ProfileDumper._get_number_of_nodes_to_dump(last_dump_time)
node_counts_str = ' & '.join(f'{count} {node_type}' for node_type, count in node_counts.items())
dry_run_message = f'Dry run for mirroring of profile `{profile.name}`: {node_counts_str} to dump.\n'
dry_run_message = f'Dry run for mirroring of profile `{profile.name}`. Would dump:'
echo.echo_report(dry_run_message)
for count, node_type in node_counts.items():
echo.echo_report(f'{count}: {node_type}')
return

if incremental:
Expand Down Expand Up @@ -376,18 +396,25 @@ def profile_mirror(
flat=flat,
)

# breakpoint()
profile_dump_config = ProfileDumpConfig(
dump_processes=dump_processes,
symlink_duplicates=symlink_duplicates,
delete_missing=delete_missing,
extra_calc_dirs=extra_calc_dirs,
organize_by_groups=organize_by_groups,
)

profile_dumper = ProfileDumper(
profile=profile,
profile_dump_config=profile_dump_config,
base_dumper=base_dumper,
process_dumper=process_dumper,
dump_logger=dump_logger,
groups=groups,
organize_by_groups=organize_by_groups,
deduplicate=deduplicate,
profile=profile,
dump_processes=dump_processes,
)

profile_dumper.dump()
profile_dumper.dump_processes()

# Append the current time to the file
last_dump_time = datetime.now().astimezone()
Expand Down
23 changes: 7 additions & 16 deletions src/aiida/cmdline/params/options/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@
'DB_PORT',
'DB_USERNAME',
'DEBUG',
'DEDUPLICATE',
'DESCRIPTION',
'DICT_FORMAT',
'DICT_KEYS',
'DRY_RUN',
'DUMP_CONFIG_FILE',
'DUMP_PROCESSES',
'EXIT_STATUS',
'EXPORT_FORMAT',
Expand Down Expand Up @@ -792,13 +790,13 @@ def set_log_level(ctx, _param, value):
show_default=True,
)

DEDUPLICATE = OverridableOption(
'--deduplicate/--no-deduplicate',
is_flag=True,
default=True,
show_default=True,
help='',
)
# DEDUPLICATE = OverridableOption(
# '--deduplicate/--no-deduplicate',
# is_flag=True,
# default=True,
# show_default=True,
# help='',
# )

DUMP_PROCESSES = OverridableOption(
'--dump-processes/--no-dump-processes',
Expand All @@ -808,13 +806,6 @@ def set_log_level(ctx, _param, value):
help='Dump process data.',
)

DUMP_CONFIG_FILE = OverridableOption(
'--dump-config-file',
default=None,
type=types.FileOrUrl(),
help='Provide dumping options via a config file in YAML format.',
)

ORGANIZE_BY_GROUPS = OverridableOption(
'--organize-by-groups/--no-organize-by-groups',
default=True,
Expand Down
2 changes: 2 additions & 0 deletions src/aiida/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from datetime import datetime
from typing import Any, Dict
from uuid import UUID
from aiida.manage import get_manager, load_profile
from aiida.manage.configuration.profile import Profile

from .lang import classproperty

Expand Down
1 change: 1 addition & 0 deletions src/aiida/repository/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ def copy_tree(self, target: Union[str, pathlib.Path], path: Optional[FilePath] =
dirpath.mkdir(parents=True, exist_ok=True)

with self.open(root / filename) as handle:
# TODO: Possibly skip
filepath.write_bytes(handle.read())

# these methods are not actually used in aiida-core, but are here for completeness
Expand Down
4 changes: 4 additions & 0 deletions src/aiida/tools/dumping/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

@dataclass
class BaseDumper:
"""Container for shared arguments of all Dumper classes."""

dump_parent_path: Path | None = None
overwrite: bool = False
incremental: bool = True
check_dirs: bool = False
# TODO: Make this a per-class attribute?
last_dump_time: datetime | None = None

def __post_init__(self):
Expand Down
Loading

0 comments on commit de8f92f

Please sign in to comment.