comparison json_data_source_mod.py @ 16:3eabece82abb draft

Uploaded 20170601
author fabio
date Thu, 01 Jun 2017 13:07:22 -0400
parents babc444d4bd0
children 2c58e3cc1b30
comparison
equal deleted inserted replaced
15:78bd202e8687 16:3eabece82abb
103 else: 103 else:
104 meta_dict[ 'dataset_id' ] = dataset_id 104 meta_dict[ 'dataset_id' ] = dataset_id
105 return "%s\n" % json.dumps( meta_dict ) 105 return "%s\n" % json.dumps( meta_dict )
106 106
107 107
108 def walk_on_archive(target_output_filename, check_ext, archive_name, appdata_path): 108 def walk_on_archive(target_output_filename, check_ext, archive_name, appdata_path, db_key="?"):
109 archive_name = archive_name.replace("_", "-").replace(".", "-") 109 archive_name = archive_name.replace("_", "-").replace(".", "-")
110 with tarfile.open( target_output_filename, check_ext ) as tf: 110 with tarfile.open( target_output_filename, check_ext ) as tf:
111 for entry in tf: 111 for entry in tf:
112 if entry.isfile(): 112 if entry.isfile():
113 fileobj = tf.extractfile( entry ) 113 fileobj = tf.extractfile( entry )
114 # reserve the underscore for the collection searator 114 # reserve the underscore for the collection searator
115 filename = os.path.basename( entry.name ).replace("_", "-") 115 filename = os.path.basename( entry.name ).replace("_", "-")
116 extension = splitext( filename )[1] 116 extension = splitext( filename )[1]
117 # pattern: (?P&lt;identifier_0&gt;[^_]+)_(?P&lt;identifier_1&gt;[^_]+) 117 # pattern: (?P<identifier_0>[^_]+)_(?P<identifier_1>[^_]+)_(?P<ext>[^_]+)_(?P<dbkey>[^_]+)
118 if (len(extension) > 0): 118 if (len(extension) > 0):
119 filename = (filename[0:len(filename)-(len(extension)+1)]).replace(".", "-") + "." + extension 119 filename = (filename[0:len(filename)-(len(extension)+1)]).replace(".", "-") + "_" + extension
120 else: 120 else:
121 extension = "auto" 121 extension = "auto"
122 filename_with_collection_prefix = archive_name + "_" + filename 122 filename_with_collection_prefix = archive_name + "_" + filename + "_" + db_key
123 target_entry_output_filename = os.path.join(appdata_path, filename_with_collection_prefix) 123 target_entry_output_filename = os.path.join(appdata_path, filename_with_collection_prefix)
124 store_file_from_archive( fileobj, target_entry_output_filename ) 124 store_file_from_archive( fileobj, target_entry_output_filename )
125 return True 125 return True
126 126
127 127
173 extra_files_path = ''.join( [ target_output_filename, 'files' ] ) 173 extra_files_path = ''.join( [ target_output_filename, 'files' ] )
174 download_extra_data( extra_data, extra_files_path ) 174 download_extra_data( extra_data, extra_files_path )
175 175
176 """ the following code handles archives and decompress them in a collection """ 176 """ the following code handles archives and decompress them in a collection """
177 if ( isArchive ): 177 if ( isArchive ):
178 walk_on_archive(target_output_path, check_ext, filename, appdata_path) 178 db_key = "?"
179 archive_metadata = query_item.get( 'metadata', None )
180 if archive_metadata is not None:
181 try:
182 db_key = archive_metadata.get( 'db_key' )
183 except:
184 pass
185 walk_on_archive(target_output_path, check_ext, filename, appdata_path, db_key)
179 186
180 return True 187 return True
181 188
182 189
183 def set_up_config_values(json_params): 190 def set_up_config_values(json_params):