annotate data_manager/make_json.py @ 2:cdef63d8a141 draft

Uploaded
author devteam
date Mon, 27 Apr 2015 16:13:06 -0400
parents d5d803e654dd
children 6f0294046f41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d5d803e654dd Uploaded
devteam
parents:
diff changeset
1 import json
d5d803e654dd Uploaded
devteam
parents:
diff changeset
2 import argparse
d5d803e654dd Uploaded
devteam
parents:
diff changeset
3 import os
d5d803e654dd Uploaded
devteam
parents:
diff changeset
4 import shutil
d5d803e654dd Uploaded
devteam
parents:
diff changeset
5
d5d803e654dd Uploaded
devteam
parents:
diff changeset
6 parser = argparse.ArgumentParser(description='Create data manager json.')
d5d803e654dd Uploaded
devteam
parents:
diff changeset
7 parser.add_argument('--db', dest='database', action='store', help='Database name')
d5d803e654dd Uploaded
devteam
parents:
diff changeset
8 parser.add_argument('--out', dest='output', action='store', help='JSON filename')
d5d803e654dd Uploaded
devteam
parents:
diff changeset
9
d5d803e654dd Uploaded
devteam
parents:
diff changeset
10 args = parser.parse_args()
d5d803e654dd Uploaded
devteam
parents:
diff changeset
11
d5d803e654dd Uploaded
devteam
parents:
diff changeset
12 def main(args):
d5d803e654dd Uploaded
devteam
parents:
diff changeset
13 data_manager_entry = {}
d5d803e654dd Uploaded
devteam
parents:
diff changeset
14 data_manager_entry['value'] = args.database.lower()
d5d803e654dd Uploaded
devteam
parents:
diff changeset
15 data_manager_entry['name'] = args.database
d5d803e654dd Uploaded
devteam
parents:
diff changeset
16 data_manager_entry['path'] = '.'
d5d803e654dd Uploaded
devteam
parents:
diff changeset
17 data_manager_json = dict(data_tables=dict(kraken_databases=data_manager_entry))
d5d803e654dd Uploaded
devteam
parents:
diff changeset
18 params = json.loads(open(args.output).read())
d5d803e654dd Uploaded
devteam
parents:
diff changeset
19 target_directory = params['output_data'][0]['extra_files_path']
d5d803e654dd Uploaded
devteam
parents:
diff changeset
20 os.mkdir(target_directory)
d5d803e654dd Uploaded
devteam
parents:
diff changeset
21 output_path = os.path.join(os.getcwd(), 'kraken-database')
d5d803e654dd Uploaded
devteam
parents:
diff changeset
22 for filename in os.listdir(output_path):
d5d803e654dd Uploaded
devteam
parents:
diff changeset
23 shutil.move(os.path.join(output_path, filename), target_directory)
d5d803e654dd Uploaded
devteam
parents:
diff changeset
24 file(args.output, 'w').write(json.dumps(data_manager_json))
d5d803e654dd Uploaded
devteam
parents:
diff changeset
25
d5d803e654dd Uploaded
devteam
parents:
diff changeset
26 if __name__ == '__main__':
d5d803e654dd Uploaded
devteam
parents:
diff changeset
27 main(args)
d5d803e654dd Uploaded
devteam
parents:
diff changeset
28