forked from platformio/platformio-core
Fix PyLint issues: consider-using-with
This commit is contained in:
@ -236,9 +236,9 @@ def CheckUploadSize(_, target, source, env):
|
||||
def _format_availale_bytes(value, total):
|
||||
percent_raw = float(value) / float(total)
|
||||
blocks_per_progress = 10
|
||||
used_blocks = int(round(blocks_per_progress * percent_raw))
|
||||
if used_blocks > blocks_per_progress:
|
||||
used_blocks = blocks_per_progress
|
||||
used_blocks = min(
|
||||
int(round(blocks_per_progress * percent_raw)), blocks_per_progress
|
||||
)
|
||||
return "[{:{}}] {: 6.1%} (used {:d} bytes from {:d} bytes)".format(
|
||||
"=" * used_blocks, blocks_per_progress, percent_raw, value, total
|
||||
)
|
||||
|
@ -31,6 +31,7 @@ class LogToFile(DeviceMonitorFilter):
|
||||
"%y%m%d-%H%M%S"
|
||||
)
|
||||
print("--- Logging an output to %s" % os.path.abspath(log_file_name))
|
||||
# pylint: disable=consider-using-with
|
||||
self._log_fp = io.open(log_file_name, "w", encoding="utf-8")
|
||||
return self
|
||||
|
||||
|
@ -73,7 +73,7 @@ class FileDownloader(object):
|
||||
def start(self, with_progress=True, silent=False):
|
||||
label = "Downloading"
|
||||
itercontent = self._request.iter_content(chunk_size=io.DEFAULT_BUFFER_SIZE)
|
||||
fp = open(self._destination, "wb")
|
||||
fp = open(self._destination, "wb") # pylint: disable=consider-using-with
|
||||
try:
|
||||
if not with_progress or self.get_size() == -1:
|
||||
if not silent:
|
||||
|
@ -62,7 +62,7 @@ class LockFile(object):
|
||||
else:
|
||||
raise LockFileExists
|
||||
|
||||
self._fp = open(self._lock_path, "w")
|
||||
self._fp = open(self._lock_path, "w") # pylint: disable=consider-using-with
|
||||
try:
|
||||
if LOCKFILE_CURRENT_INTERFACE == LOCKFILE_INTERFACE_FCNTL:
|
||||
fcntl.flock(self._fp.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
|
@ -109,16 +109,16 @@ def exec_command(*args, **kwargs):
|
||||
default.update(kwargs)
|
||||
kwargs = default
|
||||
|
||||
p = subprocess.Popen(*args, **kwargs)
|
||||
try:
|
||||
result["out"], result["err"] = p.communicate()
|
||||
result["returncode"] = p.returncode
|
||||
except KeyboardInterrupt:
|
||||
raise exception.AbortedByUser()
|
||||
finally:
|
||||
for s in ("stdout", "stderr"):
|
||||
if isinstance(kwargs[s], AsyncPipeBase):
|
||||
kwargs[s].close()
|
||||
with subprocess.Popen(*args, **kwargs) as p:
|
||||
try:
|
||||
result["out"], result["err"] = p.communicate()
|
||||
result["returncode"] = p.returncode
|
||||
except KeyboardInterrupt:
|
||||
raise exception.AbortedByUser()
|
||||
finally:
|
||||
for s in ("stdout", "stderr"):
|
||||
if isinstance(kwargs[s], AsyncPipeBase):
|
||||
kwargs[s].close()
|
||||
|
||||
for s in ("stdout", "stderr"):
|
||||
if isinstance(kwargs[s], AsyncPipeBase):
|
||||
|
Reference in New Issue
Block a user