Skip to content

Commit

Permalink
Merge pull request #754
Browse files Browse the repository at this point in the history
v5.1.0
  • Loading branch information
MatteoCampinoti94 authored Jan 10, 2025
2 parents 8b7d855 + db90a7c commit 3cbb8ae
Show file tree
Hide file tree
Showing 11 changed files with 728 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v5.1.0

### New Features

* `edit original puid` and `edit master puid` commands to set the PUID of original and master files respectively
* `manual extract` command to add manually extracted files
* `manual convert` command to add manually converted files

## v5.0.3

### Fixes
Expand Down
114 changes: 114 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [extract](#digiarch-extract)
* [edit](#digiarch-edit)
* [original](#digiarch-edit-original)
* [puid](#digiarch-edit-original-puid)
* [action](#digiarch-edit-original-action)
* [convert](#digiarch-edit-original-action-convert)
* [extract](#digiarch-edit-original-action-extract)
Expand All @@ -21,6 +22,7 @@
* [rename](#digiarch-edit-original-rename)
* [remove](#digiarch-edit-original-remove)
* [master](#digiarch-edit-master)
* [puid](#digiarch-edit-master-puid)
* [convert](#digiarch-edit-master-convert)
* [processed](#digiarch-edit-master-processed)
* [remove](#digiarch-edit-master-remove)
Expand All @@ -29,6 +31,9 @@
* [statutory](#digiarch-edit-statutory)
* [remove](#digiarch-edit-statutory-remove)
* [rollback](#digiarch-edit-rollback)
* [manual](#digiarch-manual)
* [extract](#digiarch-manual-extract)
* [convert](#digiarch-manual-convert)
* [search](#digiarch-search)
* [original](#digiarch-search-original)
* [master](#digiarch-search-master)
Expand All @@ -55,6 +60,7 @@ Commands:
identify Identify files.
extract Unpack archives.
edit Edit the database.
manual Perform actions manually.
search Search the database.
log Display the event log.
upgrade Upgrade the database.
Expand Down Expand Up @@ -326,13 +332,33 @@ Options:
--help Show this message and exit.
Commands:
puid Change PUID.
action Change actions of original files.
processed Set original files as processed.
lock Lock files.
rename Change file extensions.
remove Remove files.
```

##### digiarch edit original puid

```
Usage: digiarch edit original puid [OPTIONS] PUID QUERY REASON
Change PUID of original files.
To lock the files after editing them, use the --lock option.
To see the changes without committing them, use the --dry-run option.
For details on the QUERY argument, see the edit command.
Options:
--lock Lock the edited files.
--dry-run Show changes without committing them.
--help Show this message and exit.
```

##### digiarch edit original action

```
Expand Down Expand Up @@ -583,11 +609,28 @@ Options:
--help Show this message and exit.
Commands:
puid Change PUID.
convert Set access convert action.
processed Set master files as processed.
remove Remove files.
```

##### digiarch edit master puid

```
Usage: digiarch edit master puid [OPTIONS] PUID QUERY REASON
Change PUID of master files.
To see the changes without committing them, use the --dry-run option.
For details on the QUERY argument, see the edit command.
Options:
--dry-run Show changes without committing them.
--help Show this message and exit.
```

##### digiarch edit master convert

```
Expand Down Expand Up @@ -757,6 +800,77 @@ Options:
--help Show this message and exit.
```

### digiarch manual

```
Usage: digiarch manual [OPTIONS] COMMAND [ARGS]...
Perform complex actions manually when the automated tools fail or when one
is not available.
Options:
--help Show this message and exit.
Commands:
convert Add converted files.
extract Add extracted files.
```

#### digiarch manual extract

```
Usage: digiarch manual extract [OPTIONS] PARENT FILE...
Manually add files extracted from an archive, and assign them the PARENT
UUID.
The given FILEs can be single files or folders and must be located inside
OriginalDocuments.
To exclude children files when using a folder as target, use the --exclude
option.
If the files are not already in the database they will be added without
identification. Run the identify command to assign them a PUID and action.
If the files are in the database their parent value will be set to ORIGINAL
unless they already have one assigned, in which case they will be ignored.
Run the identify command to assign a PUID and action to newly-added files.
To see the changes without committing them, use the --dry-run option.
Options:
--exclude TEXT File and folder names to exclude. [multiple]
--dry-run Show changes without committing them.
--help Show this message and exit.
```

#### digiarch manual convert

```
Usage: digiarch manual convert [OPTIONS] ORIGINAL {master|access|statutory}
FILE...
Manually add converted files with ORIGINAL UUID as their parent.
\b Depending on the TARGET, a different type of ORIGINAL file will be
needed: * "master": original file parent * "access": master file parent *
"statutory": master file parent
The given FILEs must be located inside the MasterDocuments, AccessDocuments,
or Documents folder depending on the TARGET.
If the files are already in the database they will be ignored. Run the
identify command to assign a PUID (and action where applicable) to newly-
added files.
To see the changes without committing them, use the --dry-run option.
Options:
--dry-run Show changes without committing them.
--help Show this message and exit.
```

### digiarch search

```
Expand Down
2 changes: 1 addition & 1 deletion digiarch/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.0.3"
__version__ = "5.1.0"
2 changes: 2 additions & 0 deletions digiarch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .commands.identify import grp_identify
from .commands.init import cmd_init
from .commands.log import cmd_log
from .commands.manual import grp_manual
from .commands.search import grp_search
from .commands.upgrade import cmd_upgrade

Expand All @@ -28,6 +29,7 @@ def app():
app.add_command(grp_identify, grp_identify.name)
app.add_command(cmd_extract, cmd_extract.name)
app.add_command(grp_edit, grp_edit.name)
app.add_command(grp_manual, grp_manual.name)
app.add_command(grp_search, grp_search.name)
app.add_command(cmd_log, cmd_log.name)
app.add_command(cmd_upgrade, cmd_upgrade.name)
Expand Down
3 changes: 3 additions & 0 deletions digiarch/commands/edit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def edit_file_value(
property_value: Callable[[Any], Any] | Any, # noqa: ANN401
dry_run: bool,
*loggers: Logger,
lock: bool = False,
):
for file in query_table(table, query, [("lower(relative_path)", "asc")]):
value = property_value(getattr(file, property_name)) if callable(property_value) else property_value
Expand All @@ -46,6 +47,8 @@ def edit_file_value(
)
if not dry_run:
setattr(file, property_name, value)
if lock and hasattr(file, "lock"):
setattr(file, "lock", True)
table.update(file)
database.log.insert(event)
event.log(INFO, *loggers, show_args=["uuid", "data"], path=file.relative_path)
Expand Down
4 changes: 4 additions & 0 deletions digiarch/commands/edit/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .lock import cmd_lock_original
from .processed import cmd_processed_master
from .processed import cmd_processed_original
from .puid import cmd_puid_master
from .puid import cmd_puid_original
from .remove import cmd_remove_access
from .remove import cmd_remove_master
from .remove import cmd_remove_original
Expand Down Expand Up @@ -70,12 +72,14 @@ def grp_edit_statutory():
# noinspection DuplicatedCode
grp_edit.add_command(cmd_rollback, cmd_rollback.name)

grp_edit_original.add_command(cmd_puid_original, cmd_puid_original.name)
grp_edit_original.add_command(grp_action_original, grp_action_original.name)
grp_edit_original.add_command(cmd_processed_original, cmd_processed_original.name)
grp_edit_original.add_command(cmd_lock_original, cmd_lock_original.name)
grp_edit_original.add_command(cmd_rename_original, cmd_rename_original.name)
grp_edit_original.add_command(cmd_remove_original, cmd_remove_original.name)

grp_edit_master.add_command(cmd_puid_master, cmd_puid_master.name)
grp_edit_master.add_command(cmd_action_master_convert, cmd_action_master_convert.name)
grp_edit_master.add_command(cmd_processed_master, cmd_processed_master.name)
grp_edit_master.add_command(cmd_remove_master, cmd_remove_master.name)
Expand Down
110 changes: 110 additions & 0 deletions digiarch/commands/edit/puid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from acacore.utils.click import end_program
from acacore.utils.click import start_program
from acacore.utils.helpers import ExceptionManager
from click import argument
from click import command
from click import Context
from click import option
from click import pass_context

from digiarch.__version__ import __version__
from digiarch.commands.edit.common import edit_file_value
from digiarch.commands.edit.common import rollback_file_value
from digiarch.common import CommandWithRollback
from digiarch.common import get_avid
from digiarch.common import open_database
from digiarch.common import option_dry_run
from digiarch.common import rollback
from digiarch.query import argument_query
from digiarch.query import TQuery


@rollback("edit", rollback_file_value("puid"))
@command("puid", no_args_is_help=True, short_help="Change PUID.", cls=CommandWithRollback)
@argument("puid", nargs=1, type=str, required=True)
@argument_query(True, "uuid", ["uuid", "checksum", "puid", "relative_path", "action", "warning", "processed", "lock"])
@argument("reason", nargs=1, type=str, required=True)
@option("--lock", is_flag=True, default=False, help="Lock the edited files.")
@option_dry_run()
@pass_context
def cmd_puid_original(
ctx: Context,
puid: str,
query: TQuery,
reason: str,
lock: bool,
dry_run: bool,
):
"""
Change PUID of original files.
To lock the files after editing them, use the --lock option.
To see the changes without committing them, use the --dry-run option.
For details on the QUERY argument, see the edit command.
"""
avid = get_avid(ctx)

with open_database(ctx, avid) as database:
log_file, log_stdout, _ = start_program(ctx, database, __version__, None, True, True, dry_run)

with ExceptionManager(BaseException) as exception:
edit_file_value(
ctx,
database,
database.original_files,
query,
reason,
"original",
"puid",
puid,
dry_run,
log_stdout,
lock=lock,
)

end_program(ctx, database, exception, dry_run, log_file, log_stdout)


@rollback("edit", rollback_file_value("puid"))
@command("puid", no_args_is_help=True, short_help="Change PUID.", cls=CommandWithRollback)
@argument("puid", nargs=1, type=str, required=True)
@argument_query(True, "uuid", ["uuid", "checksum", "puid", "relative_path", "warning", "processed"])
@argument("reason", nargs=1, type=str, required=True)
@option_dry_run()
@pass_context
def cmd_puid_master(
ctx: Context,
puid: str,
query: TQuery,
reason: str,
dry_run: bool,
):
"""
Change PUID of master files.
To see the changes without committing them, use the --dry-run option.
For details on the QUERY argument, see the edit command.
"""
avid = get_avid(ctx)

with open_database(ctx, avid) as database:
log_file, log_stdout, _ = start_program(ctx, database, __version__, None, True, True, dry_run)

with ExceptionManager(BaseException) as exception:
edit_file_value(
ctx,
database,
database.master_files,
query,
reason,
"master",
"puid",
puid,
dry_run,
log_stdout,
)

end_program(ctx, database, exception, dry_run, log_file, log_stdout)
Loading

0 comments on commit 3cbb8ae

Please sign in to comment.