From 38f37be611a6fd65622d3a9d694a74e221fad90e Mon Sep 17 00:00:00 2001 From: Nana Mensah Date: Mon, 28 Oct 2019 10:59:35 +0000 Subject: [PATCH] Add minumum age option and set default age to 14. Add usage to readme. --- wscleaner/README.md | 24 ++++++++++++++++++++++-- wscleaner/wscleaner/lib.py | 3 +-- wscleaner/wscleaner/main.py | 3 ++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/wscleaner/README.md b/wscleaner/README.md index d470659..515e4cb 100644 --- a/wscleaner/README.md +++ b/wscleaner/README.md @@ -18,11 +18,31 @@ pip install workstation_housekeeping/wscleaner wscleaner --version # Print version number ``` -## Usage +## Quickstart ```bash wscleaner --set-key DNA_NEXUS_KEY # Cache dnanexus api key -wscleaner ROOT_DIRECTORY --logfile LOGFILE_PATH +wscleaner ROOT_DIRECTORY +``` + +## Usage + +``` +wscleaner [-h] [--set-key SET_KEY] [--print-key] [--dry-run] + [--logfile LOGFILE] [--min-age MIN_AGE] [--version] + root + +positional arguments: + root A directory containing runfolders to process + +optional arguments: + -h, --help show this help message and exit + --set-key SET_KEY Cache a DNA Nexus API key + --print-key Print the cached DNA Nexus API key + --dry-run Perform a dry run without deleting files + --logfile LOGFILE A path for the application logfile + --min-age MIN_AGE The age (days) a runfolder must be to be deleted + --version Print version ``` ## Test diff --git a/wscleaner/wscleaner/lib.py b/wscleaner/wscleaner/lib.py index 72c8804..7fc1040 100644 --- a/wscleaner/wscleaner/lib.py +++ b/wscleaner/wscleaner/lib.py @@ -174,7 +174,7 @@ def __validate(self, directory): self.logger.error(f'Directory does not exist: {directory}', exc_info=True) raise - def find_runfolders(self, min_age=14): + def find_runfolders(self, min_age=None): """Search the parent directory for subdirectories containing fastq.gz files. Args: min_age(int): Minimum age in days of runfolders returned. @@ -211,7 +211,6 @@ def check_logfiles(self, runfolder): def delete(self, runfolder): """Delete the local runfolder from the root directory and append name to self.deleted.""" - print(self.__dry_run) if self.__dry_run: self.logger.info(f'DRY RUN DELETE {runfolder.name}') else: diff --git a/wscleaner/wscleaner/main.py b/wscleaner/wscleaner/main.py index af2110a..cf8a51e 100644 --- a/wscleaner/wscleaner/main.py +++ b/wscleaner/wscleaner/main.py @@ -34,6 +34,7 @@ def cli_parser(): parser.add_argument('--dry-run', help='Perform a dry run without deleting files', action='store_true', default=False) parser.add_argument('root', help='A directory containing runfolders to process') parser.add_argument('--logfile', help='A path for the application logfile', default='mokaguys_logger.log') + parser.add_argument('--min-age', help='The age (days) a runfolder must be to be deleted', type=int, default=14) # Get version from setup.py as version CLI response version_number = pkg_resources.require("wscleaner")[0].version parser.add_argument('--version', help='Print version', action='version', version=f"wscleaner v{version_number}") @@ -56,7 +57,7 @@ def main(): # If dry-run CLI flag is given, no directories are deleted by the runfolder manager. RFM = RunFolderManager(args.root, dry_run=args.dry_run) logger.info(f'Root directory {args.root}') - local_runfolders = RFM.find_runfolders(min_age=0) + local_runfolders = RFM.find_runfolders(min_age=args.min_age) logger.debug(f'Found local runfolders: {[rf.name for rf in local_runfolders]}') for runfolder in local_runfolders: