Skip to content

Commit a17c1c7

Browse files
committed
Helper tool
1 parent 7d5fae3 commit a17c1c7

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

biotools_cleaner/cleaner.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
5+
from .tool import Tool
6+
7+
8+
if __name__ == '__main__':
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument('input', type=str, help="Path to yaml file")
11+
parser.add_argument('output', type=str, help="Output dir (ie, Research-software-ecosystem repository)")
12+
parser.add_argument('--dry-run', action='store_true', help="Dry run")
13+
parser.add_argument('--cleanup', action='store_true', help="Remove old layout files from repository")
14+
args = parser.parse_args()
15+
16+
tool = Tool(args.input)
17+
tool.write_yaml(args.output, dry_run=args.dry_run, remove_input=args.cleanup)

biotools_cleaner/cleaner_batch.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import pathlib
5+
6+
from .tool import Tool
7+
8+
if __name__ == '__main__':
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument('rse_repo', type=str, help="Research-software-ecosystem data folder")
11+
parser.add_argument('--dry-run', action='store_true', help="Dry run")
12+
parser.add_argument('--cleanup', action='store_true', help="Remove old layout files from repository")
13+
args = parser.parse_args()
14+
15+
for path in pathlib.Path(args.rse_repo).rglob("biocontainers.yaml"):
16+
tool = Tool(path.name)
17+
tool.write_yaml(args.rse_repo, dry_run=args.dry_run, remove_input=args.cleanup)

biotools_cleaner/tool.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import pathlib
3+
import logging
4+
from yaml import safe_load, dump
5+
6+
7+
class Tool:
8+
9+
def __init__(self, tool_yaml):
10+
self.yaml_path = tool_yaml
11+
self.yaml_data = {}
12+
13+
with open(tool_yaml, 'r') as f:
14+
self.data = safe_load(f)
15+
16+
logging.info('Processing ' + tool_yaml)
17+
18+
def write_yaml(self, output_dir, dry_run=False, remove_input=False):
19+
if not self.yaml_data.get('software'):
20+
logging.error('"software" key not found or empty')
21+
if len(self.yaml_data.get('software')) > 1:
22+
logging.error('More than one software in yaml file: this should not happen')
23+
tool_name = list(self.yaml_data['software'].keys())[0]
24+
25+
output_path = os.path.join(output_dir, tool_name, '{}.biocontainers.yaml'.format(tool_name))
26+
27+
logging.info("Moving {} to {}".format(self.yaml_path, output_path))
28+
29+
if not dry_run:
30+
pathlib.Path(os.path.join(output_dir, tool_name)).mkdir(parents=True, exist_ok=True)
31+
with open(output_path, 'w') as f:
32+
dump(self.yaml_data, f)
33+
if remove_input:
34+
logging.info("Removing {}".format(self.yaml_path))
35+
os.remove(self.yaml_path)

0 commit comments

Comments
 (0)