-
Notifications
You must be signed in to change notification settings - Fork 53
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)] | ||
else: | ||
return [] | ||
return [s.export() for s in engine.dao.get_last_files(number)] | ||
|
||
@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 ( | ||
engine.dao.get_last_files_count(duration=60) | ||
if (engine := self._manager.engines.get(uid)) | ||
else 0 | ||
) | ||
Comment on lines
-130
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@pyqtSlot(QUrl, result=str) | ||
def to_local_file(self, url: QUrl, /) -> str: | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return engine.dao.get_count( | ||
f"status IN ({TransferStatus.ONGOING.value}, {TransferStatus.PAUSED.value})", | ||
table="Sessions", | ||
|
@@ -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): | ||
Comment on lines
-231
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return engine.dao.get_count( | ||
f"status IN ({TransferStatus.CANCELLED.value}, {TransferStatus.DONE.value})", | ||
table="Sessions", | ||
|
@@ -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( | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@pyqtSlot(str, str, int, bool) | ||
def resume_transfer( | ||
|
@@ -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) | ||
else: | ||
return | ||
engine.resume_transfer(nature, uid, is_direct_transfer=is_direct_transfer) | ||
Comment on lines
-271
to
-274
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@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) | ||
else: | ||
return | ||
engine.resume_session(uid) | ||
Comment on lines
-280
to
-283
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@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) | ||
else: | ||
return | ||
engine.dao.pause_session(uid) | ||
Comment on lines
-289
to
-292
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
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) | ||
else: | ||
return | ||
engine.cancel_session(uid) | ||
Comment on lines
-297
to
-300
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@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): | ||
Comment on lines
-305
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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( | ||
self._export_formatted_state(uid, state=conflict) | ||
for conflict in engine.dao.get_unsynchronizeds() | ||
) | ||
Comment on lines
-313
to
+314
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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( | ||
self._export_formatted_state(uid, state=conflict) | ||
for conflict in engine.get_conflicts() | ||
) | ||
Comment on lines
-322
to
+324
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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( | ||
self._export_formatted_state(uid, state=error) | ||
for error in engine.dao.get_errors() | ||
) | ||
Comment on lines
-331
to
+334
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
title = feature.replace("_", " ").title() | ||
translation_key = f"FEATURE_{feature.upper()}" | ||
result.append([title, feature, translation_key]) | ||
|
@@ -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)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@pyqtSlot(str, str, result=bool) | ||
def generate_csv(self, session_id: str, engine_uid: str) -> bool: | ||
|
@@ -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) | ||
else: | ||
return | ||
|
||
self.application.show_server_folders(engine, None) | ||
Comment on lines
-386
to
-390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@pyqtSlot(str, result=str) | ||
def get_hostname_from_url(self, url: str, /) -> str: | ||
urlp = urlparse(url) | ||
|
@@ -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): | ||
Comment on lines
-400
to
+399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
engine.open_remote() | ||
|
||
@pyqtSlot(str) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@pyqtSlot() | ||
def open_help(self) -> None: | ||
|
@@ -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): | ||
Comment on lines
-451
to
+447
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.application.show_conflicts_resolution(engine) | ||
|
||
@pyqtSlot(str) | ||
|
@@ -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])) | ||
Comment on lines
-579
to
+574
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
keys = list(result) | ||
min_threshold = 10 | ||
data = 0.0 | ||
|
@@ -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): | ||
Comment on lines
-641
to
+636
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.application.show_filters(engine) | ||
|
||
def _bind_server( | ||
|
@@ -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): | ||
Comment on lines
-876
to
+870
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.setMessage.emit(error, "error") | ||
return False | ||
|
||
|
@@ -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 ( | ||
engine.dao.get_syncing_count() | ||
if (engine := self._manager.engines.get(uid)) | ||
else 0 | ||
) | ||
Comment on lines
-1051
to
+1048
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
# 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): | ||
Comment on lines
-1061
to
+1054
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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): | ||
Comment on lines
-1067
to
+1059
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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): | ||
Comment on lines
-1073
to
+1064
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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): | ||
Comment on lines
-1079
to
+1069
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
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): | ||
Comment on lines
-1087
to
+1076
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
engine.open_edit(remote_ref, remote_name) | ||
except OSError: | ||
log.exception("Remote open error") | ||
|
@@ -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): | ||
Comment on lines
-1099
to
+1087
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
url = engine.get_metadata_url(remote_ref) | ||
engine.open_remote(url=url) | ||
except OSError: | ||
|
There was a problem hiding this comment.
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:use-named-expression
)reintroduce-else
)swap-if-else-branches
)