Skip to content

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Nov 6, 2023
1 parent e589c94 commit 0e5376e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions nxdrive/updater/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,14 @@ def server_ver(self) -> Optional[str]:
`None` if no bound engine.
"""

for engine in self.manager.engines.copy().values():
if engine.remote:
return engine.remote.client.server_version # type: ignore
return None
return next(
(
engine.remote.client.server_version
for engine in self.manager.engines.copy().values()
if engine.remote
),
None,
)

#
# Public methods that can be overridden
Expand Down Expand Up @@ -157,11 +161,10 @@ def update(self, version: str, /) -> None:
self._install(version, self._download(version))
except OSError as exc:
self._set_status(UPDATE_STATUS_UPDATE_AVAILABLE, version=version)
if exc.errno in NO_SPACE_ERRORS:
log.warning("Update failed, disk space needed", exc_info=True)
self.noSpaceLeftOnDevice.emit()
else:
if exc.errno not in NO_SPACE_ERRORS:

Check warning on line 164 in nxdrive/updater/base.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/updater/base.py#L164

Added line #L164 was not covered by tests
raise
log.warning("Update failed, disk space needed", exc_info=True)
self.noSpaceLeftOnDevice.emit()

Check warning on line 167 in nxdrive/updater/base.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/updater/base.py#L166-L167

Added lines #L166 - L167 were not covered by tests
except CONNECTION_ERROR:
log.warning("Error during update request", exc_info=True)
except UpdateIntegrityError as exc:
Expand All @@ -179,7 +182,7 @@ def _download(self, version: str, /) -> str:

name = self.release_file.format(version=version)
url = "/".join([self.update_site, self.versions[version]["type"], name])
path = os.path.join(gettempdir(), uuid.uuid4().hex + "_" + name)
path = os.path.join(gettempdir(), f"{uuid.uuid4().hex}_{name}")
headers = {"User-Agent": user_agent()}

log.info(f"Fetching {APP_NAME} {version} from {url!r} into {path!r}")
Expand Down Expand Up @@ -299,14 +302,13 @@ def force_downgrade(self) -> None:
except UpdateError:
self._set_status(UPDATE_STATUS_UNAVAILABLE_SITE)
else:
versions = {
if versions := {

Check warning on line 305 in nxdrive/updater/base.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/updater/base.py#L305

Added line #L305 was not covered by tests
version: info
for version, info in self.versions.items()
if info.get("type", "").lower()
in (self.manager.get_update_channel(), "release")
and version_lt(version, "4")
}
if versions:
}:
version = max(versions.keys())
self._set_status(UPDATE_STATUS_INCOMPATIBLE_SERVER, version=version)
self.serverIncompatible.emit()
Expand Down Expand Up @@ -363,8 +365,7 @@ def _set_status(
self._set_progress(progress)

def get_version_channel(self, version: str, /) -> str:
info = self.versions.get(version)
if info:
if info := self.versions.get(version):

Check warning on line 368 in nxdrive/updater/base.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/updater/base.py#L368

Added line #L368 was not covered by tests
return info.get("type", None) or ""

log.debug(f"No version {version} in record.")
Expand Down

0 comments on commit 0e5376e

Please sign in to comment.