1111# --bandwidth-limit=limit Limit download rate for packages. Format for limit is the same that wget uses.
1212# Examples: --bandwidth-limit=250k => max. 250 kilobytes per second
1313# --bandwidth-limit=2m => max. 2 megabytes per second
14+ # --max-packages=N Process N packages and then exit. A value of 0 means infinitely.
1415#
1516# What this script does:
1617# 1. Check requirements
3738# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
3839# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
3940# changes)
40- CLIENT_VERSION = "1.1.10 "
41+ CLIENT_VERSION = "1.1.11 "
4142
4243
4344def checkRequirements ():
@@ -380,6 +381,7 @@ def uploadInfo(package, info_output, server_address):
380381packageUrl = None
381382server_address = ('cppcheck.osuosl.org' , 8000 )
382383bandwidth_limit = None
384+ max_packages = None
383385for arg in sys .argv [1 :]:
384386 # --stop-time=12:00 => run until ~12:00 and then stop
385387 if arg .startswith ('--stop-time=' ):
@@ -401,6 +403,20 @@ def uploadInfo(package, info_output, server_address):
401403 server_address = ('localhost' , 8001 )
402404 elif arg .startswith ('--bandwidth-limit=' ):
403405 bandwidth_limit = arg [arg .find ('=' )+ 1 :]
406+ elif arg .startswith ('--max-packages=' ):
407+ arg_value = arg [arg .find ('=' )+ 1 :]
408+ try :
409+ max_packages = int (arg_value )
410+ except ValueError :
411+ max_packages = None
412+ if max_packages < 0 :
413+ max_packages = None
414+ if max_packages is None :
415+ print ('Error: Max. packages value "{}" is invalid. Must be a positive number or 0.' .format (arg_value ))
416+ sys .exit (1 )
417+ # 0 means infinitely, no counting needed.
418+ if max_packages == 0 :
419+ max_packages = None
404420 elif arg == '--help' :
405421 print ('Donate CPU to Cppcheck project' )
406422 print ('' )
@@ -413,6 +429,7 @@ def uploadInfo(package, info_output, server_address):
413429 print (' --bandwidth-limit=limit Limit download rate for packages. Format for limit is the same that wget uses.' )
414430 print (' Examples: --bandwidth-limit=250k => max. 250 kilobytes per second' )
415431 print (' --bandwidth-limit=2m => max. 2 megabytes per second' )
432+ print (' --max-packages=N Process N packages and then exit. A value of 0 means infinitely.' )
416433 print ('' )
417434 print ('Quick start: just run this script without any arguments' )
418435 sys .exit (0 )
@@ -429,10 +446,20 @@ def uploadInfo(package, info_output, server_address):
429446 sys .exit (1 )
430447 else :
431448 print ('Bandwidth-limit: ' + bandwidth_limit )
449+ if max_packages :
450+ print ('Maximum number of packages to download and analyze: {}' .format (max_packages ))
432451if not os .path .exists (workpath ):
433452 os .mkdir (workpath )
434453cppcheckPath = workpath + '/cppcheck'
454+ packages_processed = 0
435455while True :
456+ if max_packages :
457+ if packages_processed >= max_packages :
458+ print ('Processed the specified number of {} package(s). Exiting now.' .format (max_packages ))
459+ break
460+ else :
461+ print ('Processing package {} of the specified {} package(s).' .format (packages_processed + 1 , max_packages ))
462+ packages_processed += 1
436463 if stopTime :
437464 print ('stopTime:' + stopTime + '. Time:' + time .strftime ('%H:%M' ) + '.' )
438465 if stopTime < time .strftime ('%H:%M' ):
@@ -525,5 +552,6 @@ def uploadInfo(package, info_output, server_address):
525552 uploadResults (package , output , server_address )
526553 if info_exists :
527554 uploadInfo (package , info_output , server_address )
528- print ('Sleep 5 seconds..' )
529- time .sleep (5 )
555+ if not max_packages or packages_processed < max_packages :
556+ print ('Sleep 5 seconds..' )
557+ time .sleep (5 )
0 commit comments