donate_cpu: Use with ... as (#2520)
This commit is contained in:
parent
488bc9997c
commit
b13ae83845
|
@ -14,7 +14,7 @@ import shlex
|
|||
# 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
|
||||
# changes)
|
||||
CLIENT_VERSION = "1.2.1"
|
||||
CLIENT_VERSION = "1.2.2"
|
||||
|
||||
# Timeout for analysis with Cppcheck in seconds
|
||||
CPPCHECK_TIMEOUT = 60 * 60
|
||||
|
@ -108,29 +108,27 @@ def compile_cppcheck(cppcheck_path, jobs):
|
|||
|
||||
def get_cppcheck_versions(server_address):
|
||||
print('Connecting to server to get Cppcheck versions..')
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(server_address)
|
||||
sock.send(b'GetCppcheckVersions\n')
|
||||
versions = sock.recv(256)
|
||||
except socket.error as err:
|
||||
print('Failed to get cppcheck versions: ' + str(err))
|
||||
return None
|
||||
sock.close()
|
||||
return versions.decode('utf-8').split()
|
||||
|
||||
|
||||
def get_packages_count(server_address):
|
||||
print('Connecting to server to get count of packages..')
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(server_address)
|
||||
sock.send(b'getPackagesCount\n')
|
||||
packages = int(sock.recv(64))
|
||||
except socket.error as err:
|
||||
print('Failed to get count of packages: ' + str(err))
|
||||
return None
|
||||
sock.close()
|
||||
return packages
|
||||
|
||||
|
||||
|
@ -213,7 +211,7 @@ def unpack_package(work_path, tgz):
|
|||
os.chdir(temp_path)
|
||||
found = False
|
||||
if tarfile.is_tarfile(tgz):
|
||||
tf = tarfile.open(tgz)
|
||||
with tarfile.open(tgz) as tf:
|
||||
for member in tf:
|
||||
if member.name.startswith(('/', '..')):
|
||||
# Skip dangerous file names
|
||||
|
@ -228,7 +226,6 @@ def unpack_package(work_path, tgz):
|
|||
pass
|
||||
except AttributeError:
|
||||
pass
|
||||
tf.close()
|
||||
os.chdir(work_path)
|
||||
return found
|
||||
|
||||
|
@ -240,12 +237,8 @@ def has_include(path, includes):
|
|||
for name in files:
|
||||
filename = os.path.join(root, name)
|
||||
try:
|
||||
if sys.version_info.major < 3:
|
||||
f = open(filename, 'rt')
|
||||
else:
|
||||
f = open(filename, 'rt', errors='ignore')
|
||||
with open(filename, 'rt', errors='ignore') as f:
|
||||
filedata = f.read()
|
||||
f.close()
|
||||
if re.search(re_expr, filedata, re.MULTILINE):
|
||||
return True
|
||||
except IOError:
|
||||
|
@ -418,11 +411,10 @@ def upload_results(package, results, server_address):
|
|||
max_retries = 4
|
||||
for retry in range(max_retries):
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(server_address)
|
||||
cmd = 'write\n'
|
||||
send_all(sock, cmd + package + '\n' + results + '\nDONE')
|
||||
sock.close()
|
||||
print('Results have been successfully uploaded.')
|
||||
return True
|
||||
except socket.error as err:
|
||||
|
@ -439,10 +431,9 @@ def upload_info(package, info_output, server_address):
|
|||
max_retries = 3
|
||||
for retry in range(max_retries):
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(server_address)
|
||||
send_all(sock, 'write_info\n' + package + '\n' + info_output + '\nDONE')
|
||||
sock.close()
|
||||
print('Information output has been successfully uploaded.')
|
||||
return True
|
||||
except socket.error as err:
|
||||
|
|
Loading…
Reference in New Issue