-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccl
executable file
·133 lines (87 loc) · 2.83 KB
/
ccl
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
import sys
import os.path
from print_help import printHelp
def isParamKey(paramStr):
return paramStr in mapParamKeyOption
def mapParamKeyToOption(paramKey):
return mapParamKeyOption[paramKey]
def prepareParamValue(paramValue):
return paramValue.split(",")
def setOption(optionName, optionValue):
if type(options[optionName]) == list:
options[optionName].extend(optionValue)
else:
options[optionName] = optionValue
def gluePaths(parentPath, childEntity):
return os.path.join(parentPath, childEntity)
def folderBypass(folderPath):
global countCodeLinesAll
childEntities = os.listdir(folderPath)
for childEntity in childEntities:
if options["withDots"] == False and childEntity[0] == ".": # If something begin with dot
continue
if childEntity in options["blackboxEntities"]:
continue
# Get path for child of current directory
childPath = gluePaths(folderPath, childEntity)
if os.path.isdir(childPath):
folderBypass(childPath)
elif os.path.isfile(childPath):
childExt = os.path.splitext(childPath)[1]
if childExt not in options["allowedExtensions"] and childEntity not in options["includedEntities"]:
continue
file = open(childPath)
countCodeLines = len(file.readlines())
countCodeLinesAll += countCodeLines
print("counted file =>", childPath, ":", countCodeLines, "lines")
else:
print("who knows =>", childPath)
def processParams(rawParams):
argv = rawParams[1:]
while len(argv):
curParam = argv.pop(0)
if isParamKey(curParam):
optionName = mapParamKeyToOption(curParam)
if optionName.startswith("with"):
preparedParamValue = True
else:
paramValue = argv.pop(0)
preparedParamValue = prepareParamValue(paramValue)
setOption(optionName, preparedParamValue)
if len(argv) == 0:
setOption("folderSearchPaths", prepareParamValue(curParam))
def printResult():
global countCodeLinesAll
print()
print("Total code lines:", countCodeLinesAll)
if __name__ == "__main__":
# initialization
countCodeLinesAll = 0 # main parameter
mapParamKeyOption = {
"-e": "allowedExtensions",
"--ext": "allowedExtensions",
"-b": "blackboxEntities",
"--blackbox": "blackboxEntities",
"--with-dots": "withDots",
"-h": "withHelp",
"--help": "withHelp",
"-i": "includedEntities",
"--include": "includedEntities"
}
options = {
"folderSearchPaths": [],
"allowedExtensions": [".js"],
"blackboxEntities": ["node_modules"],
"withDots": False,
"withHelp": False,
"includedEntities": []
}
# start programm
processParams(sys.argv)
if options["withHelp"]:
printHelp()
exit(0)
for folderSearchPath in options["folderSearchPaths"]:
folderBypass(folderSearchPath)
printResult()