daemon: updated utils.cmd to use returncode instead of wait(), removed redundant default encoding value for calls to decode/encode

This commit is contained in:
Blake Harnden 2023-06-08 14:34:24 -07:00
parent 94f070e0ff
commit 81230edac3
5 changed files with 8 additions and 8 deletions

View file

@ -1179,7 +1179,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
logger.debug("open xml: %s", request)
session = self.coreemu.create_session()
temp = tempfile.NamedTemporaryFile(delete=False)
temp.write(request.data.encode("utf-8"))
temp.write(request.data.encode())
temp.close()
temp_path = Path(temp.name)
file_path = Path(request.file)

View file

@ -105,7 +105,7 @@ class DistributedServer:
"""
with self.lock:
temp = NamedTemporaryFile(delete=False)
temp.write(data.encode("utf-8"))
temp.write(data.encode())
temp.close()
self.conn.put(temp.name, str(dst_path))
os.unlink(temp.name)

View file

@ -227,7 +227,7 @@ class DockerNode(CoreNode):
"""
logger.debug("node(%s) create file(%s) mode(%o)", self.name, file_path, mode)
temp = NamedTemporaryFile(delete=False)
temp.write(contents.encode("utf-8"))
temp.write(contents.encode())
temp.close()
temp_path = Path(temp.name)
directory = file_path.parent

View file

@ -170,7 +170,7 @@ class LxcNode(CoreNode):
"""
logger.debug("node(%s) create file(%s) mode(%o)", self.name, file_path, mode)
temp = NamedTemporaryFile(delete=False)
temp.write(contents.encode("utf-8"))
temp.write(contents.encode())
temp.close()
temp_path = Path(temp.name)
directory = file_path.parent

View file

@ -87,7 +87,7 @@ def hashkey(value: Union[str, int]) -> int:
"""
if isinstance(value, int):
value = str(value)
value = value.encode("utf-8")
value = value.encode()
return int(hashlib.sha256(value).hexdigest(), 16)
@ -224,9 +224,9 @@ def cmd(
p = Popen(args, stdout=output, stderr=output, env=env, cwd=cwd, shell=shell)
if wait:
stdout, stderr = p.communicate()
stdout = stdout.decode("utf-8").strip()
stderr = stderr.decode("utf-8").strip()
status = p.wait()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
status = p.returncode
if status != 0:
raise CoreCommandError(status, input_args, stdout, stderr)
return stdout