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