opex-manifest-generator 1.1.13__py3-none-any.whl → 1.2.0__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 +15 -15
- opex_manifest_generator/cli.py +182 -160
- opex_manifest_generator/common.py +64 -58
- opex_manifest_generator/hash.py +33 -33
- opex_manifest_generator/metadata/EAD Template.xml +101 -101
- opex_manifest_generator/metadata/GDPR Template.xml +8 -8
- opex_manifest_generator/metadata/MODS Template.xml +66 -66
- opex_manifest_generator/opex_manifest.py +86 -40
- opex_manifest_generator/options.properties +12 -12
- {opex_manifest_generator-1.1.13.dist-info → opex_manifest_generator-1.2.0.dist-info}/LICENSE.md +201 -201
- {opex_manifest_generator-1.1.13.dist-info → opex_manifest_generator-1.2.0.dist-info}/METADATA +16 -16
- opex_manifest_generator-1.2.0.dist-info/RECORD +22 -0
- opex_manifest_generator-1.1.13.dist-info/RECORD +0 -22
- {opex_manifest_generator-1.1.13.dist-info → opex_manifest_generator-1.2.0.dist-info}/WHEEL +0 -0
- {opex_manifest_generator-1.1.13.dist-info → opex_manifest_generator-1.2.0.dist-info}/entry_points.txt +0 -0
- {opex_manifest_generator-1.1.13.dist-info → opex_manifest_generator-1.2.0.dist-info}/top_level.txt +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"""
|
|
2
|
-
opex_manifest_generator package definitions
|
|
3
|
-
|
|
4
|
-
Author: Christopher Prince
|
|
5
|
-
license: Apache License 2.0"
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from .opex_manifest import OpexManifestGenerator,OpexDir,OpexFile
|
|
9
|
-
from .hash import HashGenerator
|
|
10
|
-
from .common import *
|
|
11
|
-
from .cli import parse_args,run_cli
|
|
12
|
-
import importlib.metadata
|
|
13
|
-
|
|
14
|
-
__author__ = "Christopher Prince (c.pj.prince@gmail.com)"
|
|
15
|
-
__license__ = "Apache License Version 2.0"
|
|
1
|
+
"""
|
|
2
|
+
opex_manifest_generator package definitions
|
|
3
|
+
|
|
4
|
+
Author: Christopher Prince
|
|
5
|
+
license: Apache License 2.0"
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .opex_manifest import OpexManifestGenerator,OpexDir,OpexFile
|
|
9
|
+
from .hash import HashGenerator
|
|
10
|
+
from .common import *
|
|
11
|
+
from .cli import parse_args,run_cli
|
|
12
|
+
import importlib.metadata
|
|
13
|
+
|
|
14
|
+
__author__ = "Christopher Prince (c.pj.prince@gmail.com)"
|
|
15
|
+
__license__ = "Apache License Version 2.0"
|
|
16
16
|
__version__ = importlib.metadata.version("opex_manifest_generator")
|
opex_manifest_generator/cli.py
CHANGED
|
@@ -1,161 +1,183 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Cli interaction.
|
|
3
|
-
|
|
4
|
-
author: Christopher Prince
|
|
5
|
-
license: Apache License 2.0"
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import argparse
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
parser
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
{generic} will
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
help="
|
|
38
|
-
parser.add_argument("-
|
|
39
|
-
help = "
|
|
40
|
-
parser.add_argument("-
|
|
41
|
-
help = "
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
parser.add_argument("-
|
|
49
|
-
help="
|
|
50
|
-
parser.add_argument("-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
help="Set whether to
|
|
58
|
-
parser.add_argument("-
|
|
59
|
-
help="Set
|
|
60
|
-
parser.add_argument("-
|
|
61
|
-
help="Set to
|
|
62
|
-
parser.add_argument("-
|
|
63
|
-
help="Set
|
|
64
|
-
parser.add_argument("-
|
|
65
|
-
help="Set to
|
|
66
|
-
parser.add_argument("-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
parser.add_argument("--
|
|
73
|
-
help="
|
|
74
|
-
parser.add_argument("
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
args = parse_args()
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
1
|
+
"""
|
|
2
|
+
Cli interaction.
|
|
3
|
+
|
|
4
|
+
author: Christopher Prince
|
|
5
|
+
license: Apache License 2.0"
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import argparse, os, inspect, time
|
|
9
|
+
from opex_manifest_generator.opex_manifest import OpexManifestGenerator
|
|
10
|
+
import importlib.metadata
|
|
11
|
+
|
|
12
|
+
def parse_args():
|
|
13
|
+
parser = argparse.ArgumentParser(description = "OPEX Manifest Generator for Preservica Uploads")
|
|
14
|
+
parser.add_argument('root', default = os.getcwd(), help = "The root path to generate Opexes for")
|
|
15
|
+
parser.add_argument("-c", "--autoclass", required = False,
|
|
16
|
+
choices = ['catalog', 'c', 'accession', 'a', 'both', 'b', 'generic', 'g', 'catalog-generic', 'cg', "accession-generic", "ag", "both-generic", "bg"],
|
|
17
|
+
type = str.lower,
|
|
18
|
+
help="""Toggles whether to utilise the auto_classification_generator
|
|
19
|
+
to generate an on the fly Reference listing.
|
|
20
|
+
|
|
21
|
+
There are several options, {catalog} will generate
|
|
22
|
+
a Archival Reference following an ISAD(G) sturcutre.
|
|
23
|
+
{accession} will create a running number of files.
|
|
24
|
+
{both} will do both at the same time!
|
|
25
|
+
{generic} will populate the title and description fields with the folder/file's name,
|
|
26
|
+
if used in conjunction with one of the above options:
|
|
27
|
+
{generic-catalog,generic-accession, generic-both} it will do both simultaneously.
|
|
28
|
+
""")
|
|
29
|
+
parser.add_argument("-p", "--prefix", required = False, nargs = '+',
|
|
30
|
+
help= """Assign a prefix when utilising the --autoclass option. Prefix will append any text before all generated text.
|
|
31
|
+
When utilising the {both} option fill in like: [catalog-prefix, accession-prefix] without square brackets.
|
|
32
|
+
""")
|
|
33
|
+
parser.add_argument("-fx", "--fixity", required = False, const = "SHA-1", default = None,
|
|
34
|
+
nargs = '?', choices = ['NONE', 'SHA-1', 'MD5', 'SHA-256', 'SHA-512'], type = str.upper,
|
|
35
|
+
help="Generates a hash for each file and adds it to the opex, can select the algorithm to utilise.")
|
|
36
|
+
parser.add_argument("-rme", "--remove-empty", required = False, action = 'store_true', default = False,
|
|
37
|
+
help = "Remove and log empty directories from root. Log will be exported to 'meta' / output folder.")
|
|
38
|
+
parser.add_argument("-o", "--output", required = False, nargs = 1,
|
|
39
|
+
help = "Sets the output to send any generated files to. Will not affect creation of a meta dir.")
|
|
40
|
+
parser.add_argument("--disable-meta-dir", required = False, action = 'store_false',
|
|
41
|
+
help = """Set whether to disable the creation of a 'meta' directory for generated files,
|
|
42
|
+
default behaviour is to always generate this directory""")
|
|
43
|
+
parser.add_argument("-clr", "--clear-opex", required = False, action = 'store_true', default = False,
|
|
44
|
+
help = """Clears existing opex files from a directory. If set with no further options will only clear opexes;
|
|
45
|
+
if multiple options are set will clear opexes and then run the program""")
|
|
46
|
+
parser.add_argument("-opt","--options-file", required = False, default=os.path.join(os.path.dirname(__file__),'options.properties'),
|
|
47
|
+
help="Specify a custom Options file, changing the set presets for column headers (Title,Description,etc)")
|
|
48
|
+
parser.add_argument("-s", "--start-ref", required = False, nargs = '?', default = 1,
|
|
49
|
+
help="Set a custom Starting reference for the Auto Classification generator. The generated reference will")
|
|
50
|
+
parser.add_argument("-mdir","--metadata-dir", required=False, nargs= '?',
|
|
51
|
+
default = os.path.join(os.path.dirname(os.path.realpath(__file__)), "metadata"),
|
|
52
|
+
help="Specify the metadata directory to pull XML files from")
|
|
53
|
+
parser.add_argument("-m", "--metadata", required = False, const = 'e', default = 'none',
|
|
54
|
+
nargs = '?', choices = ['none', 'n', 'exact', 'e', 'flat', 'f'], type = str.lower,
|
|
55
|
+
help="Set whether to include xml metadata fields in the generation of the Opex")
|
|
56
|
+
parser.add_argument("-ex", "--export", required = False, action = 'store_true', default = False,
|
|
57
|
+
help="Set whether to export the generated auto classification references to an AutoClass spreadsheet")
|
|
58
|
+
parser.add_argument("-i", "--input", required = False, nargs='?',
|
|
59
|
+
help="Set to utilise a CSV / XLSX spreadsheet to import data from")
|
|
60
|
+
parser.add_argument("-rm", "--remove", required = False, action = "store_true", default = False,
|
|
61
|
+
help="Set whether to enable removals of files and folders from a directory. ***Currently in testing")
|
|
62
|
+
parser.add_argument("-z", "--zip", required = False, action = 'store_true',
|
|
63
|
+
help="Set to zip files")
|
|
64
|
+
parser.add_argument("-fmt", "--output-format", required = False, default = "xlsx", choices = ['xlsx', 'csv'],
|
|
65
|
+
help="Set whether to output to an xlsx or csv format")
|
|
66
|
+
parser.add_argument("-v", "--version", action = 'version', version = '%(prog)s {version}'.format(version = importlib.metadata.version("opex_manifest_generator")))
|
|
67
|
+
parser.add_argument("--accession-mode", nargs = '?', required=False, const='file', default=None, choices=["file",'directory','both'],
|
|
68
|
+
help="""Set the mode when utilising the Accession option in autoclass.
|
|
69
|
+
file - only adds on files, folder - only adds on folders, both - adds on files and folders""")
|
|
70
|
+
parser.add_argument("--hidden", required = False, action = 'store_true', default = False,
|
|
71
|
+
help="Set whether to include hidden files and folders")
|
|
72
|
+
parser.add_argument("--print-xmls", required = False, action = "store_true", default = False,
|
|
73
|
+
help="Prints the elements from your xmls to the consoles")
|
|
74
|
+
parser.add_argument("-key","--keywords", nargs = '*', default = None)
|
|
75
|
+
parser.add_argument("-keym","--keywords-mode", nargs = '?', const = "intialise", default = "intialise", choices = ['intialise','firstletters'])
|
|
76
|
+
parser.add_argument("--keywords-retain-order", required = False, default = False, action = 'store_true')
|
|
77
|
+
parser.add_argument("--keywords-abbreviation-number", required = False, nargs='?', default = -3, type = int)
|
|
78
|
+
parser.add_argument("--sort-by", required=False, nargs = '?', default = 'foldersfirst', choices = ['foldersfirst','alphabetical'], type=str.lower)
|
|
79
|
+
parser.add_argument("-dlm", "--delimiter", required=False,nargs = '?', type = str)
|
|
80
|
+
args = parser.parse_args()
|
|
81
|
+
return args
|
|
82
|
+
|
|
83
|
+
def run_cli():
|
|
84
|
+
args = parse_args()
|
|
85
|
+
print(f"Running Opex Generation on: {args.root}")
|
|
86
|
+
if not args.output:
|
|
87
|
+
args.output = os.path.abspath(args.root)
|
|
88
|
+
print(f'Output path defaulting to root directory: {args.output}')
|
|
89
|
+
else:
|
|
90
|
+
args.output = os.path.abspath(args.output[0])
|
|
91
|
+
print(f'Output path set to: {args.output}')
|
|
92
|
+
if args.input and args.autoclass:
|
|
93
|
+
print(f'Both Input and Auto-Class options have been selected, please use only one...')
|
|
94
|
+
time.sleep(5); raise SystemExit()
|
|
95
|
+
if not args.metadata in {'none', 'n'} and not args.input:
|
|
96
|
+
print(f'Warning: Metadata Flag has been given without Input. Metadata won\'t be generated.')
|
|
97
|
+
time.sleep(5)
|
|
98
|
+
if args.print_xmls:
|
|
99
|
+
OpexManifestGenerator.print_descriptive_xmls()
|
|
100
|
+
acc_prefix = None
|
|
101
|
+
if args.autoclass in {"accession", "a", "accession-generic", "ag", "both", "b", "both-generic", "bg"} and args.accession_mode is None:
|
|
102
|
+
args.accession_mode = "file"
|
|
103
|
+
if args.prefix:
|
|
104
|
+
if args.autoclass in {"both", "b", "both-generic", "bg"}:
|
|
105
|
+
if len(args.prefix) < 2 or len(args.prefix) > 2:
|
|
106
|
+
print('"Both" option is selected, please pass only two prefixes: [-p CATALOG_PREFIX ACCESSION_PREFIX]');
|
|
107
|
+
time.sleep(3); raise SystemExit
|
|
108
|
+
for n, a in enumerate(args.prefix):
|
|
109
|
+
if n == 0:
|
|
110
|
+
args.prefix = str(a)
|
|
111
|
+
elif n == 1:
|
|
112
|
+
acc_prefix = str(a)
|
|
113
|
+
print(f"Prefixes are set as: \t Catalog: {args.prefix} \t Acc: {acc_prefix}")
|
|
114
|
+
elif args.autoclass in {"accession", "a", "accession-generic", "ag"}:
|
|
115
|
+
for a in args.prefix:
|
|
116
|
+
acc_prefix = str(a)
|
|
117
|
+
print('Prefix is set as: ' + acc_prefix)
|
|
118
|
+
elif args.autoclass in {"catalog", "c", "catalog-generic", "cg"}:
|
|
119
|
+
acc_prefix = None
|
|
120
|
+
for a in args.prefix:
|
|
121
|
+
args.prefix = str(a)
|
|
122
|
+
print('Prefix is set as: ' + args.prefix)
|
|
123
|
+
elif args.autoclass in {"generic", "g"}:
|
|
124
|
+
pass
|
|
125
|
+
else:
|
|
126
|
+
print('''An invalid option has been selected, please select a valid option:
|
|
127
|
+
{c, catalog
|
|
128
|
+
a, accession
|
|
129
|
+
b, both
|
|
130
|
+
g, generic
|
|
131
|
+
cg, catalog-generic
|
|
132
|
+
ag, accesion-generic
|
|
133
|
+
bg, both-generic}''')
|
|
134
|
+
time.sleep(3)
|
|
135
|
+
raise SystemExit
|
|
136
|
+
if args.fixity:
|
|
137
|
+
print(f'Fixity is activated, using {args.fixity} algorithm')
|
|
138
|
+
if args.sort_by:
|
|
139
|
+
if args.sort_by == "foldersfirst":
|
|
140
|
+
sort_key = lambda x: (os.path.isfile(x), str.casefold(x))
|
|
141
|
+
elif args.sort_by == "alphabetical":
|
|
142
|
+
sort_key = str.casefold
|
|
143
|
+
if args.remove:
|
|
144
|
+
print(inspect.cleandoc("""****
|
|
145
|
+
You have enabled the remove functionality of the program. This action will remove all files and folders listed for removal and any sub-files/sub-folders.
|
|
146
|
+
|
|
147
|
+
This process will permanently delete the selected items, with no way recover the items.
|
|
148
|
+
|
|
149
|
+
****"""))
|
|
150
|
+
time.sleep(2)
|
|
151
|
+
i = input(inspect.cleandoc("Please type Y if you wish to proceed, otherwise the program will close: "))
|
|
152
|
+
if not i.lower() == "y":
|
|
153
|
+
print("Closing program..."); time.sleep(3); raise SystemExit()
|
|
154
|
+
time.sleep(3)
|
|
155
|
+
OpexManifestGenerator(root = args.root,
|
|
156
|
+
output_path = args.output,
|
|
157
|
+
autoclass_flag = args.autoclass,
|
|
158
|
+
prefix = args.prefix,
|
|
159
|
+
accession_mode=args.accession_mode,
|
|
160
|
+
acc_prefix = acc_prefix,
|
|
161
|
+
empty_flag = args.remove_empty,
|
|
162
|
+
remove_flag = args.remove,
|
|
163
|
+
clear_opex_flag = args.clear_opex,
|
|
164
|
+
algorithm = args.fixity,
|
|
165
|
+
startref = args.start_ref,
|
|
166
|
+
export_flag = args.export,
|
|
167
|
+
meta_dir_flag = args.disable_meta_dir,
|
|
168
|
+
metadata_flag = args.metadata,
|
|
169
|
+
metadata_dir = args.metadata_dir,
|
|
170
|
+
hidden_flag= args.hidden,
|
|
171
|
+
zip_flag = args.zip,
|
|
172
|
+
input = args.input,
|
|
173
|
+
output_format = args.output_format,
|
|
174
|
+
options_file=args.options_file,
|
|
175
|
+
keywords = args.keywords,
|
|
176
|
+
keywords_mode = args.keywords_mode,
|
|
177
|
+
keywords_retain_order = args.keywords_retain_order,
|
|
178
|
+
sort_key = sort_key,
|
|
179
|
+
delimiter = args.delimiter,
|
|
180
|
+
keywords_abbreviation_number = args.keywords_abbreviation_number).main()
|
|
181
|
+
|
|
182
|
+
if __name__ == "__main__":
|
|
161
183
|
run_cli()
|
|
@@ -1,58 +1,64 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Common tools for use throghout program.
|
|
3
|
-
|
|
4
|
-
author: Christopher Prince
|
|
5
|
-
license: Apache License 2.0"
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import zipfile, os, sys, time, stat
|
|
9
|
-
import datetime
|
|
10
|
-
from lxml import etree
|
|
11
|
-
|
|
12
|
-
def zip_opex(file_path,opex_path):
|
|
13
|
-
zip_file = f"{file_path}.zip"
|
|
14
|
-
if not os.path.exists(zip_file):
|
|
15
|
-
with zipfile.ZipFile(zip_file,'w') as z:
|
|
16
|
-
z.write(file_path,os.path.basename(file_path))
|
|
17
|
-
z.write(opex_path,os.path.basename(opex_path))
|
|
18
|
-
else: print(f'A zip file already exists for: {zip_file}')
|
|
19
|
-
|
|
20
|
-
def win_256_check(path: str):
|
|
21
|
-
if len(path) > 255 and sys.platform == "win32":
|
|
22
|
-
if path.startswith(u'\\\\?\\'): path = path
|
|
23
|
-
else: path = u"\\\\?\\" + path
|
|
24
|
-
return path
|
|
25
|
-
|
|
26
|
-
def filter_win_hidden(path: str):
|
|
27
|
-
if sys.platform =="win32":
|
|
28
|
-
if bool(os.stat(path).st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN) is True:
|
|
29
|
-
return True
|
|
30
|
-
else:
|
|
31
|
-
return False
|
|
32
|
-
else:
|
|
33
|
-
return False
|
|
34
|
-
|
|
35
|
-
def
|
|
36
|
-
if
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
"""
|
|
2
|
+
Common tools for use throghout program.
|
|
3
|
+
|
|
4
|
+
author: Christopher Prince
|
|
5
|
+
license: Apache License 2.0"
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import zipfile, os, sys, time, stat
|
|
9
|
+
import datetime
|
|
10
|
+
from lxml import etree
|
|
11
|
+
|
|
12
|
+
def zip_opex(file_path,opex_path):
|
|
13
|
+
zip_file = f"{file_path}.zip"
|
|
14
|
+
if not os.path.exists(zip_file):
|
|
15
|
+
with zipfile.ZipFile(zip_file,'w') as z:
|
|
16
|
+
z.write(file_path,os.path.basename(file_path))
|
|
17
|
+
z.write(opex_path,os.path.basename(opex_path))
|
|
18
|
+
else: print(f'A zip file already exists for: {zip_file}')
|
|
19
|
+
|
|
20
|
+
def win_256_check(path: str):
|
|
21
|
+
if len(path) > 255 and sys.platform == "win32":
|
|
22
|
+
if path.startswith(u'\\\\?\\'): path = path
|
|
23
|
+
else: path = u"\\\\?\\" + path
|
|
24
|
+
return path
|
|
25
|
+
|
|
26
|
+
def filter_win_hidden(path: str):
|
|
27
|
+
if sys.platform =="win32":
|
|
28
|
+
if bool(os.stat(path).st_file_attributes & stat.FILE_ATTRIBUTE_HIDDEN) is True:
|
|
29
|
+
return True
|
|
30
|
+
else:
|
|
31
|
+
return False
|
|
32
|
+
else:
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
def win_path_delimiter():
|
|
36
|
+
if sys.platform == "win32":
|
|
37
|
+
return "\\"
|
|
38
|
+
else:
|
|
39
|
+
return "/"
|
|
40
|
+
|
|
41
|
+
def check_nan(value):
|
|
42
|
+
if str(value).lower() in {"nan","nat"}:
|
|
43
|
+
value = None
|
|
44
|
+
return value
|
|
45
|
+
|
|
46
|
+
def check_opex(opex_path:str):
|
|
47
|
+
opex_path = opex_path + ".opex"
|
|
48
|
+
if os.path.exists(win_256_check(opex_path)):
|
|
49
|
+
return False
|
|
50
|
+
else:
|
|
51
|
+
return True
|
|
52
|
+
|
|
53
|
+
def write_opex(path: str, opexxml: etree.Element):
|
|
54
|
+
opex_path = win_256_check(str(path) + ".opex")
|
|
55
|
+
opex = etree.indent(opexxml, " ")
|
|
56
|
+
opex = etree.tostring(opexxml, pretty_print=True, xml_declaration=True, encoding="UTF-8", standalone=True)
|
|
57
|
+
with open(f'{opex_path}', 'w', encoding="UTF-8") as writer:
|
|
58
|
+
writer.write(opex.decode('UTF-8'))
|
|
59
|
+
print('Saved Opex File to: ' + opex_path)
|
|
60
|
+
return opex_path
|
|
61
|
+
|
|
62
|
+
def print_running_time(start_time):
|
|
63
|
+
print(f'Running time: {datetime.datetime.now() - start_time}')
|
|
64
|
+
time.sleep(5)
|
opex_manifest_generator/hash.py
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Hash Generator class for generating Fixities for files.
|
|
3
|
-
|
|
4
|
-
author: Christopher Prince
|
|
5
|
-
license: Apache License 2.0"
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import hashlib
|
|
9
|
-
|
|
10
|
-
class HashGenerator():
|
|
11
|
-
def __init__(self,algorithm="SHA-1"):
|
|
12
|
-
self.algorithm = algorithm
|
|
13
|
-
self.buffer = 4096
|
|
14
|
-
|
|
15
|
-
def hash_generator(self,file_path: str):
|
|
16
|
-
if self.algorithm == "SHA-1":
|
|
17
|
-
hash = hashlib.sha1()
|
|
18
|
-
elif self.algorithm == "MD5":
|
|
19
|
-
hash = hashlib.md5()
|
|
20
|
-
elif self.algorithm == "SHA-256":
|
|
21
|
-
hash = hashlib.sha256()
|
|
22
|
-
elif self.algorithm == "SHA-512":
|
|
23
|
-
hash = hashlib.sha512()
|
|
24
|
-
else:
|
|
25
|
-
hash = hashlib.sha1()
|
|
26
|
-
print(f'Generating Fixity using {self.algorithm} for: {file_path}')
|
|
27
|
-
with open(file_path, "rb") as f:
|
|
28
|
-
while True:
|
|
29
|
-
buff = f.read(self.buffer)
|
|
30
|
-
if not buff:
|
|
31
|
-
break
|
|
32
|
-
hash.update(buff)
|
|
33
|
-
f.close()
|
|
1
|
+
"""
|
|
2
|
+
Hash Generator class for generating Fixities for files.
|
|
3
|
+
|
|
4
|
+
author: Christopher Prince
|
|
5
|
+
license: Apache License 2.0"
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
|
|
10
|
+
class HashGenerator():
|
|
11
|
+
def __init__(self,algorithm="SHA-1"):
|
|
12
|
+
self.algorithm = algorithm
|
|
13
|
+
self.buffer = 4096
|
|
14
|
+
|
|
15
|
+
def hash_generator(self,file_path: str):
|
|
16
|
+
if self.algorithm == "SHA-1":
|
|
17
|
+
hash = hashlib.sha1()
|
|
18
|
+
elif self.algorithm == "MD5":
|
|
19
|
+
hash = hashlib.md5()
|
|
20
|
+
elif self.algorithm == "SHA-256":
|
|
21
|
+
hash = hashlib.sha256()
|
|
22
|
+
elif self.algorithm == "SHA-512":
|
|
23
|
+
hash = hashlib.sha512()
|
|
24
|
+
else:
|
|
25
|
+
hash = hashlib.sha1()
|
|
26
|
+
print(f'Generating Fixity using {self.algorithm} for: {file_path}')
|
|
27
|
+
with open(file_path, "rb") as f:
|
|
28
|
+
while True:
|
|
29
|
+
buff = f.read(self.buffer)
|
|
30
|
+
if not buff:
|
|
31
|
+
break
|
|
32
|
+
hash.update(buff)
|
|
33
|
+
f.close()
|
|
34
34
|
return hash.hexdigest().upper()
|