Skip to content

Commit

Permalink
Reorganize proxy to be packagable for install via pipx
Browse files Browse the repository at this point in the history
  • Loading branch information
mill1000 committed Nov 13, 2023
1 parent be18f6a commit e35d849
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv/
build/
dist/
*.egg-info/
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)/
Expand All @@ -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)
rm -f $(SYSTEMD_POLICY_PATH)/$(SYSTEMD_POLICY_NAME)
pipx uninstall $(TARGET_NAME)
4 changes: 2 additions & 2 deletions librespot-mpris-proxy.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 18 additions & 12 deletions librespot-mpris-proxy.py → librespot_mpris_proxy.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"},
]
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"]

0 comments on commit e35d849

Please sign in to comment.