Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NXDRIVE-2861: Fix behavior when not entering the correct URL format (Sourcery refactored) #4232

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 67 additions & 80 deletions nxdrive/gui/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@
@pyqtSlot(str, int, result=list)
def get_last_files(self, uid: str, number: int, /) -> List[Dict[str, Any]]:
"""Return the last files transferred (see EngineDAO)."""
engine = self._manager.engines.get(uid)
if not engine:
if engine := self._manager.engines.get(uid):
return [s.export() for s in engine.dao.get_last_files(number)]

Check warning on line 123 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L122-L123

Added lines #L122 - L123 were not covered by tests
else:
return []
return [s.export() for s in engine.dao.get_last_files(number)]
Comment on lines -122 to -125
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_last_files refactored with the following changes:


@pyqtSlot(str, result=int)
def get_last_files_count(self, uid: str, /) -> int:
"""Return the count of the last files transferred (see EngineDAO)."""
count = 0
engine = self._manager.engines.get(uid)
if engine:
count = engine.dao.get_last_files_count(duration=60)
return count
return (

Check warning on line 130 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L130

Added line #L130 was not covered by tests
engine.dao.get_last_files_count(duration=60)
if (engine := self._manager.engines.get(uid))
else 0
)
Comment on lines -130 to +134
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_last_files_count refactored with the following changes:


@pyqtSlot(QUrl, result=str)
def to_local_file(self, url: QUrl, /) -> str:
Expand Down Expand Up @@ -217,8 +217,7 @@
@pyqtSlot(str, result=int)
def get_active_sessions_count(self, uid: str, /) -> int:
"""Return the count of active sessions items."""
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 220 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L220

Added line #L220 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_active_sessions_count refactored with the following changes:

return engine.dao.get_count(
f"status IN ({TransferStatus.ONGOING.value}, {TransferStatus.PAUSED.value})",
table="Sessions",
Expand All @@ -228,8 +227,7 @@
@pyqtSlot(str, result=int)
def get_completed_sessions_count(self, uid: str, /) -> int:
"""Return the count of completed sessions items."""
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 230 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L230

Added line #L230 was not covered by tests
Comment on lines -231 to +230
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_completed_sessions_count refactored with the following changes:

return engine.dao.get_count(
f"status IN ({TransferStatus.CANCELLED.value}, {TransferStatus.DONE.value})",
table="Sessions",
Expand All @@ -249,12 +247,12 @@
) -> None:
"""Pause a given transfer. *nature* is either downloads or upload."""
log.info(f"Pausing {nature} {transfer_uid} for engine {engine_uid!r}")
engine = self._manager.engines.get(engine_uid)
if not engine:
if engine := self._manager.engines.get(engine_uid):
engine.dao.pause_transfer(

Check warning on line 251 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L250-L251

Added lines #L250 - L251 were not covered by tests
nature, transfer_uid, progress, is_direct_transfer=is_direct_transfer
)
else:
return
engine.dao.pause_transfer(
nature, transfer_uid, progress, is_direct_transfer=is_direct_transfer
)
Comment on lines -252 to -257
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.pause_transfer refactored with the following changes:


@pyqtSlot(str, str, int, bool)
def resume_transfer(
Expand All @@ -268,77 +266,79 @@
) -> None:
"""Resume a given transfer. *nature* is either downloads or upload."""
log.info(f"Resume {nature} {uid} for engine {engine_uid!r}")
engine = self._manager.engines.get(engine_uid)
if not engine:
if engine := self._manager.engines.get(engine_uid):
engine.resume_transfer(nature, uid, is_direct_transfer=is_direct_transfer)

Check warning on line 270 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L269-L270

Added lines #L269 - L270 were not covered by tests
else:
return
engine.resume_transfer(nature, uid, is_direct_transfer=is_direct_transfer)
Comment on lines -271 to -274
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.resume_transfer refactored with the following changes:


@pyqtSlot(str, int)
def resume_session(self, engine_uid: str, uid: int, /) -> None:
"""Resume a given session and it's transfers."""
log.info(f"Resume session {uid} for engine {engine_uid!r}")
engine = self._manager.engines.get(engine_uid)
if not engine:
if engine := self._manager.engines.get(engine_uid):
engine.resume_session(uid)

Check warning on line 279 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L278-L279

Added lines #L278 - L279 were not covered by tests
else:
return
engine.resume_session(uid)
Comment on lines -280 to -283
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.resume_session refactored with the following changes:


@pyqtSlot(str, int)
def pause_session(self, engine_uid: str, uid: int, /) -> None:
"""Pause a given session and it's transfers."""
log.info(f"Pausing session {uid} for engine {engine_uid!r}")
engine = self._manager.engines.get(engine_uid)
if not engine:
if engine := self._manager.engines.get(engine_uid):
engine.dao.pause_session(uid)

Check warning on line 288 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L287-L288

Added lines #L287 - L288 were not covered by tests
else:
return
engine.dao.pause_session(uid)
Comment on lines -289 to -292
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.pause_session refactored with the following changes:


def cancel_session(self, engine_uid: str, uid: int, /) -> None:
"""Cancel a given session and it's transfers."""
log.info(f"Cancelling session {uid} for engine {engine_uid!r}")
engine = self._manager.engines.get(engine_uid)
if not engine:
if engine := self._manager.engines.get(engine_uid):
engine.cancel_session(uid)

Check warning on line 296 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L295-L296

Added lines #L295 - L296 were not covered by tests
else:
return
engine.cancel_session(uid)
Comment on lines -297 to -300
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.cancel_session refactored with the following changes:


@pyqtSlot(str, str)
def show_metadata(self, uid: str, ref: str, /) -> None:
self.application.hide_systray()
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 303 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L303

Added line #L303 was not covered by tests
Comment on lines -305 to +303
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.show_metadata refactored with the following changes:

path = engine.local.abspath(Path(ref))
self.application.show_metadata(path)

@pyqtSlot(str, result=list)
def get_unsynchronizeds(self, uid: str, /) -> List[Dict[str, Any]]:
result = []
engine = self._manager.engines.get(uid)
if engine:
for conflict in engine.dao.get_unsynchronizeds():
result.append(self._export_formatted_state(uid, state=conflict))
if engine := self._manager.engines.get(uid):
result.extend(

Check warning on line 311 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L310-L311

Added lines #L310 - L311 were not covered by tests
self._export_formatted_state(uid, state=conflict)
for conflict in engine.dao.get_unsynchronizeds()
)
Comment on lines -313 to +314
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_unsynchronizeds refactored with the following changes:

return result

@pyqtSlot(str, result=list)
def get_conflicts(self, uid: str, /) -> List[Dict[str, Any]]:
result = []
engine = self._manager.engines.get(uid)
if engine:
for conflict in engine.get_conflicts():
result.append(self._export_formatted_state(uid, state=conflict))
if engine := self._manager.engines.get(uid):
result.extend(

Check warning on line 321 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L320-L321

Added lines #L320 - L321 were not covered by tests
self._export_formatted_state(uid, state=conflict)
for conflict in engine.get_conflicts()
)
Comment on lines -322 to +324
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_conflicts refactored with the following changes:

return result

@pyqtSlot(str, result=list)
def get_errors(self, uid: str, /) -> List[Dict[str, Any]]:
result = []
engine = self._manager.engines.get(uid)
if engine:
for error in engine.dao.get_errors():
result.append(self._export_formatted_state(uid, state=error))
if engine := self._manager.engines.get(uid):
result.extend(

Check warning on line 331 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L330-L331

Added lines #L330 - L331 were not covered by tests
self._export_formatted_state(uid, state=error)
for error in engine.dao.get_errors()
)
Comment on lines -331 to +334
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_errors refactored with the following changes:

return result

@pyqtSlot(result=list)
def get_features_list(self) -> List[List[str]]:
"""Return the list of declared features with their value, title and translation key."""
result = []
for feature in vars(Feature).keys():
for feature in vars(Feature):

Check warning on line 341 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L341

Added line #L341 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_features_list refactored with the following changes:

title = feature.replace("_", " ").title()
translation_key = f"FEATURE_{feature.upper()}"
result.append([title, feature, translation_key])
Expand All @@ -350,7 +350,7 @@
return str(self._manager.generate_report())
except Exception as e:
log.exception("Report error")
return "[ERROR] " + str(e)
return f"[ERROR] {str(e)}"

Check warning on line 353 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L353

Added line #L353 was not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.generate_report refactored with the following changes:


@pyqtSlot(str, str, result=bool)
def generate_csv(self, session_id: str, engine_uid: str) -> bool:
Expand Down Expand Up @@ -383,12 +383,11 @@
def open_server_folders(self, uid: str, /) -> None:
"""Hide the systray and show the server folders dialog."""
self.application.hide_systray()
engine = self._manager.engines.get(uid)
if not engine:
if engine := self._manager.engines.get(uid):
self.application.show_server_folders(engine, None)

Check warning on line 387 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L386-L387

Added lines #L386 - L387 were not covered by tests
else:
return

self.application.show_server_folders(engine, None)
Comment on lines -386 to -390
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.open_server_folders refactored with the following changes:


@pyqtSlot(str, result=str)
def get_hostname_from_url(self, url: str, /) -> str:
urlp = urlparse(url)
Expand All @@ -397,8 +396,7 @@
@pyqtSlot(str)
def open_remote_server(self, uid: str, /) -> None:
self.application.hide_systray()
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 399 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L399

Added line #L399 was not covered by tests
Comment on lines -400 to +399
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.open_remote_server refactored with the following changes:

engine.open_remote()

@pyqtSlot(str)
Expand All @@ -415,11 +413,9 @@
filepath = Path(force_decode(path).lstrip("/"))
if not uid:
self._manager.open_local_file(filepath)
else:
engine = self._manager.engines.get(uid)
if engine:
filepath = engine.local.abspath(filepath)
self._manager.open_local_file(filepath)
elif engine := self._manager.engines.get(uid):
filepath = engine.local.abspath(filepath)
self._manager.open_local_file(filepath)

Check warning on line 418 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L416-L418

Added lines #L416 - L418 were not covered by tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.open_local refactored with the following changes:


@pyqtSlot()
def open_help(self) -> None:
Expand Down Expand Up @@ -448,8 +444,7 @@
@pyqtSlot(str)
def show_conflicts_resolution(self, uid: str, /) -> None:
self.application.hide_systray()
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 447 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L447

Added line #L447 was not covered by tests
Comment on lines -451 to +447
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.show_conflicts_resolution refactored with the following changes:

self.application.show_conflicts_resolution(engine)

@pyqtSlot(str)
Expand Down Expand Up @@ -576,7 +571,7 @@
def _balance_percents(self, result: Dict[str, float], /) -> Dict[str, float]:
"""Return an altered version of the dict in which no value is under a minimum threshold."""

result = {k: v for k, v in sorted(result.items(), key=lambda item: item[1])}
result = dict(sorted(result.items(), key=lambda item: item[1]))

Check warning on line 574 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L574

Added line #L574 was not covered by tests
Comment on lines -579 to +574
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi._balance_percents refactored with the following changes:

keys = list(result)
min_threshold = 10
data = 0.0
Expand Down Expand Up @@ -638,8 +633,7 @@

@pyqtSlot(str)
def filters_dialog(self, uid: str, /) -> None:
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 636 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L636

Added line #L636 was not covered by tests
Comment on lines -641 to +636
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.filters_dialog refactored with the following changes:

self.application.show_filters(engine)

def _bind_server(
Expand Down Expand Up @@ -873,8 +867,7 @@
self.setMessage.emit("PROXY_NO_PAC_FILE", "error")
return False

error = self._manager.set_proxy(proxy)
if error:
if error := self._manager.set_proxy(proxy):

Check warning on line 870 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L870

Added line #L870 was not covered by tests
Comment on lines -876 to +870
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.set_proxy_settings refactored with the following changes:

self.setMessage.emit(error, "error")
return False

Expand Down Expand Up @@ -1048,44 +1041,39 @@

@pyqtSlot(str, result=int)
def get_syncing_count(self, uid: str, /) -> int:
count = 0
engine = self._manager.engines.get(uid)
if engine:
count = engine.dao.get_syncing_count()
return count
return (

Check warning on line 1044 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L1044

Added line #L1044 was not covered by tests
engine.dao.get_syncing_count()
if (engine := self._manager.engines.get(uid))
else 0
)
Comment on lines -1051 to +1048
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.get_syncing_count refactored with the following changes:


# Conflicts section

@pyqtSlot(str, int)
def resolve_with_local(self, uid: str, state_id: int, /) -> None:
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 1054 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L1054

Added line #L1054 was not covered by tests
Comment on lines -1061 to +1054
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.resolve_with_local refactored with the following changes:

engine.resolve_with_local(state_id)

@pyqtSlot(str, int)
def resolve_with_remote(self, uid: str, state_id: int, /) -> None:
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 1059 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L1059

Added line #L1059 was not covered by tests
Comment on lines -1067 to +1059
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.resolve_with_remote refactored with the following changes:

engine.resolve_with_remote(state_id)

@pyqtSlot(str, int)
def retry_pair(self, uid: str, state_id: int, /) -> None:
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 1064 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L1064

Added line #L1064 was not covered by tests
Comment on lines -1073 to +1064
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.retry_pair refactored with the following changes:

engine.retry_pair(state_id)

@pyqtSlot(str, int, str)
def ignore_pair(self, uid: str, state_id: int, reason: str, /) -> None:
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 1069 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L1069

Added line #L1069 was not covered by tests
Comment on lines -1079 to +1069
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.ignore_pair refactored with the following changes:

engine.ignore_pair(state_id, reason)

@pyqtSlot(str, str, str)
def open_remote(self, uid: str, remote_ref: str, remote_name: str, /) -> None:
log.info(f"Should open {remote_name!r} ({remote_ref!r})")
try:
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 1076 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L1076

Added line #L1076 was not covered by tests
Comment on lines -1087 to +1076
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.open_remote refactored with the following changes:

engine.open_edit(remote_ref, remote_name)
except OSError:
log.exception("Remote open error")
Expand All @@ -1096,8 +1084,7 @@
) -> None:
log.info(f"Should open remote document {remote_path!r} ({remote_ref!r})")
try:
engine = self._manager.engines.get(uid)
if engine:
if engine := self._manager.engines.get(uid):

Check warning on line 1087 in nxdrive/gui/api.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/gui/api.py#L1087

Added line #L1087 was not covered by tests
Comment on lines -1099 to +1087
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QMLDriveApi.open_remote_document refactored with the following changes:

url = engine.get_metadata_url(remote_ref)
engine.open_remote(url=url)
except OSError:
Expand Down
Loading