-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
83 lines (62 loc) · 2.97 KB
/
Copy pathmain.py
File metadata and controls
83 lines (62 loc) · 2.97 KB
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
74
75
76
77
78
79
80
81
82
83
import os
import sys
from groupdocs.metadata import License
from methods.extract_all_metadata import extract_all_metadata
from methods.compare_metadata_sets import compare_metadata_sets
from methods.detect_ownership_changes import detect_ownership_changes
from methods.detect_revision_history import detect_revision_history
from methods.export_diff_to_json import export_diff_to_json
from methods.export_diff_to_csv import export_diff_to_csv
LICENSE_PATH = r"YOUR-LICENSE-PATH-HERE"
HERE = os.path.dirname(os.path.abspath(__file__))
INPUT_DIR = os.path.join(HERE, "resources")
OUTPUT_DIR = os.path.join(HERE, "output")
def set_license():
if os.path.exists(LICENSE_PATH):
License().set_license(LICENSE_PATH)
print("License applied")
else:
print(f"WARN license file not found at {LICENSE_PATH}; running in evaluation mode")
def do_assert(condition: bool, message: str):
if not condition:
raise AssertionError(f"assert failed: {message}")
print(f"PASS {message}")
def main() -> int:
try:
set_license()
os.makedirs(OUTPUT_DIR, exist_ok=True)
v1 = os.path.join(INPUT_DIR, "document-v1.docx")
v2 = os.path.join(INPUT_DIR, "document-v2.docx")
if not (os.path.exists(v1) and os.path.exists(v2)):
print(f"FAIL missing input files at {INPUT_DIR}")
return 2
props1 = extract_all_metadata(v1)
do_assert(len(props1) > 0, f"extract_all_metadata v1 returned {len(props1)} properties")
props2 = extract_all_metadata(v2)
do_assert(len(props2) > 0, f"extract_all_metadata v2 returned {len(props2)} properties")
diff = compare_metadata_sets(v1, v2)
do_assert(diff.total_changes > 0,
f"compare_metadata_sets found {diff.total_changes} total changes "
f"(added={len(diff.added)}, removed={len(diff.removed)}, changed={len(diff.changed)})")
ownership = detect_ownership_changes(v1, v2)
do_assert(True, f"detect_ownership_changes reported {len(ownership)} identity changes")
revisions = detect_revision_history(v1, v2)
do_assert(True, f"detect_revision_history reported {len(revisions)} time/revision changes")
json_path = os.path.join(OUTPUT_DIR, "diff.json")
export_diff_to_json(diff, json_path)
do_assert(os.path.exists(json_path) and os.path.getsize(json_path) > 0,
f"export_diff_to_json wrote {os.path.getsize(json_path)} bytes to diff.json")
csv_path = os.path.join(OUTPUT_DIR, "diff.csv")
export_diff_to_csv(diff, csv_path)
do_assert(os.path.exists(csv_path) and os.path.getsize(csv_path) > 0,
f"export_diff_to_csv wrote {os.path.getsize(csv_path)} bytes to diff.csv")
print()
print("ALL PASS")
return 0
except Exception as ex:
print(f"FAIL {type(ex).__name__}: {ex}")
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
sys.exit(main())