-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathskeletongenerator.py
73 lines (57 loc) · 2.01 KB
/
skeletongenerator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Skeleton test suite generator."""
import argparse
import configparser as ConfigParser
import os
import re
import sys
import time
import deletefiles
import fmtxmlextractor
def readPronomExport(config):
"""Read pronom export and forward to puid handlers."""
export_location = config.get("locations", "xmlexport")
for puids in ["fmt", "x-fmt"]:
# go into loop to read each file in each folder and map data as required
puid_xml_loc = export_location + "//" + puids
for root, _, files in os.walk(puid_xml_loc):
for file in files:
file_path = root + "//" + file
file_no = re.findall(r"\d+", file_path)[
0
] # create a file number based on integers in path
fmtxmlextractor.handler(puids, [file_no, file_path])
def parseCommandLine():
"""Handle skeleton generator CLI."""
parser = argparse.ArgumentParser(
description="Tool for the automated generation of digital objects based on the digital signatures documented in the PRONOM database maintained by The National Archives, UK."
)
parser.add_argument(
"--version",
help="Display the version number of the tool",
action="version",
version="%(prog)s v0.2-BETA",
)
_ = parser.parse_args()
def main():
"""Primary entry-point for this script."""
parseCommandLine()
# time script execution time roughly...
# TODO: time.process_time() may also be appropriate.
t0 = time.perf_counter()
config = ConfigParser.RawConfigParser()
config.read("skeletonsuite.cfg")
deletefiles.cleanup()
readPronomExport(config)
# print script execution time...
sys.stdout.write(
"Skeleton suite generation time: "
+ str(time.perf_counter() - t0)
+ "s"
+ "\n"
)
# print script stats
stats = fmtxmlextractor.get_stats()
for value in stats:
sys.stdout.write(value + str(stats[value]) + "\n")
if __name__ == "__main__":
main()