forked from mooniak/textual-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (85 loc) · 2.75 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#
# main.py
#
# Copyright (c) 2015,
# Mooniak <[email protected]>
# Ayantha Randika <[email protected]>
# Improvements: https://github.com/mooniak/textual-tools
# Released under the GNU General Public License version 3 or later.
# See accompanying LICENSE file for details.
import sys
import json
from fileOps import *
from counter import *
from scraper import scrape
from jsonFormulate import json_formulate
def local_count(name, out=os.getcwd() + "/report.JSON"):
file_list = folder_reader(name)
count = Counter()
count.name = name
count.source = name
if file_list == None:
count.name = name
print(json.dumps(count))
else:
for file in file_list:
count.count(name + "/" + file)
writer(out, json_formulate(count))
def web_count(name, levels, out=None):
folder = scrape(name, levels, out)
file_list = folder_reader(folder)
count = Counter()
count.name = folder
count.source = name
if file_list == None:
return
else:
for file in file_list:
count.count(folder + "/" + file)
if out == None:
out = os.getcwd()
writer(out + "/report.JSON", json_formulate(count))
def main():
if len(sys.argv) > 1 and sys.argv[1] == "-l":
if len(sys.argv) <= 2:
print("Invalid Location")
else:
print("Starting analysis...")
if len(sys.argv) > 3:
local_count(sys.argv[2], sys.argv[3])
print("Done..!")
else:
local_count(sys.argv[2])
print("Done..!")
elif len(sys.argv) > 1 and sys.argv[1] == "-w":
if len(sys.argv) <= 2:
print("Invalid Location")
else:
print("Starting analysis...")
if len(sys.argv) == 3:
web_count(sys.argv[2], 1)
print("Done..!")
elif len(sys.argv) == 4:
try:
level = int(sys.argv[3])
web_count(sys.argv[2], level)
print("Done..!")
except ValueError:
print("Number of levels must be a integer")
return
elif len(sys.argv) > 4:
if os.path.isdir(sys.argv[4]):
try:
level = int(sys.argv[3])
web_count(sys.argv[2], level, sys.argv[5])
print("Done..!")
except ValueError:
print("Number of levels must be a integer")
return
else:
print("Output location for web count must be a folder")
return
else:
print("Invalid argument")
if __name__ == "__main__":
main()