annotate data_manager/path_name_value_key_manager.py @ 0:5f8d9309058b draft

planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
author rhpvorderman
date Mon, 25 Sep 2017 03:35:26 -0400
parents
children 8495c49cd056
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
1 #!/usr/bin/env python
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
2
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
3 import json
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
4 import argparse
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
5 import os
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
6 import yaml
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
7
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
8 def _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
9 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
10 data_manager_dict['data_tables'][ data_table_name ] = data_manager_dict['data_tables'].get( data_table_name, [] )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
11 data_manager_dict['data_tables'][ data_table_name ].append( data_table_entry )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
12 return data_manager_dict
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
13
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
14
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
15 def check_param(name, value, default=None, check_tab=True):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
16 if value in [ None, '', '?' ]:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
17 if default:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
18 print "Using {0} for {1} as no value provided".format( default, name )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
19 value = default
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
20 else:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
21 raise Exception( '{0} is not a valid {1}. You must specify a valid {1}.'.format( value, name ) )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
22 if check_tab and "\t" in value:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
23 raise Exception( '{0} is not a valid {1}. It may not contain a tab because these are used as seperators by galaxy .'.format( value, name ) )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
24 return value
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
25
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
26 def prefix_exists(directory, prefix):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
27 '''checks if files exist with prefix in a directory. Returns Boolean'''
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
28 matched_files = []
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
29 directory_files = os.listdir(directory)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
30 for directory_file in directory_files:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
31 if directory_file.startswith(prefix):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
32 matched_files.append(directory_file)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
33 # Empty list should return False
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
34 return bool(matched_files)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
35
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
36 def prefix_plus_extension_exists(directory, prefix, extension):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
37 '''checks if files exist with prefix in a directory. Returns Boolean'''
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
38 matched_files = []
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
39 directory_files = os.listdir(directory)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
40 for directory_file in directory_files:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
41 if directory_file.startswith(prefix) and directory_file.endswith(extension):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
42 matched_files.append(directory_file)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
43 # Empty list should return False
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
44 return bool(matched_files)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
45
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
46 def main():
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
47
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
48 #value = "test_value"
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
49 #name = "test_name"
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
50 #print '{0} other {1} more{0}'.format(value, name )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
51 #print '{0} is not a valid {1}. It may not contain a tab.'.format( value, name )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
52
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
53 #Parse Command Line
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
54 parser = argparse.ArgumentParser()
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
55 parser.add_argument( '--value', action='store', type=str, default=None, help='value' )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
56 parser.add_argument( '--dbkey', action='store', type=str, default=None, help='dbkey' )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
57 parser.add_argument( '--name', action='store', type=str, default=None, help='name' )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
58 parser.add_argument( '--path', action='store', type=str, default=None, help='path' )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
59 parser.add_argument( '--data_table_name', action='store', type=str, default=None, help='path' )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
60 parser.add_argument( '--json_output_file', action='store', type=str, default=None, help='path' )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
61 options = parser.parse_args()
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
62
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
63 path = check_param("path", options.path)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
64 basename = os.path.basename(path)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
65 filename = os.path.splitext(basename)[0]
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
66 name = check_param("name", options.name, default=filename)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
67 value = check_param("value", options.value, default=name)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
68 dbkey = check_param("dbkey", options.dbkey, default=value)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
69 data_table_name = check_param("data_table_name", options.data_table_name)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
70 json_output_file = check_param("json_output_file", options.json_output_file, check_tab=False)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
71
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
72 # Check if file or prefix exists
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
73 indexes = yaml.load(file(os.path.join(os.path.dirname(__file__), 'indexes.yml')))
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
74 index_dict = indexes.get(data_table_name,{})
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
75 index_name = index_dict.get('name','index')
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
76 index_extensions = index_dict.get('extensions', [''])
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
77 no_prefix = index_dict.get('no_prefix', False)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
78 if not no_prefix:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
79 dirname = os.path.dirname(path)
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
80 prefix = basename
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
81 for extension in index_extensions:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
82 if not prefix_plus_extension_exists(dirname,prefix,extension):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
83 raise Exception( 'Unable to find files with prefix "{0}" and extension "{1}" in {2}. Is this a valid {3}?'.format( prefix, extension, dirname, index_name ) )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
84 else:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
85 if not os.path.exists(path):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
86 raise Exception( 'Unable to find path {0}.'.format( path ) )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
87
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
88 if os.path.exists(json_output_file):
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
89 params = json.loads( open( json_output_file ).read() )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
90 print "params", params
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
91 else:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
92 params = {}
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
93
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
94 data_manager_dict = {}
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
95 data_table_entry = dict( value=value, dbkey=dbkey, name=name, path=path )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
96 _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
97
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
98 #save info to json file
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
99 with open( json_output_file, 'wb' ) as output_file:
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
100 output_file.write( json.dumps( data_manager_dict ) )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
101 output_file.write( "\n" )
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
102
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
103 if __name__ == "__main__":
5f8d9309058b planemo upload for repository https://github.com/LUMC/lumc-galaxy-tools/tree/master/data_manager_select_index_by_path commit b3f86a0c89c2956f40ee0d462cb31a60eb91724a
rhpvorderman
parents:
diff changeset
104 main()