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 Jul 27, 2023
1 parent 87932f7 commit 34d9d84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
44 changes: 17 additions & 27 deletions nxdrive/engine/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ def _get_next_doc_pair(self, item: DocPair) -> Optional[DocPair]:
try:
return self.dao.acquire_state(self.thread_id, item.id)
except sqlite3.OperationalError:
state = self.dao.get_state_from_id(item.id)
if state:
if state := self.dao.get_state_from_id(item.id):
if (
WINDOWS
and state.pair_state == "locally_moved"
Expand Down Expand Up @@ -460,9 +459,7 @@ def _execute(self) -> None:
log.info("The document does not exist anymore locally")
self.dao.remove_state(doc_pair)
elif error in LONG_FILE_ERRORS:
self.dao.remove_filter(
doc_pair.remote_parent_path + "/" + doc_pair.remote_ref
)
self.dao.remove_filter(f"{doc_pair.remote_parent_path}/{doc_pair.remote_ref}")
self.engine.longPathError.emit(doc_pair)
elif hasattr(exc, "trash_issue"):
"""
Expand All @@ -475,18 +472,19 @@ def _execute(self) -> None:
else:
self._handle_pair_handler_exception(doc_pair, handler_name, exc)
except RuntimeError as exc:
if "but the refreshed credentials are still expired" in str(exc):
log.warning(
"AWS credentials were refreshed, but the refreshed credentials are still expired"
)
log.info("Reinitializing the upload")
self.dao.remove_transfer(
"upload",
doc_pair=doc_pair.id,
is_direct_transfer=doc_pair.local_state == "direct",
)
else:
if "but the refreshed credentials are still expired" not in str(
exc
):
raise
log.warning(
"AWS credentials were refreshed, but the refreshed credentials are still expired"
)
log.info("Reinitializing the upload")
self.dao.remove_transfer(
"upload",
doc_pair=doc_pair.id,
is_direct_transfer=doc_pair.local_state == "direct",
)
except Exception as exc:
# Workaround to forward unhandled exceptions to sys.excepthook between all Qthreads
sys.excepthook(*sys.exc_info())
Expand Down Expand Up @@ -562,12 +560,7 @@ def _synchronize_direct_transfer(self, doc_pair: DocPair, /) -> None:
log.debug(f"The session is paused, skipping <DocPair[{doc_pair.id}]>")
return

if WINDOWS:
path = doc_pair.local_path
else:
# The path retrieved from the database will have its starting slash trimmed, restore it
path = Path(f"/{doc_pair.local_path}")

path = doc_pair.local_path if WINDOWS else Path(f"/{doc_pair.local_path}")
if not path.exists():
self.engine.directTranferError.emit(path)
if session:
Expand Down Expand Up @@ -615,9 +608,7 @@ def _direct_transfer_end(
# Clean-up
self.dao.remove_state(doc_pair, recursive=recursive)

# Update session then handle the status
session = self.dao.get_session(doc_pair.session)
if session:
if session := self.dao.get_session(doc_pair.session):
if (
not cancelled_transfer
and session.status is not TransferStatus.CANCELLED
Expand Down Expand Up @@ -656,8 +647,7 @@ def _synchronize_if_not_remotely_dirty(
remote_info.name != doc_pair.local_name
or remote_info.digest != doc_pair.local_digest
):
modified = self.dao.get_state_from_local(doc_pair.local_path)
if modified:
if modified := self.dao.get_state_from_local(doc_pair.local_path):
log.info(
f"Forcing remotely_modified for pair={modified!r} "
f"with info={remote_info!r}"
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ def engine(engine_dao):

@pytest.fixture
def remote():
mocked_remote = MockedRemote()
return mocked_remote
return MockedRemote()


@pytest.fixture()
Expand Down

0 comments on commit 34d9d84

Please sign in to comment.