forked from gofed/gofed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.py
107 lines (82 loc) · 2.71 KB
/
lint.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
96
97
98
99
100
101
102
103
104
105
106
107
import sys
from modules.GoLint import GoLint
import optparse
from os import walk
from modules.Utils import FormatedPrint
from modules.Config import Config
from modules.FilesDetector import FilesDetector
def setOptions():
parser = optparse.OptionParser("%prog [-a] [-c] [-d [-v]] [directory]")
parser.add_option(
"", "-d", "--detect", dest="detect", action = "store_true", default = False,
help = "Detect spec file and tarball (and sources if in Fedora repository) in the current directory"
)
parser.add_option(
"", "-s", "--spec", dest="spec", default = "",
help = "Set spec file"
)
parser.add_option(
"", "", "--sources", dest="sources", default = "",
help = "Set sources file (optional)"
)
parser.add_option(
"", "-a", "--archive", dest="archive", default = "",
help = "Set archive file"
)
parser.add_option(
"", "-i", "--info", dest="info", action = "store_true", default = False,
help = "Displays only detected files (only with -d option)"
)
parser.add_option(
"", "-v", "--verbose", dest="verbose", action = "store_true", default = False,
help = "Verbose mode"
)
parser.add_option(
"", "", "--scan-all-dirs", dest="scanalldirs", action = "store_true", default = False,
help = "Scan all dirs, including Godeps directory"
)
parser.add_option(
"", "", "--skip-dirs", dest="skipdirs", default = "",
help = "Scan all dirs except specified via SKIPDIRS. Directories are comma separated list."
)
return parser
if __name__ == "__main__":
parser = setOptions()
options, args = parser.parse_args()
fd = FilesDetector()
fd.detect()
specfile = fd.getSpecfile()
sources = fd.getSources()
archive = fd.getArchive()
# if options only files detection
if options.info:
exit(0)
if options.archive:
archive = options.archive
if options.spec:
specfile = options.spec
if options.sources:
sources = options.sources
fp_obj = FormatedPrint(formated=True)
if archive == "":
fp_obj.printError("archive not set")
exit(1)
if specfile == "":
fp_obj.printError("specfile not set")
exit(1)
if not options.scanalldirs:
noGodeps = Config().getSkippedDirectories()
else:
noGodeps = []
if options.skipdirs:
for dir in options.skipdirs.split(','):
dir = dir.strip()
if dir == "":
continue
noGodeps.append(dir)
obj = GoLint(specfile, sources, archive, options.verbose, noGodeps = noGodeps)
if not obj.test():
print obj.getError()
err_cnt = obj.getErrorCount()
warn_cnt = obj.getWarningCount()
print "1 golang specfile checked; %s errors, %s warnings." % (err_cnt, warn_cnt)