Skip to content

Commit

Permalink
Merge branch 'master' into fix-desktop-sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
geigi committed Feb 3, 2024
2 parents 76e2d09 + 1dfba0b commit 68cfeeb
Show file tree
Hide file tree
Showing 69 changed files with 1,229 additions and 7,618 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/build.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Checks

on:
push:
branches:
- "main"
pull_request:

jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
args: --exit-zero
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Tests

on:
push:
branches:
- "main"
pull_request:

jobs:
test:
runs-on: ubuntu-latest
container:
image: ghcr.io/geigi/cozy-ci:main

steps:
- uses: actions/checkout@v4
run: |
pytest
23 changes: 15 additions & 8 deletions cozy/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from cozy.view_model.search_view_model import SearchViewModel
from cozy.view_model.settings_view_model import SettingsViewModel
from cozy.view_model.sleep_timer_view_model import SleepTimerViewModel
from cozy.view_model.storages_view_model import StoragesViewModel


class AppController(metaclass=Singleton):
Expand All @@ -51,12 +52,12 @@ def __init__(self, gtk_app, main_window_builder, main_window):

self.whats_new_window: WhatsNewWindow = WhatsNewWindow()

self.library_view: LibraryView = LibraryView(main_window_builder)
self.app_view: AppView = AppView(main_window_builder)
self.search_view: SearchView = SearchView()
self.book_detail_view: BookDetailView = BookDetailView(main_window_builder)
self.headerbar: Headerbar = Headerbar(main_window_builder)
self.library_view: LibraryView = LibraryView(main_window_builder)
self.book_detail_view: BookDetailView = BookDetailView(main_window_builder)
self.media_controller: MediaController = MediaController(main_window_builder)
self.search_view: SearchView = SearchView(main_window_builder, self.headerbar)

self.library_view_model = inject.instance(LibraryViewModel)
self.app_view_model = inject.instance(AppViewModel)
Expand All @@ -68,14 +69,14 @@ def __init__(self, gtk_app, main_window_builder, main_window):
self.settings_view_model = inject.instance(SettingsViewModel)
self.player = inject.instance(Player)

self._connect_popovers()
self._connect_search_button()

self.search_view_model.add_listener(self._on_open_view)
self.book_detail_view_model.add_listener(self._on_open_view)
self.library_view_model.add_listener(self._on_open_view)
self.library_view_model.add_listener(self._on_library_view_event)
self.playback_control_view_model.add_listener(self._on_open_view)
self.headerbar_view_model.add_listener(self._on_open_view)
self.headerbar_view_model.add_listener(self._on_working_event)
self.app_view_model.add_listener(self._on_app_view_event)

self.main_window.add_listener(self._on_main_window_event)
Expand Down Expand Up @@ -108,6 +109,7 @@ def configure_inject(self, binder):
binder.bind_to_constructor(ToastNotifier, lambda: ToastNotifier())
binder.bind_to_constructor(AppViewModel, lambda: AppViewModel())
binder.bind_to_constructor(SettingsViewModel, lambda: SettingsViewModel())
binder.bind_to_constructor(StoragesViewModel, lambda: StoragesViewModel())

def open_author(self, author: str):
self.library_view_model.library_view_mode = LibraryViewMode.AUTHOR
Expand All @@ -125,8 +127,11 @@ def open_library(self):
self.library_view_model.open_library()
self.app_view_model.view = View.LIBRARY_FILTER

def _connect_popovers(self):
self.headerbar.search_button.set_popover(self.search_view.popover)
def _connect_search_button(self):
self.headerbar.search_button.connect(
"notify::active",
self.search_view.on_state_changed
)

def _on_open_view(self, event, data):
if event == OpenView.AUTHOR:
Expand All @@ -146,10 +151,12 @@ def _on_app_view_event(self, event: str, data):
if event == "view":
self.headerbar_view_model.set_view(data)

def _on_main_window_event(self, event: str, data):
def _on_working_event(self, event: str, data) -> None:
if event == "working":
self.book_detail_view_model.lock_ui = data
self.settings_view_model.lock_ui = data

def _on_main_window_event(self, event: str, data):
if event == "open_view":
self._on_open_view(data, None)

Expand Down
12 changes: 7 additions & 5 deletions cozy/architecture/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ def remove_bind(self, prop: str, callback: Callable):
if callback in self._observers[prop]:
self._observers[prop].remove(callback)
else:
log.info("Callback not found in prop's {} observers. Skipping remove bind...".format(prop))
log.info("Callback not found in prop's %s observers. Skipping remove bind...", prop)
else:
log.info("Prop not found in observers. Skipping remove bind...")

def _notify(self, prop: str):
if prop not in self._observers:
return

try:
if prop in self._observers:
for callback in self._observers[prop]:
callback()
for callback in self._observers[prop]:
callback()
except Exception as e:
log.error(e)
reporter.exception("observable", e)

def _notify_main_thread(self, prop: str):
GLib.MainContext.default().invoke_full(GLib.PRIORITY_DEFAULT_IDLE, self._notify, (prop))
GLib.MainContext.default().invoke_full(GLib.PRIORITY_DEFAULT_IDLE, self._notify, prop)

def _destroy_observers(self):
self._observers = {}
2 changes: 1 addition & 1 deletion cozy/control/artwork_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _load_pixbuf_from_cache(self, book, size):
else:
pixbuf = None

Check failure on line 130 in cozy/control/artwork_cache.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (SIM108)

cozy/control/artwork_cache.py:127:13: SIM108 Use ternary operator `pixbuf = GdkPixbuf.Pixbuf.new_from_file(path) if path else None` instead of `if`-`else`-block
except Exception as e:
log.warning("Failed to load pixbuf from path: {}. Deleting file.".format(path))
log.warning("Failed to load pixbuf from path: %s. Deleting file.", path)
log.debug(e)
os.remove(path)
return None
Expand Down
2 changes: 1 addition & 1 deletion cozy/control/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def init_db():
_connect_db(_db)

sqlite_version = ".".join([str(num) for num in _db.server_version])
log.info("SQLite version: {}".format(sqlite_version))
log.info("SQLite version: %s", sqlite_version)

if Settings.table_exists():
update_db()
Expand Down
4 changes: 2 additions & 2 deletions cozy/control/db_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ def _update_db_9(db):
file = next((f for f in files if f.path == path), None)

if File.select().where(File.path == path).count() > 0:
log.info("Path already existing in db: {}".format(path))
log.info("Path already existing in db: %s", path)
file = File.select().where(File.path == path).get()
elif not file:
file = File(path=path, modified=track.modified, id=file_id)
files.append(file)
file_id += 1

if TrackToFile.select().join(Track).where(TrackToFile.track.id == track.id).count() > 0:
log.info("TrackToFile already existing in db: {}".format(path))
log.info("TrackToFile already existing in db: %s", path)
continue

track_to_file = TrackToFile(track=track.id, file=file, start_at=0)
Expand Down
4 changes: 2 additions & 2 deletions cozy/control/filesystem_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def is_external(self, directory: str) -> bool:
return False

if path in directory and mount.can_unmount():
log.info("Storage location {} is external".format(directory))
log.info("Storage location %s is external", directory)
return True

log.info("Storage location {} is not external".format(directory))
log.info("Storage location %s is not external", directory)
return False

def __on_mount_added(self, monitor, mount):
Expand Down
6 changes: 3 additions & 3 deletions cozy/control/mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ def on_method_call(
result = getattr(self, snake_method)(*args)
except AttributeError:
invocation.return_dbus_error(
"{}.Error.NotSupported".format(interface_name), "Unsupported property"
f"{interface_name}.Error.NotSupported", "Unsupported property"
)
except Exception as e:
log.error(e)
reporter.exception("mpris", e)
reporter.error(
"mpris",
"MPRIS method call failed with method name: {}".format(method_name),
f"MPRIS method call failed with method name: {method_name}",
)
invocation.return_dbus_error(
"{}.Error.Failed".format(interface_name), "Internal exception occurred"
f"{interface_name}.Error.Failed", "Internal exception occurred"
)
else:
# out_args is at least (signature1).
Expand Down
15 changes: 2 additions & 13 deletions cozy/extensions/set.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import re
from typing import Set


def split_strings_to_set(set_to_split: Set[str]):
finished = set()
for entry in set_to_split:
results = re.split(",|;|/|&", entry)
results = {
entry.strip()
for entry in results
}

finished.update(results)

return finished
def split_strings_to_set(set_to_split: set[str]) -> set[str]:
return {entry.strip() for item in set_to_split for entry in re.split(",|;|/|&", item)}
4 changes: 2 additions & 2 deletions cozy/media/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _copy_all(self, sources, destination: str):
self._copy_file(path, file_copy_destination)

def _copy_file(self, source_path: str, dest_path: str):
log.info("Copy file {} to {}".format(source_path, dest_path))
log.info("Copy file %s to %s", source_path, dest_path)

source = Gio.File.new_for_path(source_path)
destination = Gio.File.new_for_path(dest_path)
Expand All @@ -72,7 +72,7 @@ def _copy_file(self, source_path: str, dest_path: str):
else:
reporter.exception("files", e)

log.error("Failed to copy file: {}".format(e))
log.error("Failed to copy file: %s", e)
self._file_progess += 1

def _copy_directory(self, path, destination):
Expand Down
6 changes: 3 additions & 3 deletions cozy/media/gst_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def state(self) -> GstPlayerState:
elif state == Gst.State.PAUSED:
return GstPlayerState.PAUSED
else:
log.debug("GST player state was not playing or paused but {}.".format(state))
log.debug("GST player state was not playing or paused but %s", state)
return GstPlayerState.STOPPED

@property
Expand Down Expand Up @@ -268,7 +268,7 @@ def _on_gst_message(self, _, message: Gst.Message):
reporter.warning("gst_player", "gst: Resource not found. Stopping player.")
return

reporter.error("player", "{}: {}".format(error.code, error))
log.error("{}: {}".format(error.code, error))
reporter.error("player", f"{error.code}: {error}")
log.error("%s: %s", error.code, error)
log.debug(debug_msg)
self.emit_event("error", error)
2 changes: 1 addition & 1 deletion cozy/media/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _filter_unchanged_files(self, files: List[str]) -> List[str]:
yield file
except Exception as e:
log.debug(e)
log.info("Could not get modified timestamp for file {}".format(file))
log.info("Could not get modified timestamp for file %s", file)
continue

continue
Expand Down
2 changes: 1 addition & 1 deletion cozy/media/media_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_media_data(self) -> MediaFile:
try:
discoverer_info: GstPbutils.DiscovererInfo = self.discoverer.discover_uri(self.uri)
except Exception as e:
log.info("Skipping file because it couldn't be detected: {}".format(self.uri))
log.info("Skipping file because it couldn't be detected: %s", self.uri)
raise AudioFileCouldNotBeDiscovered(self.uri)

is_valid_audio_file = self._is_valid_audio_file(discoverer_info)
Expand Down
2 changes: 1 addition & 1 deletion cozy/media/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def _emit_tick(self):
position_for_ui = self.position - self.loaded_chapter.start_position
self.emit_event_main_thread("position", position_for_ui)
except Exception as e:
log.warning("Could not emit position event: {}".format(e))
log.warning("Could not emit position event: %s", e)

def _fadeout_playback(self):
duration = self._app_settings.sleep_timer_fadeout_duration * 20
Expand Down
2 changes: 1 addition & 1 deletion cozy/model/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _fetch_chapters(self):
except TrackInconsistentData:
log.warning("Skipping inconsistent model")
except Exception as e:
log.error("Could not create chapter object: {}".format(e))
log.error("Could not create chapter object: %s", e)

for chapter in self._chapters:
chapter.add_listener(self._on_chapter_event)
Expand Down
2 changes: 1 addition & 1 deletion cozy/model/database_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _prepare_track_db_objects(self, media_files: Set[MediaFile]) -> Set[TrackIns
book = next((book for book in book_db_objects if is_same_book(book.name, media_file.book_name)), None)
file_query = File.select().where(File.path == media_file.path)
if not file_query.exists():
log.error("No file object with path present: {}".format(media_file.path))
log.error("No file object with path present: %s", media_file.path)
continue

file = file_query.get()
Expand Down
4 changes: 1 addition & 3 deletions cozy/model/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ def rebase_path(self, old_path: str, new_path: str):
self.emit_event_main_thread("rebase-started")

chapter_count = len(self.chapters)
progress = 0
for chapter in self.chapters:
for progress, chapter in enumerate(self.chapters, 1):
if chapter.file.startswith(old_path):
progress += 1
chapter.file = chapter.file.replace(old_path, new_path)
self.emit_event_main_thread("rebase-progress", progress / chapter_count)

Expand Down
Loading

0 comments on commit 68cfeeb

Please sign in to comment.