-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator.py
49 lines (35 loc) · 1.39 KB
/
validator.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
"""
This loads a json data file exported from plone and:
counts the number of json items - to manually validate a good export.
"""
import argparse
import ijson
def process_args():
parser = argparse.ArgumentParser(description="Validate a plone export."
"Note only 'story' types are expected",
usage="usage: validator.py <filename>")
parser.add_argument("filename",
help="filename of json export")
parser.add_argument("-v", "--verbose",
help="turn on debug")
parsed_args = parser.parse_args()
return parsed_args
def validate(filename):
with open(filename, 'r') as filep:
# stream it from json into objects one item at a time
items = ijson.items(filep, 'item')
objects = 0
errors = 0
unpublished = 0
for item in items:
if '@id' in item:
objects += 1
if item.get('review_state') != "published":
unpublished += 1
else:
errors = len(item['unexported_paths'])
return (objects, unpublished, errors)
if __name__ == "__main__":
args = process_args()
(objects, unpublished, errors) = validate(args.filename)
print(f"{args.filename}: {objects} objects | {objects - unpublished} published | {errors} errors")