donate-cpu.py: added `--version` and show a message when a newer client is available (#4288)

This commit is contained in:
Oliver Stöneberg 2022-07-18 16:24:04 +02:00 committed by GitHub
parent db155a59c1
commit cc9c5a2768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -17,6 +17,7 @@
# --max-packages=N Process N packages and then exit. A value of 0 means infinitely. # --max-packages=N Process N packages and then exit. A value of 0 means infinitely.
# --no-upload Do not upload anything. Defaults to False. # --no-upload Do not upload anything. Defaults to False.
# --packages Process a list of given packages. # --packages Process a list of given packages.
# --version Returns the version (of the underlying donate_cpu_lib.py).
# #
# What this script does: # What this script does:
# 1. Check requirements # 1. Check requirements
@ -30,6 +31,8 @@
# Quick start: just run this script without any arguments # Quick start: just run this script without any arguments
import platform import platform
from distutils.version import StrictVersion
from donate_cpu_lib import * from donate_cpu_lib import *
max_packages = None max_packages = None
@ -86,6 +89,9 @@ for arg in sys.argv[1:]:
max_packages = None max_packages = None
elif arg.startswith('--no-upload'): elif arg.startswith('--no-upload'):
do_upload = False do_upload = False
elif arg == '--version':
print(get_client_version())
sys.exit(0)
elif arg == '--help': elif arg == '--help':
print('Donate CPU to Cppcheck project') print('Donate CPU to Cppcheck project')
print('') print('')
@ -100,6 +106,8 @@ for arg in sys.argv[1:]:
print(' --bandwidth-limit=2m => max. 2 megabytes per second') print(' --bandwidth-limit=2m => max. 2 megabytes per second')
print(' --max-packages=N Process N packages and then exit. A value of 0 means infinitely.') print(' --max-packages=N Process N packages and then exit. A value of 0 means infinitely.')
print(' --no-upload Do not upload anything. Defaults to False.') print(' --no-upload Do not upload anything. Defaults to False.')
print(' --packages Process a list of given packages.')
print(' --version Returns the version (of the underlying donate_cpu_lib.py).')
print('') print('')
print('Quick start: just run this script without any arguments') print('Quick start: just run this script without any arguments')
sys.exit(0) sys.exit(0)
@ -209,6 +217,7 @@ while True:
head_timing_info = '' head_timing_info = ''
old_timing_info = '' old_timing_info = ''
cppcheck_head_info = '' cppcheck_head_info = ''
client_version_head = ''
libraries = library_includes.get_libraries(source_path) libraries = library_includes.get_libraries(source_path)
for ver in cppcheck_versions: for ver in cppcheck_versions:
@ -218,6 +227,17 @@ while True:
tree_path = os.path.join(work_path, 'tree-main') tree_path = os.path.join(work_path, 'tree-main')
cppcheck_head_info = get_cppcheck_info(tree_path) cppcheck_head_info = get_cppcheck_info(tree_path)
capture_callstack = True capture_callstack = True
def get_client_version_head():
cmd = os.path.join(tree_path, 'tools', 'donate-cpu.py') + ' ' + '--version'
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
try:
comm = p.communicate()
return comm[1]
except:
return None
client_version_head = get_client_version_head()
c, errout, info, t, cppcheck_options, timing_info = scan_package(tree_path, source_path, jobs, libraries, capture_callstack) c, errout, info, t, cppcheck_options, timing_info = scan_package(tree_path, source_path, jobs, libraries, capture_callstack)
if c < 0: if c < 0:
if c == -101 and 'error: could not find or open any of the paths given.' in errout: if c == -101 and 'error: could not find or open any of the paths given.' in errout:
@ -268,4 +288,6 @@ while True:
upload_info(package, info_output, server_address) upload_info(package, info_output, server_address)
if not max_packages or packages_processed < max_packages: if not max_packages or packages_processed < max_packages:
print('Sleep 5 seconds..') print('Sleep 5 seconds..')
if (client_version_head is not None) and (StrictVersion(client_version_head) >= StrictVersion(get_client_version())):
print("ATTENTION: A newer client version ({}) is available - please update!".format(client_version_head))
time.sleep(5) time.sleep(5)

View File

@ -15,7 +15,7 @@ import shlex
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/ # Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic # Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes) # changes)
CLIENT_VERSION = "1.3.27" CLIENT_VERSION = "1.3.28"
# Timeout for analysis with Cppcheck in seconds # Timeout for analysis with Cppcheck in seconds
CPPCHECK_TIMEOUT = 30 * 60 CPPCHECK_TIMEOUT = 30 * 60
@ -627,6 +627,10 @@ def get_compiler_version():
return stdout.split('\n')[0] return stdout.split('\n')[0]
def get_client_version():
return CLIENT_VERSION
my_script_name = os.path.splitext(os.path.basename(sys.argv[0]))[0] my_script_name = os.path.splitext(os.path.basename(sys.argv[0]))[0]
jobs = '-j1' jobs = '-j1'
stop_time = None stop_time = None