-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.py
60 lines (52 loc) · 1.95 KB
/
report.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
import os
import sys
import requests
from requests.auth import HTTPBasicAuth
import json
import csv
def clear_terminal_line(chars):
padding = ""
for i in range(chars):
padding += " "
print(padding, end='\r')
def generate_report(report_path, aem_path_to_search):
with open(report_path, 'w', newline='') as csvfile:
writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["Component", "Path", "Page"])
count = 1
total = "/" + str(len(components)) + " "
length = len(total) + 1
for path in components:
print(str(count) + total + path, end='\r')
url = "http://localhost:4502/bin/querybuilder.json?path=" + aem_path_to_search.replace("/","%2f") + "&property=sling%3aresourceType&p.limit=-1&property.value=" + path.replace("/","%2f")
r = requests.get(url, auth=HTTPBasicAuth("admin", "admin"))
results = json.loads(r.text)
for res in results["hits"]:
writer.writerow([path, res["path"], res["path"].split("/jcr:", 1)[0]])
cur_length = len(path)
if cur_length > length:
length = cur_length
else:
clear_terminal_line(length + len(str(count) + total))
count += 1
clear_terminal_line(length + len(str(count) + total))
def get_path_list(file):
if os.path.isfile(file):
f = open(file, "r")
paths = f.read().splitlines()
f.close()
return paths
else:
print("Invalid file: " + file + ". Please try again.")
exit()
components = []
has_argument = False
for arg in sys.argv[1:]:
has_argument = True
components = get_path_list(arg)
if not has_argument:
print("Please include path to list of components as an argument.")
exit(1)
total = str(len(components))
generate_report("report.csv","/content")
print(total + "/" + total + " Report is complete.")