diff 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
line wrap: on
line diff
--- a/json_data_source_mod.py	Tue May 30 15:56:33 2017 -0400
+++ b/json_data_source_mod.py	Thu Jun 01 13:07:22 2017 -0400
@@ -105,7 +105,7 @@
     return "%s\n" % json.dumps( meta_dict )
 
 
-def walk_on_archive(target_output_filename, check_ext, archive_name, appdata_path):
+def walk_on_archive(target_output_filename, check_ext, archive_name, appdata_path, db_key="?"):
     archive_name = archive_name.replace("_", "-").replace(".", "-")
     with tarfile.open( target_output_filename, check_ext ) as tf:
         for entry in tf:
@@ -114,12 +114,12 @@
                 # reserve the underscore for the collection searator
                 filename = os.path.basename( entry.name ).replace("_", "-")
                 extension = splitext( filename )[1]
-                # pattern: (?P<identifier_0>[^_]+)_(?P<identifier_1>[^_]+)
+                # pattern: (?P<identifier_0>[^_]+)_(?P<identifier_1>[^_]+)_(?P<ext>[^_]+)_(?P<dbkey>[^_]+)
                 if (len(extension) > 0):
-                    filename = (filename[0:len(filename)-(len(extension)+1)]).replace(".", "-") + "." + extension
+                    filename = (filename[0:len(filename)-(len(extension)+1)]).replace(".", "-") + "_" + extension
                 else:
                     extension = "auto"
-                filename_with_collection_prefix = archive_name + "_" + filename
+                filename_with_collection_prefix = archive_name + "_" + filename + "_" + db_key
                 target_entry_output_filename = os.path.join(appdata_path, filename_with_collection_prefix)
                 store_file_from_archive( fileobj, target_entry_output_filename )
     return True
@@ -175,7 +175,14 @@
 
     """ the following code handles archives and decompress them in a collection """
     if ( isArchive ):
-        walk_on_archive(target_output_path, check_ext, filename, appdata_path)
+        db_key = "?"
+        archive_metadata = query_item.get( 'metadata', None )
+        if archive_metadata is not None:
+            try:
+                db_key = archive_metadata.get( 'db_key' )
+            except:
+                pass
+        walk_on_archive(target_output_path, check_ext, filename, appdata_path, db_key)
 
     return True