From e35d849644c5bf68952a102af299f22386f7e7cc Mon Sep 17 00:00:00 2001 From: Tucker Kern Date: Sun, 12 Nov 2023 17:51:44 -0700 Subject: [PATCH] Reorganize proxy to be packagable for install via pipx --- .gitignore | 4 +++ Makefile | 9 +++-- librespot-mpris-proxy.service | 4 +-- ...mpris-proxy.py => librespot_mpris_proxy.py | 30 +++++++++------- pyproject.toml | 36 +++++++++++++++++++ 5 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 .gitignore rename librespot-mpris-proxy.py => librespot_mpris_proxy.py (95%) create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..812ecdf --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.venv/ +build/ +dist/ +*.egg-info/ \ No newline at end of file diff --git a/Makefile b/Makefile index f5cb3b4..0db9a22 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,11 @@ install-systemd: $(SYSTEMD_SERVICE_NAME) systemctl enable $(SYSTEMD_SERVICE_NAME) systemctl start $(SYSTEMD_SERVICE_NAME) -install-bin: $(TARGET_NAME).py $(ONEVENT_NAME).py +install-bin: $(ONEVENT_NAME).py @$(MKDIR_P) $(DESTDIR)$(PREFIX)/bin - cp $< $(DESTDIR)$(PREFIX)/bin/${TARGET_NAME} - chmod +x $(DESTDIR)$(PREFIX)/bin/${TARGET_NAME} cp $< $(DESTDIR)$(PREFIX)/bin/${ONEVENT_NAME} chmod +x $(DESTDIR)$(PREFIX)/bin/${ONEVENT_NAME} + pipx install . install-policy: $(SYSTEMD_POLICY_NAME) cp $< $(SYSTEMD_POLICY_PATH)/ @@ -38,6 +37,6 @@ uninstall-systemd: rm -f $(SYSTEMD_SERVICE_PATH)/$(SYSTEMD_SERVICE_NAME) uninstall: uninstall-systemd - rm -f $(DESTDIR)$(PREFIX)/bin/${TARGET_NAME} rm -f $(DESTDIR)$(PREFIX)/bin/${ONEVENT_NAME} - rm -f $(SYSTEMD_POLICY_PATH)/$(SYSTEMD_POLICY_NAME) \ No newline at end of file + rm -f $(SYSTEMD_POLICY_PATH)/$(SYSTEMD_POLICY_NAME) + pipx uninstall $(TARGET_NAME) \ No newline at end of file diff --git a/librespot-mpris-proxy.service b/librespot-mpris-proxy.service index c949652..7c35fc0 100644 --- a/librespot-mpris-proxy.service +++ b/librespot-mpris-proxy.service @@ -4,10 +4,10 @@ After=dbus.service network-online.target Wants=dbus.service network-online.target [Service] -ExecStart=/usr/local/bin/librespot-mpris-proxy +ExecStart=/home/pi/.local/bin/librespot-mpris-proxy StandardOutput=journal StandardError=journal -SyslogIdentifier=librespot-mpris-monitor +SyslogIdentifier=librespot-mpris-proxy [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/librespot-mpris-proxy.py b/librespot_mpris_proxy.py similarity index 95% rename from librespot-mpris-proxy.py rename to librespot_mpris_proxy.py index a9a82ea..fa46ad3 100755 --- a/librespot-mpris-proxy.py +++ b/librespot_mpris_proxy.py @@ -1,13 +1,13 @@ -#! /bin/env python3 +#!/usr/bin/env python3 -from dbus_next.aio import MessageBus -from dbus_next.service import ServiceInterface, dbus_property -from dbus_next import BusType, PropertyAccess - -import os -import stat import asyncio +import os import re +import stat + +from dbus_next import BusType, PropertyAccess +from dbus_next.aio import MessageBus +from dbus_next.service import ServiceInterface, dbus_property class MediaPlayer2Interface(ServiceInterface): @@ -83,7 +83,7 @@ def can_seek(self) -> "b": return False -async def main(): +async def _run(): # Connect to the system bus print("Connecting to system bus.") bus = await MessageBus(bus_type=BusType.SYSTEM).connect() @@ -131,7 +131,13 @@ async def main(): # TODO might want to re-eval aiofiles await asyncio.sleep(1) -try: - asyncio.run(main()) -except KeyboardInterrupt: - pass + +def main(): + try: + asyncio.run(_run()) + except KeyboardInterrupt: + pass + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..330a3e5 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,36 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "librespot-mpris-proxy" +description = "Proxy events from librespot events to MPRIS D-Bus signals." +version = "1.0.0" +readme = "README.md" +authors = [ + {name = "Tucker Kern", email = "tuckkern@gmail.com"}, +] +requires-python = ">=3.8" +license = {text = "MIT"} +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent" +] +dependencies = [ + "dbus-next" +] + +[project.urls] +Repository = "https://github.com/mill1000/librespot-mpris-proxy" +Issues = "https://github.com/mill1000/librespot-mpris-proxy/issues" + +[project.scripts] +librespot-mpris-proxy = "librespot_mpris_proxy:main" + +[tool.setuptools] +py-modules = ["librespot_mpris_proxy"]