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 26, 2023
1 parent a1bd381 commit 8c35f76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 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):

Check warning on line 294 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L294

Added line #L294 was not covered by tests
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}")

Check warning on line 462 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L462

Added line #L462 was not covered by tests
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(

Check warning on line 475 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L475

Added line #L475 was not covered by tests
exc
):
raise
log.warning(

Check warning on line 479 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L479

Added line #L479 was not covered by tests
"AWS credentials were refreshed, but the refreshed credentials are still expired"
)
log.info("Reinitializing the upload")
self.dao.remove_transfer(

Check warning on line 483 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L482-L483

Added lines #L482 - L483 were not covered by tests
"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 @@ -563,12 +561,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 @@ -616,9 +609,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):

Check warning on line 612 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L612

Added line #L612 was not covered by tests
if (
not cancelled_transfer
and session.status is not TransferStatus.CANCELLED
Expand Down Expand Up @@ -657,8 +648,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):

Check warning on line 651 in nxdrive/engine/processor.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/engine/processor.py#L651

Added line #L651 was not covered by tests
log.info(
f"Forcing remotely_modified for pair={modified!r} "
f"with info={remote_info!r}"
Expand Down
6 changes: 1 addition & 5 deletions nxdrive/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def should_ignore(event: _Event) -> bool:

def before_send(event: _Event, _: _Hint, /) -> Any:
"""Alter an event before sending to the Sentry server."""
if should_ignore(event):
# The event will not be sent if None is returned
return None

return event
return None if should_ignore(event) else event


def setup_sentry() -> None:
Expand Down

0 comments on commit 8c35f76

Please sign in to comment.