3131# Quick start: just run this script without any arguments
3232
3333import platform
34+ import os
35+ import sys
36+ import re
37+ import time
38+ import subprocess
39+ import donate_cpu_lib as lib
3440
3541from packaging .version import Version
36- from donate_cpu_lib import *
3742
43+ __my_script_name = os .path .splitext (os .path .basename (sys .argv [0 ]))[0 ]
44+ work_path = os .path .expanduser (os .path .join ('~' , 'cppcheck-' + __my_script_name + '-workfolder' ))
3845max_packages = None
3946package_urls = []
47+ do_upload = True
48+ bandwidth_limit = None
49+ stop_time = None
4050
4151for arg in sys .argv [1 :]:
4252 # --stop-time=12:00 => run until ~12:00 and then stop
4858 print ('Argument "{}" is invalid.' .format (arg ))
4959 print ('"-j" must be followed by a positive number.' )
5060 sys .exit (1 )
51- jobs = arg
52- print ( 'Jobs:' + jobs [ 2 :] )
61+ print ( 'Jobs:' + arg [ 2 :])
62+ lib . set_jobs ( arg )
5363 elif arg .startswith ('--package=' ):
5464 pkg = arg [arg .find ('=' )+ 1 :]
5565 package_urls .append (pkg )
7080 print ('work path does not exist!' )
7181 sys .exit (1 )
7282 elif arg == '--test' :
73- server_address = ( 'localhost' , 8001 )
83+ lib . set_server_address (( 'localhost' , 8001 ) )
7484 elif arg .startswith ('--bandwidth-limit=' ):
7585 bandwidth_limit = arg [arg .find ('=' )+ 1 :]
7686 elif arg .startswith ('--max-packages=' ):
90100 elif arg .startswith ('--no-upload' ):
91101 do_upload = False
92102 elif arg == '--version' :
93- print (get_client_version ())
103+ print (lib . get_client_version ())
94104 sys .exit (0 )
95105 elif arg == '--help' :
96106 print ('Donate CPU to Cppcheck project' )
124134 sys .exit (1 )
125135
126136print ('Thank you!' )
127- if not check_requirements ():
137+ if not lib . check_requirements ():
128138 sys .exit (1 )
129139if bandwidth_limit and isinstance (bandwidth_limit , str ):
130140 if subprocess .call (['wget' , '--limit-rate=' + bandwidth_limit , '-q' , '--spider' , 'cppcheck1.osuosl.org' ]) == 2 :
146156
147157print ('Get Cppcheck..' )
148158try :
149- try_retry (clone_cppcheck , fargs = (repo_path , migrate_repo_path ))
150- except :
151- print ('Error: Failed to clone Cppcheck, retry later' )
159+ lib . try_retry (lib . clone_cppcheck , fargs = (repo_path , migrate_repo_path ))
160+ except Exception as e :
161+ print ('Error: Failed to clone Cppcheck ({}) , retry later' . format ( e ) )
152162 sys .exit (1 )
153163
154164while True :
163173 if stop_time < time .strftime ('%H:%M' ):
164174 print ('Stopping. Thank you!' )
165175 sys .exit (0 )
166- cppcheck_versions = get_cppcheck_versions (server_address )
176+ cppcheck_versions = lib . get_cppcheck_versions ()
167177 if cppcheck_versions is None :
168178 print ('Failed to communicate with server, retry later' )
169179 sys .exit (1 )
176186 current_cppcheck_dir = os .path .join (work_path , 'tree-' + ver )
177187 try :
178188 print ('Fetching Cppcheck-{}..' .format (ver ))
179- try_retry (checkout_cppcheck_version , fargs = (repo_path , ver , current_cppcheck_dir ))
189+ lib . try_retry (lib . checkout_cppcheck_version , fargs = (repo_path , ver , current_cppcheck_dir ))
180190 except KeyboardInterrupt as e :
181191 # Passthrough for user abort
182192 raise e
183- except :
184- print ('Failed to update Cppcheck, retry later' )
193+ except Exception as e :
194+ print ('Failed to update Cppcheck ({}) , retry later' . format ( e ) )
185195 sys .exit (1 )
186196 if ver == 'main' :
187- if not compile_cppcheck (current_cppcheck_dir , jobs ):
197+ if not lib . compile_cppcheck (current_cppcheck_dir ):
188198 print ('Failed to compile Cppcheck-{}, retry later' .format (ver ))
189199 sys .exit (1 )
190200 else :
191- if not compile_version (current_cppcheck_dir , jobs ):
201+ if not lib . compile_version (current_cppcheck_dir ):
192202 print ('Failed to compile Cppcheck-{}, retry later' .format (ver ))
193203 sys .exit (1 )
194204 if package_urls :
195205 package = package_urls [packages_processed - 1 ]
196206 else :
197- package = get_package (server_address )
198- tgz = download_package (work_path , package , bandwidth_limit )
207+ package = lib . get_package ()
208+ tgz = lib . download_package (work_path , package , bandwidth_limit )
199209 if tgz is None :
200210 print ("No package downloaded" )
201211 continue
202212 skip_files = None
203213 if package .find ('/qtcreator/' ) > 0 :
204214 # macro_pounder_fn.c is a preprocessor torture test that takes time to finish
205215 skip_files = ('macro_pounder_fn.c' ,)
206- source_path , source_found = unpack_package (work_path , tgz , skip_files = skip_files )
216+ source_path , source_found = lib . unpack_package (work_path , tgz , skip_files = skip_files )
207217 if not source_found :
208218 print ("No files to process" )
209219 continue
218228 old_timing_info = ''
219229 cppcheck_head_info = ''
220230 client_version_head = ''
221- libraries = library_includes .get_libraries (source_path )
231+ libraries = lib . library_includes .get_libraries (source_path )
222232
223233 for ver in cppcheck_versions :
224234 tree_path = os .path .join (work_path , 'tree-' + ver )
225235 capture_callstack = False
226236 if ver == 'head' :
227237 tree_path = os .path .join (work_path , 'tree-main' )
228- cppcheck_head_info = get_cppcheck_info (tree_path )
238+ cppcheck_head_info = lib . get_cppcheck_info (tree_path )
229239 capture_callstack = True
230240
231241 def get_client_version_head ():
@@ -238,12 +248,12 @@ def get_client_version_head():
238248 return None
239249
240250 client_version_head = get_client_version_head ()
241- c , errout , info , t , cppcheck_options , timing_info = scan_package (tree_path , source_path , jobs , libraries , capture_callstack )
251+ c , errout , info , t , cppcheck_options , timing_info = lib . scan_package (tree_path , source_path , libraries , capture_callstack )
242252 if c < 0 :
243253 if c == - 101 and 'error: could not find or open any of the paths given.' in errout :
244254 # No sourcefile found (for example only headers present)
245255 count += ' 0'
246- elif c == RETURN_CODE_TIMEOUT :
256+ elif c == lib . RETURN_CODE_TIMEOUT :
247257 # Timeout
248258 count += ' TO!'
249259 timeout = True
@@ -263,8 +273,8 @@ def get_client_version_head():
263273 output = 'cppcheck-options: ' + cppcheck_options + '\n '
264274 output += 'platform: ' + platform .platform () + '\n '
265275 output += 'python: ' + platform .python_version () + '\n '
266- output += 'client-version: ' + get_client_version () + '\n '
267- output += 'compiler: ' + get_compiler_version () + '\n '
276+ output += 'client-version: ' + lib . get_client_version () + '\n '
277+ output += 'compiler: ' + lib . get_compiler_version () + '\n '
268278 output += 'cppcheck: ' + ' ' .join (cppcheck_versions ) + '\n '
269279 output += 'head-info: ' + cppcheck_head_info + '\n '
270280 output += 'count:' + count + '\n '
@@ -276,18 +286,18 @@ def get_client_version_head():
276286 if 'head' in cppcheck_versions :
277287 output += 'head results:\n ' + results_to_diff [cppcheck_versions .index ('head' )]
278288 if not crash and not timeout :
279- output += 'diff:\n ' + diff_results (cppcheck_versions [0 ], results_to_diff [0 ], cppcheck_versions [1 ], results_to_diff [1 ]) + '\n '
289+ output += 'diff:\n ' + lib . diff_results (cppcheck_versions [0 ], results_to_diff [0 ], cppcheck_versions [1 ], results_to_diff [1 ]) + '\n '
280290 if package_urls :
281291 print ('=========================================================' )
282292 print (output )
283293 print ('=========================================================' )
284294 print (info_output )
285295 print ('=========================================================' )
286296 if do_upload :
287- if upload_results (package , output , server_address ):
288- upload_info (package , info_output , server_address )
297+ if lib . upload_results (package , output ):
298+ lib . upload_info (package , info_output )
289299 if not max_packages or packages_processed < max_packages :
290300 print ('Sleep 5 seconds..' )
291- if (client_version_head is not None ) and (Version (client_version_head ) > Version (get_client_version ())):
301+ if (client_version_head is not None ) and (Version (client_version_head ) > Version (lib . get_client_version ())):
292302 print ("ATTENTION: A newer client version ({}) is available - please update!" .format (client_version_head ))
293303 time .sleep (5 )
0 commit comments