Skip to content

Commit

Permalink
feat(command): add --dry-run option for del command (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCrab13 authored Mar 23, 2024
1 parent c83851f commit 99f038a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
17 changes: 11 additions & 6 deletions docs/source/commands/del.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ pdbstore del
.. code-block:: text
$ pdbstore del -h
usage: pdbstore del [-s DIRECTORY] [-V [LEVEL]] [-L PATH] [-C PATH] [-S NAME]
[-f NAME] [-h]
[ID ...]
usage: pdbstore del [-s DIRECTORY] [--dry-run] [-V [LEVEL]] [-L PATH] [-C PATH]
[-S NAME] [-f NAME] [-h] [ID ...]
Delete files from local symbol store
Expand All @@ -19,6 +18,8 @@ pdbstore del
-s DIRECTORY, --store-dir DIRECTORY
Local root directory for the symbol store. [env var:
PDBSTORE_STORAGE_DIR]
--dry-run Do not delete file or directory, but show a list of paths
to be removed.
-V [LEVEL], --verbosity [LEVEL]
Level of detail of the output. Valid options from less
verbose to more verbose: -Vquiet, -Verror, -Vwarning,
Expand All @@ -36,8 +37,12 @@ pdbstore del
-h, --help show this help message and exit
The ``pdbstore del`` will search for the speciifed transaction identifiers and delete
them from the specified if exists.
The ``pdbstore del`` will search for the specified transaction identifiers and delete
all required associated files. A file will be automatically deleted if it is not referenced
anymore by the store.

The ``--dry-run`` option can be used to obtain a summary of files to be deleted along
the specified transaction.

The ``pdbstore del`` will perform the requested delete operation with using transaction
identifier as unique criteria. If you want to delete transactions given more criteria,
Expand All @@ -49,4 +54,4 @@ The ``pdbstore del`` command will:
- extract **GUID** and **age** from required files
- add files that are not referenced yet based on their **GUID** and **age**
- delete oldest transactions if required
- print a summary to **stdout** stream
- print a summary to **stdout** stream
9 changes: 8 additions & 1 deletion pdbstore/cli/commands/del.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ def delete(parser: PDBStoreArgumentParser, *args: Any) -> Any:
help="Transaction ID string.",
)

parser.add_argument(
"--dry-run",
dest="dry_run",
action="store_true",
help="""Do not delete file or directory, but show a list of paths to be removed.""",
)

add_storage_arguments(parser)
add_global_arguments(parser)

Expand All @@ -63,7 +70,7 @@ def delete(parser: PDBStoreArgumentParser, *args: Any) -> Any:

for trans_id in transaction_id if isinstance(transaction_id, list) else [transaction_id]:
try:
summary_del: Summary = store.delete_transaction(trans_id)
summary_del: Summary = store.delete_transaction(trans_id, opts.dry_run)
except PDBStoreException as exp:
output.error(str(exp))
summary_del = Summary(trans_id, OpStatus.FAILED, TransactionType.DEL, str(exp))
Expand Down
32 changes: 32 additions & 0 deletions tests/cli/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@ def test_complete(capsys, tmp_store_dir, test_data_native_dir):
assert len(store.Store(tmp_store_dir).history) == 4


def test_complete_with_dry_run(tmp_store_dir, test_data_native_dir):
"""test complete command-line with --dry-run option"""

argv = [
"--store-dir",
str(tmp_store_dir),
"--product-name",
"myproduct",
"--product-version",
"1.0.0",
str(test_data_native_dir / "dummyapp.pdb"),
]

# New file into the store and twice to have 2 records
assert cli.cli.main(["add"] + argv) == 0
assert len(store.Store(tmp_store_dir).history) == ERROR_GENERAL
assert cli.cli.main(["add"] + argv) == 0
assert len(store.Store(tmp_store_dir).history) == 2

# Test through direct command-line
with mock.patch(
"sys.argv",
["pdbstore", "del", "1", "--dry-run"] + argv[0:2],
):
assert cli.cli.main() == SUCCESS
assert len(store.Store(tmp_store_dir).history) == 2

# Test with direct call to main function
assert cli.cli.main(["del", "2", "--dry-run"] + argv[0:2]) == SUCCESS
assert len(store.Store(tmp_store_dir).history) == 2


def test_complete_with_config(dynamic_config_file, test_data_native_dir):
"""test complete command-line with configuration file usage"""
argv = [
Expand Down

0 comments on commit 99f038a

Please sign in to comment.