From e516a65b682ccbcd61c965b36f9ce740f63f130f Mon Sep 17 00:00:00 2001 From: "P.M. Kuipers" Date: Sat, 2 Apr 2022 15:15:35 +0200 Subject: [PATCH] Python3 switch and systemd boot --- debian/postinst | 2 +- debian/prerm | 2 +- lib/systemd/system/mediaserver.service | 12 ++++++++++++ mediaserver/VERSION.py | 7 ------- mediaserver/dbus_smartobject.py | 14 +++++++------- sbin/mediaserver | 2 +- setup.py | 10 ++++------ 7 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 lib/systemd/system/mediaserver.service delete mode 100755 mediaserver/VERSION.py mode change 100644 => 100755 sbin/mediaserver diff --git a/debian/postinst b/debian/postinst index 1f861a5..92731d8 100755 --- a/debian/postinst +++ b/debian/postinst @@ -20,7 +20,7 @@ set -e case "$1" in configure) - update-rc.d mediaserver defaults + systemctl enable mediaserver.service ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/debian/prerm b/debian/prerm index 73f3269..5be99a1 100755 --- a/debian/prerm +++ b/debian/prerm @@ -19,7 +19,7 @@ set -e case "$1" in remove|upgrade|deconfigure) - update-rc.d -f mediaserver remove + systemctl disable mediaserver.service ;; failed-upgrade) diff --git a/lib/systemd/system/mediaserver.service b/lib/systemd/system/mediaserver.service new file mode 100644 index 0000000..b1cb78d --- /dev/null +++ b/lib/systemd/system/mediaserver.service @@ -0,0 +1,12 @@ +[Unit] +Description=Start Mediaserver + +[Service] +ExecStart=/usr/bin/startx /usr/sbin/mediaserver +Restart=always +RestartSec=10s +KillMode=process +TimeoutSec=infinity + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/mediaserver/VERSION.py b/mediaserver/VERSION.py deleted file mode 100755 index e01d32f..0000000 --- a/mediaserver/VERSION.py +++ /dev/null @@ -1,7 +0,0 @@ - -major=4 # Major version -minor=0 # Minor version -micro=0 # Bugfix version - -# code to generate version string from above data -version_string = "{0}.{1}.{2}".format(major,minor,micro) diff --git a/mediaserver/dbus_smartobject.py b/mediaserver/dbus_smartobject.py index 9064f06..ce38d78 100755 --- a/mediaserver/dbus_smartobject.py +++ b/mediaserver/dbus_smartobject.py @@ -1,7 +1,7 @@ import dbus import dbus.service import dbus.mainloop.glib -import event +from . import event class NoConnectionError(Exception): pass @@ -70,7 +70,7 @@ class DBusSmartObject: def _initialize_new_connection(self): # test if service is available on the selected bus. Skip otherwise if self._dbus_object.NameHasOwner(self._service, dbus_interface=self._dbus_interface): - print "Initializing new connection to {0}".format(self._service) + print("Initializing new connection to {0}".format(self._service)) self._bus = dbus.Bus(self._bus_type) self.busobject = self._bus.get_object(self._service, self._object_path) @@ -82,7 +82,7 @@ class DBusSmartObject: else: self._beenconnected = True else: - print "Could not create connection to {0}".format(self._service) + print("Could not create connection to {0}".format(self._service)) # bus object is not available - so disconnect the bus if self._bus is not None: @@ -91,7 +91,7 @@ class DBusSmartObject: def _close_existing_connection(self): if self._bus is not None: - print "Lost connection to {0}".format(self._service) + print("Lost connection to {0}".format(self._service)) #self._bus.close() self._bus = None self.busobject = None @@ -109,7 +109,7 @@ class DBusSmartObject: self._initialize_new_connection() def call(self,method, *args, **kwargs): - if kwargs.has_key("interface"): + if "interface" in kwargs: interface = kwargs["interface"] else: interface = self._interface @@ -132,8 +132,8 @@ class DBusSmartObject: default = None try: return self.call(method, *args, **kwargs) - except NoConnectionError as x: - print "Could not call {0} because there is currently no connection to {1}".format(method,self._service) + except NoConnectionError: + print("Could not call {0} because there is currently no connection to {1}".format(method,self._service)) return default def connected(self): diff --git a/sbin/mediaserver b/sbin/mediaserver old mode 100644 new mode 100755 index 188a82e..2b047f6 --- a/sbin/mediaserver +++ b/sbin/mediaserver @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import mediaserver.mediaserver mediaserver.mediaserver.Run() \ No newline at end of file diff --git a/setup.py b/setup.py index fdc2e01..5f9fe86 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 '''KHMedia applications. Includes scheduled recorder, music player, sound level meter and a webcam viewer @@ -7,7 +7,6 @@ Includes scheduled recorder, music player, sound level meter and a webcam viewer from distutils.core import setup from distutils.extension import Extension from glob import glob -from mediaserver import VERSION # patch distutils if it's too old to cope with the "classifiers" or # "download_url" keywords @@ -20,7 +19,7 @@ if version < '2.2.3': if __name__ == '__main__': setup( name = 'mediaserver', - version = VERSION.version_string, + version = "4.0.5", description = 'Mediacore mediaserver', long_description = __doc__, author = 'Miqra Engineering', @@ -39,13 +38,12 @@ if __name__ == '__main__': 'Topic :: Multimedia :: Sound/Audio :: Players', ], packages=['mediaserver'], - package_data={'mediaserver': ['image/*', ]}, + package_data={'mediaserver': ['images/*', ]}, data_files = [ - # note that some files are forced to /usr/share/... instead of just share/.. - # this is because the system does not look in /usr/local/share/... for those files, but only in /usr/share/... ('/usr/share/mediaserver', glob('usr-share-mediaserver/*')), ('/etc/dbus-1/system.d', glob('etc/dbus-1/system.d/*')), ('/etc/init.d', glob('etc/init.d/*')), + ('/lib/systemd/system', glob('lib/systemd/system/*')), ('bin', glob('bin/*')), ('sbin', glob('sbin/*')), ],