33
33
import sys # @UnusedImport
34
34
import copy
35
35
import nsiqcppstyle_checker
36
+ from nsiqcppstyle_outputer import _consoleOutputer as console
36
37
import nsiqcppstyle_state
37
38
import nsiqcppstyle_rulemanager
38
39
import nsiqcppstyle_reporter
49
50
50
51
51
52
def ShowMessageAndExit (msg , usageOutput = True ):
52
- print >> sys . stderr , msg
53
+ console . Err . Error ( msg )
53
54
if usageOutput :
54
55
Usage ()
55
56
sys .exit (- 1 )
@@ -74,7 +75,7 @@ def Usage():
74
75
-o path Set the output path. It's only applied when the output is csv or xml.
75
76
-f path Set the filefilter path. If not provided, it uses the default filterpath
76
77
(target/filefilter.txt)
77
- If you provide the file path(not folder path) for the target,
78
+ If you provide the file path (not a folder path) for the target,
78
79
-f option should be provided.
79
80
--var=key: value,key: value
80
81
provide the variables to customize the rule behavior.
@@ -86,7 +87,8 @@ def Usage():
86
87
that each tool recognizes.
87
88
csv and xml outputs the result on the file "nsiqcppstyle_result.csv"
88
89
"nsiqcppstyle_result.xml" respectively, if you don't provide -o option.
89
- --ci Continuous Integration mode. If this mode is on, this tool only report summary.
90
+ --ci Continuous Integration mode. If this mode is on, this tool only reports summary.
91
+ --quiet / -q Quiet mode. If this mode is on, this tool only reports errors.
90
92
91
93
* nsiqcppstyle reports coding standard violations on C/C++ source code.
92
94
* In default, it doesn't apply any rules on the source. If you want to apply rule,
@@ -133,9 +135,9 @@ def main(argv=None):
133
135
argv = sys .argv
134
136
try :
135
137
try :
136
- opts , args = getopt .getopt (argv [1 : ], "o: s: m: hvrf : " , ["help" , "csv" ,
138
+ opts , args = getopt .getopt (argv [1 : ], "o: s: m: hqvrf : " , ["help" , "csv" ,
137
139
"output=" , "list_rules" , "verbose=" , "show-url" , "no-update" ,
138
- "ci" , "var=" , "noBase" ])
140
+ "ci" , "quiet" , " var=" , "noBase" ])
139
141
except getopt .error , msg :
140
142
raise ShowMessageAndExit (msg )
141
143
return 0
@@ -144,7 +146,6 @@ def main(argv=None):
144
146
_nsiqcppstyle_state .output_format = "vs7"
145
147
filterScope = "default"
146
148
filterPath = ""
147
- ciMode = False
148
149
noBase = False
149
150
varMap = {}
150
151
extLangMap = {
@@ -171,7 +172,7 @@ def main(argv=None):
171
172
elif o == "-f" :
172
173
filterPath = a .strip ().replace ("\" " , "" )
173
174
elif o == "-v" :
174
- EnableVerbose ( )
175
+ console . SetLevel ( console . Level . Verbose )
175
176
elif o == "-s" :
176
177
filterScope = a
177
178
elif o == "--show-url" :
@@ -184,19 +185,21 @@ def main(argv=None):
184
185
elif o == "--var" :
185
186
varMap = GetCustomKeyValueMap (a , "--var=" + a )
186
187
elif o == "--ci" :
187
- ciMode = True
188
+ console .SetLevel (console .Level .Ci );
189
+ elif o in ("-q" , "--quiet" ):
190
+ console .SetLevel (console .Level .Error );
188
191
elif o == "--noBase" :
189
192
noBase = True
190
193
191
- print title
194
+ console . Out . Ci ( title )
192
195
runtimePath = GetRuntimePath ()
193
196
sys .path .append (runtimePath )
194
197
if updateNsiqCppStyle :
198
+ console .Out .Ci (console .Separator )
195
199
try :
196
- print "======================================================================================"
197
200
updateagent .agent .Update (version )
198
201
except Exception , e :
199
- print e
202
+ console . Out . Error ( e )
200
203
201
204
targetPaths = GetRealTargetPaths (args )
202
205
multipleTarget = True
@@ -219,8 +222,8 @@ def main(argv=None):
219
222
nsiqcppstyle_reporter .StartTarget (targetPath )
220
223
extLangMapCopy = copy .deepcopy (extLangMap )
221
224
targetName = os .path .basename (targetPath )
222
- print "======================================================================================"
223
- print "= Analyzing %s " % targetName
225
+ console . Out . Ci ( console . Separator )
226
+ console . Out . Ci ( "= Analyzing %s " % targetName )
224
227
225
228
if filterPath != "" :
226
229
filefilterPath = filterPath
@@ -237,7 +240,8 @@ def main(argv=None):
237
240
filterManager = FilterManager (filefilterPath , extLangMapCopy , varMap , filterScope )
238
241
239
242
if filterScope != filterManager .GetActiveFilter ().filterName :
240
- print "\n %s filter scope is not available. Instead, use %s\n " % (filterScope , filterManager .GetActiveFilter ().filterName )
243
+ console .Out .Error ("\n %s filter scope is not available. Instead, use %s\n "
244
+ % (filterScope , filterManager .GetActiveFilter ().filterName ))
241
245
242
246
filter = filterManager .GetActiveFilter ()
243
247
# Load Rule
@@ -246,21 +250,20 @@ def main(argv=None):
246
250
ShowMessageAndExit ("Error!. Rules must be set in %s" % filefilterPath , False )
247
251
continue
248
252
249
- ruleManager .LoadRules (filter .nsiqCppStyleRules , not ciMode )
253
+ ruleManager .LoadRules (filter .nsiqCppStyleRules )
250
254
_nsiqcppstyle_state .checkers = filter .nsiqCppStyleRules
251
255
_nsiqcppstyle_state .varMap = filter .varMap
252
256
nsiqcppstyle_reporter .ReportRules (ruleManager .availRuleNames , filter .nsiqCppStyleRules )
253
- if not ciMode :
254
- print filter .to_string ()
255
- print "======================================================================================"
256
-
257
- if VerboseMode (): print "* run nsiqcppstyle analysis on %s" % targetName
257
+
258
+ console .Out .Info (filter .to_string ())
259
+ console .Out .Ci (console .Separator )
260
+ console .Out .Verbose ("* run nsiqcppstyle analysis on %s" % targetName )
258
261
259
262
# if the target is file, analyze it without condition
260
263
if os .path .isfile (targetPath ):
261
264
fileExtension = targetPath [targetPath .rfind ('.' ) + 1 : ]
262
265
if fileExtension in cExtendstionSet :
263
- ProcessFile (ruleManager , targetPath , analyzedFiles , ciMode )
266
+ ProcessFile (ruleManager , targetPath , analyzedFiles )
264
267
265
268
# if the target is directory, analyze it with filefilter and basefilelist
266
269
else :
@@ -279,25 +282,25 @@ def main(argv=None):
279
282
basePart = eachFile [len (targetPath ): ]
280
283
if fileExtension in cExtendstionSet and basefilelist .IsNewOrChanged (eachFile ) and filter .CheckFileInclusion (basePart ):
281
284
nsiqcppstyle_reporter .StartFile (os .path .dirname (basePart ), fname )
282
- ProcessFile (ruleManager , eachFile , analyzedFiles , ciMode )
285
+ ProcessFile (ruleManager , eachFile , analyzedFiles )
283
286
nsiqcppstyle_reporter .EndFile ()
284
287
ruleManager .RunProjectRules (targetPath )
285
288
nsiqcppstyle_reporter .EndTarget ()
286
289
287
- nsiqcppstyle_reporter .ReportSummaryToScreen (analyzedFiles , _nsiqcppstyle_state , filter , ciMode )
290
+ nsiqcppstyle_reporter .ReportSummaryToScreen (analyzedFiles , _nsiqcppstyle_state , filter )
288
291
nsiqcppstyle_reporter .CloseReport (_nsiqcppstyle_state .output_format )
289
292
return _nsiqcppstyle_state .error_count
290
293
291
294
except Usage , err :
292
- print >> sys . stderr , err .msg
293
- print >> sys . stderr , "for help use --help"
295
+ console . Err . Error ( err .msg )
296
+ console . Err . Error ( "for help use --help" )
294
297
sys .exit (- 1 )
295
298
296
299
297
300
#################################################################################################3
298
301
299
- def ProcessFile (ruleManager , file , analyzedFiles , ciMode ):
300
- if not ciMode : print "Processing: " , file
302
+ def ProcessFile (ruleManager , file , analyzedFiles ):
303
+ console . Out . Info ( "Processing: " , file )
301
304
nsiqcppstyle_checker .ProcessFile (ruleManager , file )
302
305
analyzedFiles .append (file )
303
306
@@ -328,15 +331,7 @@ def GetRealTargetPaths(args):
328
331
ShowMessageAndExit ("Error!: Target directory %s is not exists" % eachTarget )
329
332
return targetPaths
330
333
331
- #################################################################################################3
332
-
333
- def EnableVerbose ():
334
- _nsiqcppstyle_state .verbose = True
335
-
336
- def VerboseMode ():
337
- return _nsiqcppstyle_state .verbose
338
-
339
-
334
+ #################################################################################################
340
335
341
336
##############################################################################
342
337
# Filter Manager
0 commit comments