Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Add minumum age option and set default age to 14. Add usage to readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nana Mensah authored and Nana Mensah committed Oct 28, 2019
1 parent 54712f5 commit 38f37be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
24 changes: 22 additions & 2 deletions wscleaner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions wscleaner/wscleaner/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion wscleaner/wscleaner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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:
Expand Down

0 comments on commit 38f37be

Please sign in to comment.