opex-manifest-generator 1.3.5__py3-none-any.whl → 1.3.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opex_manifest_generator/__init__.py +3 -3
- opex_manifest_generator/cli.py +204 -123
- opex_manifest_generator/common.py +7 -7
- opex_manifest_generator/hash.py +4 -4
- opex_manifest_generator/metadata/EAD Template.xml +1 -1
- opex_manifest_generator/metadata/GDPR Template.xml +1 -1
- opex_manifest_generator/metadata/MODS Template.xml +1 -1
- opex_manifest_generator/opex_manifest.py +57 -57
- opex_manifest_generator/options/options.properties +1 -1
- opex_manifest_generator-1.3.6.dist-info/METADATA +619 -0
- opex_manifest_generator-1.3.6.dist-info/RECORD +16 -0
- opex_manifest_generator-1.3.6.dist-info/entry_points.txt +2 -0
- {opex_manifest_generator-1.3.5.dist-info → opex_manifest_generator-1.3.6.dist-info}/licenses/LICENSE.md +1 -1
- opex_manifest_generator-1.3.5.dist-info/METADATA +0 -557
- opex_manifest_generator-1.3.5.dist-info/RECORD +0 -16
- opex_manifest_generator-1.3.5.dist-info/entry_points.txt +0 -2
- {opex_manifest_generator-1.3.5.dist-info → opex_manifest_generator-1.3.6.dist-info}/WHEEL +0 -0
- {opex_manifest_generator-1.3.5.dist-info → opex_manifest_generator-1.3.6.dist-info}/top_level.txt +0 -0
|
@@ -48,17 +48,17 @@ class OpexManifestGenerator():
|
|
|
48
48
|
:param start_ref: set to set the starting reference number
|
|
49
49
|
:param algorithm: set whether to generate fixities and the algorithm to use {MD5, SHA-1, SHA-256, SHA-512}
|
|
50
50
|
:param empty_flag: set whether to delete and log empty directories
|
|
51
|
-
:param removal_flag: set whether to enable removals; data must also contain removals column and cell be set to True
|
|
51
|
+
:param removal_flag: set whether to enable removals; data must also contain removals column and cell be set to True
|
|
52
52
|
:param clear_opex_flag: set whether clear existing opexes
|
|
53
53
|
:param export_flag: set whether to export the spreadsheet when using autoref
|
|
54
54
|
:param output_format: set output format when using autoref {xlsx, csv,ods,json,lxml}
|
|
55
55
|
:param input: set whether to use an autoref spreadsheet / dataframe to establish data.
|
|
56
56
|
:param zip_flag: set whether to zip files and opexes together
|
|
57
57
|
:param hidden_flag: set to include hidden files/directories
|
|
58
|
-
:param print_xmls_flag: set to print all
|
|
58
|
+
:param print_xmls_flag: set to print all
|
|
59
59
|
:param options_file: set to specify options file
|
|
60
60
|
:param keywords: set to replace numbers in reference with alphabetical characters, specified in list or all if unset
|
|
61
|
-
:param keywords_mode: set to specify keywords mode [initialise, firstletters,from_json]
|
|
61
|
+
:param keywords_mode: set to specify keywords mode [initialise, firstletters,from_json]
|
|
62
62
|
:param keywords_retain_order: set to continue counting reference, if keyword is used, skips numbers if not
|
|
63
63
|
:param keywords_abbreviation: set int for number of characters to abbreviate to for keywords mode
|
|
64
64
|
:param sort_key: set the sort key, can be any valid function for sorted
|
|
@@ -72,7 +72,7 @@ class OpexManifestGenerator():
|
|
|
72
72
|
autoref_flag: str = None,
|
|
73
73
|
prefix: str = None,
|
|
74
74
|
suffix: str = None,
|
|
75
|
-
suffix_option: Optional[str] = '
|
|
75
|
+
suffix_option: Optional[str] = 'file',
|
|
76
76
|
acc_prefix: str = None,
|
|
77
77
|
accession_mode: str = False,
|
|
78
78
|
start_ref: int = 1,
|
|
@@ -99,10 +99,10 @@ class OpexManifestGenerator():
|
|
|
99
99
|
sort_key = lambda x: (os.path.isfile(x), str.casefold(x)),
|
|
100
100
|
delimiter = "/",
|
|
101
101
|
autoref_options: Optional[str] = None) -> None:
|
|
102
|
-
|
|
102
|
+
|
|
103
103
|
self.root = os.path.abspath(root)
|
|
104
104
|
# Base Parameters
|
|
105
|
-
self.opexns = "http://www.openpreservationexchange.org/opex/v1.2"
|
|
105
|
+
self.opexns = "http://www.openpreservationexchange.org/opex/v1.2"
|
|
106
106
|
self.start_time = datetime.now()
|
|
107
107
|
self.list_path = []
|
|
108
108
|
self.list_fixity = []
|
|
@@ -132,14 +132,14 @@ class OpexManifestGenerator():
|
|
|
132
132
|
self.metadata_dir = metadata_dir
|
|
133
133
|
|
|
134
134
|
# Parameters for Auto Reference
|
|
135
|
-
self.autoref_flag = autoref_flag
|
|
135
|
+
self.autoref_flag = autoref_flag
|
|
136
136
|
self.autoref_options = autoref_options
|
|
137
137
|
self.prefix = prefix
|
|
138
138
|
self.suffix = suffix
|
|
139
139
|
self.suffix_option = suffix_option
|
|
140
140
|
self.start_ref = start_ref
|
|
141
141
|
self.acc_prefix = acc_prefix
|
|
142
|
-
self.accession_mode = accession_mode
|
|
142
|
+
self.accession_mode = accession_mode
|
|
143
143
|
self.keywords_list = keywords
|
|
144
144
|
self.keywords_mode = keywords_mode
|
|
145
145
|
self.keywords_retain_order = keywords_retain_order
|
|
@@ -158,13 +158,13 @@ class OpexManifestGenerator():
|
|
|
158
158
|
self.hash_from_spread = False
|
|
159
159
|
|
|
160
160
|
self.parse_config(options_file=os.path.abspath(options_file))
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
def parse_config(self, options_file: str = os.path.join('options','options.properties')) -> None:
|
|
163
163
|
config = configparser.ConfigParser()
|
|
164
164
|
read_config = config.read(options_file, encoding='utf-8')
|
|
165
165
|
if not read_config:
|
|
166
166
|
logger.warning(f"Options files not found or not reable: {options_file}. Using defaults.")
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
section = config['options'] if 'options' in config else {}
|
|
169
169
|
|
|
170
170
|
self.INDEX_FIELD = section.get('INDEX_FIELD', "FullName")
|
|
@@ -206,7 +206,7 @@ class OpexManifestGenerator():
|
|
|
206
206
|
except Exception as e:
|
|
207
207
|
logger.exception(f'Failed to print Descriptive metadta files, ensure correct path {e}')
|
|
208
208
|
raise
|
|
209
|
-
|
|
209
|
+
|
|
210
210
|
def convert_descriptive_xmls(self) -> None:
|
|
211
211
|
try:
|
|
212
212
|
for file in os.scandir(self.metadata_dir):
|
|
@@ -279,7 +279,7 @@ class OpexManifestGenerator():
|
|
|
279
279
|
self.column_headers = self.df.columns.values.tolist()
|
|
280
280
|
self.set_input_flags()
|
|
281
281
|
if self.export_flag:
|
|
282
|
-
output_path = define_output_file(self.output_path, self.root, self.METAFOLDER, meta_dir_flag = self.meta_dir_flag, output_format = self.output_format)
|
|
282
|
+
output_path = define_output_file(self.output_path, self.root, self.METAFOLDER, meta_dir_flag = self.meta_dir_flag, output_format = self.output_format)
|
|
283
283
|
if self.output_format == "xlsx":
|
|
284
284
|
export_xl(self.df, output_path)
|
|
285
285
|
elif self.output_format == "csv":
|
|
@@ -308,27 +308,27 @@ class OpexManifestGenerator():
|
|
|
308
308
|
logger.debug(f'Input Dataframe initialised with columns: {self.column_headers}')
|
|
309
309
|
return True
|
|
310
310
|
else:
|
|
311
|
-
logger.
|
|
311
|
+
logger.debug('No Auto Reference or Input file specified, proceeding without Dataframe')
|
|
312
312
|
self.df = None
|
|
313
313
|
self.column_headers = None
|
|
314
314
|
return False
|
|
315
315
|
except Exception as e:
|
|
316
|
-
logger.exception(f'Failed to intialise Dataframe: {e}')
|
|
317
|
-
raise
|
|
316
|
+
logger.exception(f'Failed to intialise Dataframe: {e}')
|
|
317
|
+
raise
|
|
318
318
|
|
|
319
319
|
def clear_opex(self) -> None:
|
|
320
320
|
try:
|
|
321
321
|
walk = list(os.walk(self.root))
|
|
322
322
|
for dir, _, files in walk[::-1]:
|
|
323
323
|
for file in files:
|
|
324
|
-
file_path = win_256_check(os.path.join(dir, file))
|
|
324
|
+
file_path = win_256_check(os.path.join(dir, file))
|
|
325
325
|
if str(file_path).endswith('.opex'):
|
|
326
326
|
os.remove(file_path)
|
|
327
327
|
logger.info(f'Cleared Opex: {file_path}')
|
|
328
328
|
except Exception as e:
|
|
329
329
|
logger.exception(f'Error looking up Clearing Opex: {e}')
|
|
330
330
|
raise
|
|
331
|
-
|
|
331
|
+
|
|
332
332
|
def index_df_lookup(self, path: str) -> pd.Index:
|
|
333
333
|
if getattr(self, 'df', None) is None:
|
|
334
334
|
logger.error('Dataframe not initialised, cannot perform lookup')
|
|
@@ -379,11 +379,11 @@ class OpexManifestGenerator():
|
|
|
379
379
|
except Exception as e:
|
|
380
380
|
logger.exception(f'Error looking up XIP from Dataframe: {e}')
|
|
381
381
|
raise
|
|
382
|
-
|
|
382
|
+
|
|
383
383
|
def removal_df_lookup(self, idx: pd.Index) -> bool:
|
|
384
384
|
if getattr(self, 'df', None) is None:
|
|
385
385
|
logger.error('Dataframe not initialised, cannot perform lookup')
|
|
386
|
-
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
386
|
+
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
387
387
|
try:
|
|
388
388
|
if idx.empty:
|
|
389
389
|
return False
|
|
@@ -409,7 +409,7 @@ class OpexManifestGenerator():
|
|
|
409
409
|
def ignore_df_lookup(self, idx: pd.Index) -> bool:
|
|
410
410
|
if getattr(self, 'df', None) is None:
|
|
411
411
|
logger.error('Dataframe not initialised, cannot perform lookup')
|
|
412
|
-
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
412
|
+
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
413
413
|
try:
|
|
414
414
|
if idx.empty:
|
|
415
415
|
return False
|
|
@@ -432,7 +432,7 @@ class OpexManifestGenerator():
|
|
|
432
432
|
def sourceid_df_lookup(self, xml_element: ET.SubElement, idx: pd.Index) -> None:
|
|
433
433
|
if getattr(self, 'df', None) is None:
|
|
434
434
|
logger.error('Dataframe not initialised, cannot perform lookup')
|
|
435
|
-
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
435
|
+
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
436
436
|
try:
|
|
437
437
|
if idx.empty:
|
|
438
438
|
pass
|
|
@@ -457,12 +457,12 @@ class OpexManifestGenerator():
|
|
|
457
457
|
def hash_df_lookup(self, xml_fixities: ET.SubElement, idx: pd.Index) -> None:
|
|
458
458
|
if getattr(self, 'df', None) is None:
|
|
459
459
|
logger.error('Dataframe not initialised, cannot perform lookup')
|
|
460
|
-
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
460
|
+
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
461
461
|
try:
|
|
462
462
|
hash_value = None
|
|
463
463
|
algo_value = None
|
|
464
464
|
file_path = None
|
|
465
|
-
|
|
465
|
+
|
|
466
466
|
if idx.empty:
|
|
467
467
|
return
|
|
468
468
|
else:
|
|
@@ -503,7 +503,7 @@ class OpexManifestGenerator():
|
|
|
503
503
|
def ident_df_lookup(self, idx: pd.Index, default_key: str = None) -> None:
|
|
504
504
|
if getattr(self, 'df', None) is None:
|
|
505
505
|
logger.error('Dataframe not initialised, cannot perform lookup')
|
|
506
|
-
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
506
|
+
raise RuntimeError('Dataframe not initialised, cannot perform lookup')
|
|
507
507
|
try:
|
|
508
508
|
if idx.empty:
|
|
509
509
|
pass
|
|
@@ -514,22 +514,22 @@ class OpexManifestGenerator():
|
|
|
514
514
|
if f'{self.IDENTIFIER_FIELD}:' in header:
|
|
515
515
|
key_name = str(header).split(':',1)[-1]
|
|
516
516
|
elif self.IDENTIFIER_FIELD in header:
|
|
517
|
-
key_name = self.IDENTIFIER_DEFAULT
|
|
517
|
+
key_name = self.IDENTIFIER_DEFAULT
|
|
518
518
|
elif self.ARCREF_FIELD in header:
|
|
519
519
|
key_name = self.IDENTIFIER_DEFAULT
|
|
520
520
|
elif self.ACCREF_FIELD in header:
|
|
521
521
|
key_name = self.ACCREF_CODE
|
|
522
522
|
else:
|
|
523
523
|
key_name = self.IDENTIFIER_DEFAULT
|
|
524
|
-
ident = check_nan(self.df.loc[idx,header].item())
|
|
524
|
+
ident = check_nan(self.df.loc[idx,header].item())
|
|
525
525
|
if ident:
|
|
526
|
-
self.identifier = ET.SubElement(self.identifiers, f"{{{self.opexns}}}Identifier")
|
|
526
|
+
self.identifier = ET.SubElement(self.identifiers, f"{{{self.opexns}}}Identifier")
|
|
527
527
|
self.identifier.set("type", key_name)
|
|
528
528
|
self.identifier.text = str(ident)
|
|
529
529
|
logger.debug(f'Adding Identifer: {header}: {ident}')
|
|
530
530
|
except KeyError as e:
|
|
531
531
|
logger.exception(f'Key Error in Identifer Lookup: {e}' \
|
|
532
|
-
'\n Please ensure column header\'s are an exact match.')
|
|
532
|
+
'\n Please ensure column header\'s are an exact match.')
|
|
533
533
|
raise
|
|
534
534
|
except IndexError as e:
|
|
535
535
|
logger.warning(f'Index Error in Identifier Lookup: {e}. Proceeding...' \
|
|
@@ -537,7 +537,7 @@ class OpexManifestGenerator():
|
|
|
537
537
|
'\nafter generating your input spreadsheet. An opex will still be generated but xml information may be missing.' \
|
|
538
538
|
'\nTo ensure metadata match up please regenerate the spreadsheet.')
|
|
539
539
|
except Exception as e:
|
|
540
|
-
logger.exception(f'Error looking up Identifiers: {e}')
|
|
540
|
+
logger.exception(f'Error looking up Identifiers: {e}')
|
|
541
541
|
raise
|
|
542
542
|
|
|
543
543
|
def init_generate_descriptive_metadata(self) -> None:
|
|
@@ -609,10 +609,10 @@ class OpexManifestGenerator():
|
|
|
609
609
|
name = elem_dict.get('Name')
|
|
610
610
|
path = elem_dict.get('Path')
|
|
611
611
|
ns = elem_dict.get('Namespace')
|
|
612
|
-
if self.metadata_flag in {'
|
|
612
|
+
if self.metadata_flag in {'exact'}:
|
|
613
613
|
val_series = self.df.loc[idx,path]
|
|
614
614
|
val = check_nan(val_series.item())
|
|
615
|
-
elif self.metadata_flag in {'
|
|
615
|
+
elif self.metadata_flag in {'flat'}:
|
|
616
616
|
val_series = self.df.loc[idx,name]
|
|
617
617
|
val = check_nan(val_series.item())
|
|
618
618
|
if val is None:
|
|
@@ -621,13 +621,13 @@ class OpexManifestGenerator():
|
|
|
621
621
|
if is_datetime64_any_dtype(val_series):
|
|
622
622
|
val = pd.to_datetime(val)
|
|
623
623
|
val = datetime.strftime(val, "%Y-%m-%dT%H:%M:%S.000Z")
|
|
624
|
-
if self.metadata_flag in {'
|
|
624
|
+
if self.metadata_flag in {'exact'}:
|
|
625
625
|
n = path.replace(localname + ":", f"{{{ns}}}")
|
|
626
626
|
elem = xml_new.find(f'./{n}')
|
|
627
627
|
if elem is None:
|
|
628
628
|
logger.warning(f'XML element not found for path: {n} in {xml_file.get("xmlfile")}')
|
|
629
629
|
continue
|
|
630
|
-
elif self.metadata_flag in {'
|
|
630
|
+
elif self.metadata_flag in {'flat'}:
|
|
631
631
|
n = name.split(':')[-1]
|
|
632
632
|
elem = xml_new.find(f'.//{{{ns}}}{n}')
|
|
633
633
|
if elem is None:
|
|
@@ -637,7 +637,7 @@ class OpexManifestGenerator():
|
|
|
637
637
|
xml_desc_elem.append(xml_new.find('.'))
|
|
638
638
|
except KeyError as e:
|
|
639
639
|
logger.exception(f'Key Error in XML Lookup: {e}' \
|
|
640
|
-
'\n please ensure column header\'s are an exact match.')
|
|
640
|
+
'\n please ensure column header\'s are an exact match.')
|
|
641
641
|
raise
|
|
642
642
|
except IndexError as e:
|
|
643
643
|
logger.warning(f'Index Error: {e}' \
|
|
@@ -656,7 +656,7 @@ class OpexManifestGenerator():
|
|
|
656
656
|
self.titlexml.text = str(title)
|
|
657
657
|
if description:
|
|
658
658
|
self.descriptionxml = ET.SubElement(self.properties, f"{{{self.opexns}}}Description")
|
|
659
|
-
self.descriptionxml.text = str(description)
|
|
659
|
+
self.descriptionxml.text = str(description)
|
|
660
660
|
if security:
|
|
661
661
|
self.securityxml = ET.SubElement(self.properties, f"{{{self.opexns}}}SecurityDescriptor")
|
|
662
662
|
self.securityxml.text = str(security)
|
|
@@ -678,7 +678,7 @@ class OpexManifestGenerator():
|
|
|
678
678
|
self.fixity.set("value", hash_value)
|
|
679
679
|
list_fixity.append([algorithm_type, hash_value, file_path])
|
|
680
680
|
return list_fixity
|
|
681
|
-
|
|
681
|
+
|
|
682
682
|
def generate_pax_folder_opex_fixity(self, folder_path: str, fixitiesxml: ET._Element, filesxml: ET._Element, algorithm: Optional[list] = None) -> list:
|
|
683
683
|
"""Generate fixities for files inside a pax folder. If algorithm is None, defaults to ['SHA-1']."""
|
|
684
684
|
algorithm = algorithm or ['SHA-1']
|
|
@@ -719,7 +719,7 @@ class OpexManifestGenerator():
|
|
|
719
719
|
self.fixity.set("value", hash_value)
|
|
720
720
|
list_fixity.append([algorithm_type, hash_value, f"{file_path}/{file.filename}"])
|
|
721
721
|
return list_fixity
|
|
722
|
-
|
|
722
|
+
|
|
723
723
|
def main(self) -> None:
|
|
724
724
|
if self.clear_opex_flag:
|
|
725
725
|
self.clear_opex()
|
|
@@ -792,7 +792,7 @@ class OpexDir(OpexManifestGenerator):
|
|
|
792
792
|
self.folders = ET.SubElement(self.manifest, f"{{{self.opexns}}}Folders")
|
|
793
793
|
self.files = ET.SubElement(self.manifest, f"{{{self.opexns}}}Files")
|
|
794
794
|
if self.OMG.title_flag or self.OMG.description_flag or self.OMG.security_flag:
|
|
795
|
-
self.title, self.description, self.security = self.OMG.xip_df_lookup(index)
|
|
795
|
+
self.title, self.description, self.security = self.OMG.xip_df_lookup(index)
|
|
796
796
|
elif self.OMG.autoref_flag in {"generic", "g", "catalog-generic", "cg", "accession-generic", "ag", "both-generic", "bg"}:
|
|
797
797
|
if title is not None:
|
|
798
798
|
self.title = title
|
|
@@ -819,7 +819,7 @@ class OpexDir(OpexManifestGenerator):
|
|
|
819
819
|
self.OMG.list_fixity.extend(tmp_list_fixity)
|
|
820
820
|
self.OMG.list_path.extend(tmp_list_path)
|
|
821
821
|
if self.OMG.autoref_flag or self.OMG.input:
|
|
822
|
-
self.OMG.generate_opex_properties(self.xmlroot, index,
|
|
822
|
+
self.OMG.generate_opex_properties(self.xmlroot, index,
|
|
823
823
|
title = self.title,
|
|
824
824
|
description = self.description,
|
|
825
825
|
security = self.security)
|
|
@@ -833,27 +833,27 @@ class OpexDir(OpexManifestGenerator):
|
|
|
833
833
|
list_directories = sorted([win_256_check(os.path.join(directory, f.name)) for f in os.scandir(directory)
|
|
834
834
|
if not f.name.startswith('.')
|
|
835
835
|
and filter_win_hidden(win_256_check(os.path.join(directory, f.name))) is False
|
|
836
|
-
and not f.name in ('opex_generate.exe','opex_generate.bin')
|
|
836
|
+
and not f.name in ('opex_generate.exe','opex_generate.bin')
|
|
837
837
|
and f.name != self.OMG.METAFOLDER
|
|
838
838
|
and f.name != os.path.basename(__file__)],
|
|
839
839
|
key=sort_key)
|
|
840
840
|
elif self.OMG.hidden_flag is True:
|
|
841
841
|
list_directories = sorted([win_256_check(os.path.join(directory, f.name)) for f in os.scandir(directory) \
|
|
842
842
|
if f.name != self.OMG.METAFOLDER
|
|
843
|
-
and not f.name in ('opex_generate.exe','opex_generate.bin')
|
|
843
|
+
and not f.name in ('opex_generate.exe','opex_generate.bin')
|
|
844
844
|
and f.name != os.path.basename(__file__)],
|
|
845
845
|
key=sort_key)
|
|
846
846
|
return list_directories
|
|
847
847
|
except Exception as e:
|
|
848
848
|
logger.exception(f'Failed to Filter Directories: {e}')
|
|
849
849
|
raise
|
|
850
|
-
|
|
850
|
+
|
|
851
851
|
def generate_opex_dirs(self, path: str) -> None:
|
|
852
852
|
""""
|
|
853
853
|
This function loops recursively through a given directory.
|
|
854
|
-
|
|
854
|
+
|
|
855
855
|
There are two loops to first generate Opexes for Files; Then Generate the Folder Opex Manifests.
|
|
856
|
-
"""
|
|
856
|
+
"""
|
|
857
857
|
current = OpexDir(self.OMG, path)
|
|
858
858
|
if current.OMG.algorithm and current.OMG.pax_fixity_flag is True and current.folder_path.endswith(".pax"):
|
|
859
859
|
opex_path = os.path.abspath(current.folder_path)
|
|
@@ -872,14 +872,14 @@ class OpexDir(OpexManifestGenerator):
|
|
|
872
872
|
if current.ignore is True or \
|
|
873
873
|
(current.OMG.removal_flag is True and \
|
|
874
874
|
current.OMG.removal_df_lookup(current.OMG.index_df_lookup(f_path)) is True):
|
|
875
|
-
#If Ignore is True, or the Folder below is marked for Removal: Don't add to Opex
|
|
875
|
+
#If Ignore is True, or the Folder below is marked for Removal: Don't add to Opex
|
|
876
876
|
pass
|
|
877
877
|
else:
|
|
878
878
|
#Add Folder to OPEX Manifest (doesn't get written yet...)
|
|
879
879
|
current.folder = ET.SubElement(self.folders, f"{{{self.opexns}}}Folder")
|
|
880
880
|
current.folder.text = str(os.path.basename(f_path))
|
|
881
881
|
if current.OMG.algorithm and current.OMG.pax_fixity_flag is True and current.folder_path.endswith(".pax"):
|
|
882
|
-
#If using fixity, but the current folder is a PAX & using PAX Fixity: End descent.
|
|
882
|
+
#If using fixity, but the current folder is a PAX & using PAX Fixity: End descent.
|
|
883
883
|
pass
|
|
884
884
|
else:
|
|
885
885
|
#Recurse Descent.
|
|
@@ -907,16 +907,16 @@ class OpexDir(OpexManifestGenerator):
|
|
|
907
907
|
file.set("size", str(os.path.getsize(f_path)))
|
|
908
908
|
file.text = str(os.path.basename(f_path))
|
|
909
909
|
logger.debug(f'Adding File to Opex Manifest: {f_path}')
|
|
910
|
-
#Writes Folder OPEX
|
|
910
|
+
#Writes Folder OPEX
|
|
911
911
|
write_opex(opex_path, current.xmlroot)
|
|
912
912
|
else:
|
|
913
|
-
#Avoids Override if exists, lets you continue where left off.
|
|
913
|
+
#Avoids Override if exists, lets you continue where left off.
|
|
914
914
|
logger.info(f"Avoiding override, Opex exists at: {opex_path}")
|
|
915
915
|
|
|
916
916
|
class OpexFile(OpexManifestGenerator):
|
|
917
917
|
def __init__(self, OMG: OpexManifestGenerator, file_path: str, title: str = None, description: str = None, security: str = None) -> None:
|
|
918
918
|
self.OMG = OMG
|
|
919
|
-
self.opexns = self.OMG.opexns
|
|
919
|
+
self.opexns = self.OMG.opexns
|
|
920
920
|
if file_path.startswith(u'\\\\?\\'):
|
|
921
921
|
self.file_path = file_path.replace(u'\\\\?\\', "")
|
|
922
922
|
else:
|
|
@@ -924,7 +924,7 @@ class OpexFile(OpexManifestGenerator):
|
|
|
924
924
|
if check_opex(self.file_path):
|
|
925
925
|
index = None
|
|
926
926
|
if any([self.OMG.input,
|
|
927
|
-
self.OMG.autoref_flag in {"
|
|
927
|
+
self.OMG.autoref_flag in {"catalog","accession","both","catalog-generic","accession-generic","both-generic"},
|
|
928
928
|
self.OMG.ignore_flag,
|
|
929
929
|
self.OMG.removal_flag,
|
|
930
930
|
self.OMG.sourceid_flag,
|
|
@@ -932,21 +932,21 @@ class OpexFile(OpexManifestGenerator):
|
|
|
932
932
|
self.OMG.description_flag,
|
|
933
933
|
self.OMG.security_flag]):
|
|
934
934
|
index = self.OMG.index_df_lookup(self.file_path)
|
|
935
|
-
elif self.OMG.autoref_flag is None or self.OMG.autoref_flag in {"
|
|
935
|
+
elif self.OMG.autoref_flag is None or self.OMG.autoref_flag in {"generic"}:
|
|
936
936
|
index = None
|
|
937
937
|
self.ignore = False
|
|
938
938
|
self.removal = False
|
|
939
939
|
if self.OMG.ignore_flag:
|
|
940
940
|
self.ignore = self.OMG.ignore_df_lookup(index)
|
|
941
941
|
if self.ignore:
|
|
942
|
-
return
|
|
942
|
+
return
|
|
943
943
|
if self.OMG.removal_flag:
|
|
944
944
|
self.removal = self.OMG.removal_df_lookup(index)
|
|
945
945
|
if self.removal:
|
|
946
946
|
return
|
|
947
947
|
if self.OMG.title_flag or self.OMG.description_flag or self.OMG.security_flag:
|
|
948
|
-
self.title, self.description, self.security = self.OMG.xip_df_lookup(index)
|
|
949
|
-
elif self.OMG.autoref_flag in {"generic", "
|
|
948
|
+
self.title, self.description, self.security = self.OMG.xip_df_lookup(index)
|
|
949
|
+
elif self.OMG.autoref_flag in {"generic", "catalog-generic", "accession-generic", "both-generic"}:
|
|
950
950
|
if title is not None:
|
|
951
951
|
self.title = title
|
|
952
952
|
else:
|
|
@@ -972,7 +972,7 @@ class OpexFile(OpexManifestGenerator):
|
|
|
972
972
|
if self.OMG.algorithm:
|
|
973
973
|
self.fixities = ET.SubElement(self.transfer, f"{{{self.opexns}}}Fixities")
|
|
974
974
|
if self.OMG.hash_from_spread:
|
|
975
|
-
self.OMG.hash_df_lookup(self.fixities, index)
|
|
975
|
+
self.OMG.hash_df_lookup(self.fixities, index)
|
|
976
976
|
else:
|
|
977
977
|
self.OMG.list_path.append(self.file_path)
|
|
978
978
|
if self.OMG.pax_fixity_flag is True and (self.file_path.endswith("pax.zip") or self.file_path.endswith(".pax")):
|
|
@@ -991,7 +991,7 @@ class OpexFile(OpexManifestGenerator):
|
|
|
991
991
|
self.xml_descmeta = ET.SubElement(self.xmlroot, f"{{{self.opexns}}}DescriptiveMetadata")
|
|
992
992
|
self.OMG.generate_descriptive_metadata(self.xml_descmeta, index)
|
|
993
993
|
opex_path = write_opex(self.file_path, self.xmlroot)
|
|
994
|
-
# Zip cannot be activated unless another flag - which
|
|
994
|
+
# Zip cannot be activated unless another flag - which
|
|
995
995
|
if self.OMG.zip_flag:
|
|
996
996
|
zip_opex(self.file_path, opex_path)
|
|
997
997
|
if self.OMG.zip_file_removal:
|
|
@@ -1001,4 +1001,4 @@ class OpexFile(OpexManifestGenerator):
|
|
|
1001
1001
|
logger.debug(f'Removed file: {opex_path}')
|
|
1002
1002
|
logger.debug(f'Removed file: {self.file_path}')
|
|
1003
1003
|
else:
|
|
1004
|
-
logger.info(f"Avoiding override, Opex exists at: {self.file_path}: ")
|
|
1004
|
+
logger.info(f"Avoiding override, Opex exists at: {self.file_path}: ")
|