From 6183fdb1522ddf4b515a7f108adfe30c036cfea4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Braun Date: Sat, 27 Oct 2012 03:40:52 +0200 Subject: [PATCH 1/9] Rename to python-systemd-dbus to avoid conflicts --- README | 12 +++---- TODO | 2 +- setup.py | 12 +++---- {systemd => systemd_dbus}/__init__.py | 0 {systemd => systemd_dbus}/automount.py | 10 +++--- {systemd => systemd_dbus}/device.py | 10 +++--- {systemd => systemd_dbus}/exceptions.py | 6 ++-- {systemd => systemd_dbus}/job.py | 10 +++--- {systemd => systemd_dbus}/manager.py | 44 ++++++++++++------------- {systemd => systemd_dbus}/mount.py | 10 +++--- {systemd => systemd_dbus}/path.py | 10 +++--- {systemd => systemd_dbus}/property.py | 6 ++-- {systemd => systemd_dbus}/service.py | 10 +++--- {systemd => systemd_dbus}/snapshot.py | 10 +++--- {systemd => systemd_dbus}/socket.py | 10 +++--- {systemd => systemd_dbus}/swap.py | 10 +++--- {systemd => systemd_dbus}/target.py | 10 +++--- {systemd => systemd_dbus}/timer.py | 10 +++--- {systemd => systemd_dbus}/unit.py | 28 ++++++++-------- 19 files changed, 110 insertions(+), 110 deletions(-) rename {systemd => systemd_dbus}/__init__.py (100%) rename {systemd => systemd_dbus}/automount.py (85%) rename {systemd => systemd_dbus}/device.py (85%) rename {systemd => systemd_dbus}/exceptions.py (81%) rename {systemd => systemd_dbus}/job.py (86%) rename {systemd => systemd_dbus}/manager.py (92%) rename {systemd => systemd_dbus}/mount.py (85%) rename {systemd => systemd_dbus}/path.py (85%) rename {systemd => systemd_dbus}/property.py (75%) rename {systemd => systemd_dbus}/service.py (85%) rename {systemd => systemd_dbus}/snapshot.py (86%) rename {systemd => systemd_dbus}/socket.py (85%) rename {systemd => systemd_dbus}/swap.py (85%) rename {systemd => systemd_dbus}/target.py (78%) rename {systemd => systemd_dbus}/timer.py (85%) rename {systemd => systemd_dbus}/unit.py (89%) diff --git a/README b/README index 6e5c937..dde8c10 100644 --- a/README +++ b/README @@ -1,8 +1,8 @@ ============== -python-systemd +python-systemd-dbus ============== -python-systemd python wrapper for `systemd`_ system and session manager dbus +python-systemd-dbus python wrapper for `systemd`_ system and session manager dbus interfaces. .. systemd: http://www.freedesktop.org/wiki/Software/systemd @@ -10,7 +10,7 @@ interfaces. Basic usage =========== ->>> from systemd.manager import Manager +>>> from systemd_dbus.manager import Manager >>> manager = Manager() # List all units @@ -36,7 +36,7 @@ loaded active running # Let's stop crond >>> unit.stop('fail') - + # is crond running? why I stop it!! >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState @@ -54,7 +54,7 @@ loaded inactive dead # Let's start crond >>> unit.start('fail') - + # Remember we want o loop! >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState @@ -67,4 +67,4 @@ KeyboardInterrupt # Updated! >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState -loaded active running \ No newline at end of file +loaded active running diff --git a/TODO b/TODO index 16b7f2a..c465462 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,7 @@ TODO ==== -This is todo file for python-systemd. +This is todo file for python-systemd-dbus. CODE ==== diff --git a/setup.py b/setup.py index 1e02d28..a417d83 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from distutils.core import setup import os -from systemd import get_version +from systemd_dbus import get_version # Compile the list of packages available, because distutils doesn't have @@ -11,7 +11,7 @@ if root_dir: os.chdir(root_dir) -for dirpath, dirnames, filenames in os.walk('systemd'): +for dirpath, dirnames, filenames in os.walk('systemd_dbus'): # Ignore dirnames that start with '.' for i, dirname in enumerate(dirnames): if dirname.startswith('.'): del dirnames[i] @@ -26,20 +26,20 @@ data_files.append(os.path.join(prefix, f)) -setup(name='python-systemd', +setup(name='python-systemd-dbus-dbus', version=get_version().replace(' ', '-'), description='Systemd interfaces wrapper', author='Wiliam Souza', author_email='wiliam@mandriva.com', url='', download_url='', - package_dir={'systemd': 'systemd'}, + package_dir={'systemd_dbus': 'systemd_dbus'}, packages=packages, - package_data={'systemd': data_files}, + package_data={'systemd_dbus': data_files}, classifiers=['Development Status :: 1 - Planning', 'Intended Audience :: Developers', 'License :: ', - 'Operating System :: POSIX :: Linux', + 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', 'Topic :: Libraries :: Python Modules',] ) diff --git a/systemd/__init__.py b/systemd_dbus/__init__.py similarity index 100% rename from systemd/__init__.py rename to systemd_dbus/__init__.py diff --git a/systemd/automount.py b/systemd_dbus/automount.py similarity index 85% rename from systemd/automount.py rename to systemd_dbus/automount.py index ffb446c..8f89256 100644 --- a/systemd/automount.py +++ b/systemd_dbus/automount.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Automount(object): """Abstraction class to org.freedesktop.systemd1.Automount interface""" diff --git a/systemd/device.py b/systemd_dbus/device.py similarity index 85% rename from systemd/device.py rename to systemd_dbus/device.py index fa1eb3c..97762c5 100644 --- a/systemd/device.py +++ b/systemd_dbus/device.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Device(object): """Abstraction class to org.freedesktop.systemd1.Device interface""" diff --git a/systemd/exceptions.py b/systemd_dbus/exceptions.py similarity index 81% rename from systemd/exceptions.py rename to systemd_dbus/exceptions.py index ea9febb..0aec30c 100644 --- a/systemd/exceptions.py +++ b/systemd_dbus/exceptions.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. diff --git a/systemd/job.py b/systemd_dbus/job.py similarity index 86% rename from systemd/job.py rename to systemd_dbus/job.py index 3d1ae18..970e15b 100644 --- a/systemd/job.py +++ b/systemd_dbus/job.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Job(object): """Abstraction class to org.freedesktop.systemd1.Job interface""" diff --git a/systemd/manager.py b/systemd_dbus/manager.py similarity index 92% rename from systemd/manager.py rename to systemd_dbus/manager.py index 1fe1d32..8eae9a2 100644 --- a/systemd/manager.py +++ b/systemd_dbus/manager.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,10 +21,10 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.unit import Unit -from systemd.job import Job -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.unit import Unit +from systemd_dbus.job import Job +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Manager(object): """Abstraction class to org.freedesktop.systemd1.Manager interface""" @@ -93,7 +93,7 @@ def get_job(self, ID): @raise SystemdError: Raised when no job is found with the given ID. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: job_path = self.__interface.GetJob(ID) @@ -109,7 +109,7 @@ def get_unit(self, name): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: systemd.unit.Unit + @rtype: systemd_dbus.unit.Unit """ try: unit_path = self.__interface.GetUnit(name) @@ -125,7 +125,7 @@ def get_unit_by_pid(self, pid): @raise SystemdError: Raised when no unit with that PID is found. - @rtype: systemd.unit.Unit + @rtype: systemd_dbus.unit.Unit """ try: unit_path = self.__interface.GetUnitByPID(pid) @@ -157,7 +157,7 @@ def kill_unit(self, name, who, mode, signal): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: self.__interface.KillUnit(name, who, mode, signal) @@ -171,7 +171,7 @@ def list_jobs(self): @raise SystemdError, IndexError: Raised when dbus error or index error is raised. - @rtype: A tuple of L{systemd.unit.Job} + @rtype: A tuple of L{systemd_dbus.unit.Job} """ try: jobs = [] @@ -187,7 +187,7 @@ def list_units(self): @raise SystemdError: Raised when dbus error or index error is raised. - @rtype: A tuple of L{systemd.unit.Unit} + @rtype: A tuple of L{systemd_dbus.unit.Unit} """ try: units = [] @@ -204,7 +204,7 @@ def load_unit(self, name): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.unit.Unit} + @rtype: L{systemd_dbus.unit.Unit} """ try: unit_path = self.__interface.LoadUnit(name) @@ -245,7 +245,7 @@ def reload_or_restart_unit(self, name, mode): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.ReloadOrRestartUnit(name, mode) @@ -262,7 +262,7 @@ def reload_or_try_restart_unit(self, name, mode): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.ReloadOrTryRestartUnit(name, mode) @@ -280,7 +280,7 @@ def reload_unit(self, name, mode): @raise SystemdError: Raised when no unit is found with the given name or mode is not corret. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.ReloadUnit(name, mode) @@ -309,7 +309,7 @@ def restart_unit(self, name, mode): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.RestartUnit(name, mode) @@ -332,7 +332,7 @@ def start_unit(self, name, mode): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.StartUnit(name, mode) @@ -350,7 +350,7 @@ def start_unit_replace(self, old_unit, new_unit, mode): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.StartUnitReplace(old_unit, new_unit, mode) @@ -367,7 +367,7 @@ def stop_unit(self, name, mode): @raise SystemdError: Raised when no unit is found with the given name. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.StopUnit(name, mode) @@ -392,7 +392,7 @@ def try_restart_unit(self, name, mode): @raise SystemdError: Raised when no unit is found with the given name or mode is invalid. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.TryRestartUnit(name, mode) diff --git a/systemd/mount.py b/systemd_dbus/mount.py similarity index 85% rename from systemd/mount.py rename to systemd_dbus/mount.py index 070443b..26a0119 100644 --- a/systemd/mount.py +++ b/systemd_dbus/mount.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Mount(object): """Abstraction class to org.freedesktop.systemd1.Mount interface""" diff --git a/systemd/path.py b/systemd_dbus/path.py similarity index 85% rename from systemd/path.py rename to systemd_dbus/path.py index e28ab32..b68fdba 100644 --- a/systemd/path.py +++ b/systemd_dbus/path.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Path(object): """Abstraction class to org.freedesktop.systemd1.Path interface""" diff --git a/systemd/property.py b/systemd_dbus/property.py similarity index 75% rename from systemd/property.py rename to systemd_dbus/property.py index f2b2db3..6d91e2c 100644 --- a/systemd/property.py +++ b/systemd_dbus/property.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. diff --git a/systemd/service.py b/systemd_dbus/service.py similarity index 85% rename from systemd/service.py rename to systemd_dbus/service.py index e7d8610..73f06ad 100644 --- a/systemd/service.py +++ b/systemd_dbus/service.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Service(object): """Abstraction class to org.freedesktop.systemd1.Service interface""" diff --git a/systemd/snapshot.py b/systemd_dbus/snapshot.py similarity index 86% rename from systemd/snapshot.py rename to systemd_dbus/snapshot.py index 66ed8b2..01ec8bb 100644 --- a/systemd/snapshot.py +++ b/systemd_dbus/snapshot.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Snapshot(object): """Abstraction class to org.freedesktop.systemd1.Snapshot interface""" diff --git a/systemd/socket.py b/systemd_dbus/socket.py similarity index 85% rename from systemd/socket.py rename to systemd_dbus/socket.py index 7f10d65..d87b78f 100644 --- a/systemd/socket.py +++ b/systemd_dbus/socket.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Socket(object): """Abstraction class to org.freedesktop.systemd1.Socket interface""" diff --git a/systemd/swap.py b/systemd_dbus/swap.py similarity index 85% rename from systemd/swap.py rename to systemd_dbus/swap.py index de133c5..a441d85 100644 --- a/systemd/swap.py +++ b/systemd_dbus/swap.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Swap(object): """Abstraction class to org.freedesktop.systemd1.Swap interface""" diff --git a/systemd/target.py b/systemd_dbus/target.py similarity index 78% rename from systemd/target.py rename to systemd_dbus/target.py index bd2f87d..1bfe59a 100644 --- a/systemd/target.py +++ b/systemd_dbus/target.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Target(object): """Abstraction class to org.freedesktop.systemd1.Target interface""" diff --git a/systemd/timer.py b/systemd_dbus/timer.py similarity index 85% rename from systemd/timer.py rename to systemd_dbus/timer.py index 0c344ed..5c75cbd 100644 --- a/systemd/timer.py +++ b/systemd_dbus/timer.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,8 +21,8 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError class Timer(object): """Abstraction class to org.freedesktop.systemd1.Timer interface""" diff --git a/systemd/unit.py b/systemd_dbus/unit.py similarity index 89% rename from systemd/unit.py rename to systemd_dbus/unit.py index 8bfbe02..6248b2f 100644 --- a/systemd/unit.py +++ b/systemd_dbus/unit.py @@ -1,14 +1,14 @@ # # Copyright (c) 2010 Mandriva # -# This file is part of python-systemd. +# This file is part of python-systemd-dbus. # -# python-systemd is free software; you can redistribute it and/or modify +# python-systemd-dbus is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of # the License, or (at your option) any later version. # -# python-systemd is distributed in the hope that it will be useful, +# python-systemd-dbus is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. @@ -21,9 +21,9 @@ import dbus.mainloop.glib dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) -from systemd.property import Property -from systemd.exceptions import SystemdError -from systemd.job import Job +from systemd_dbus.property import Property +from systemd_dbus.exceptions import SystemdError +from systemd_dbus.job import Job class Unit(object): """Abstraction class to org.freedesktop.systemd1.Unit interface""" @@ -69,7 +69,7 @@ def kill(self, who, mode, signal): @raise SystemdError: Raised when who, mode or signal are invalid. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: self.__interface.KillUnit(who, mode, signal) @@ -84,7 +84,7 @@ def reload(self, mode): @raise SystemdError: Raised when mode is invalid. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: job_path = self.__interface.Reload(mode) @@ -102,7 +102,7 @@ def reload_or_restart(self, mode): @raise SystemdError: Raised when mode is invalid. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: job_path = self.__interface.ReloadOrRestart(mode) @@ -118,7 +118,7 @@ def reload_or_try_restart(self, mode): @raise SystemdError: Raised when mode is invalid. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: job_path = self.__interface.ReloadOrTryRestart(mode) @@ -140,7 +140,7 @@ def restart(self, mode): @raise SystemdError: Raised when mode is invalid. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: job_path = self.__interface.Restart(mode) @@ -156,7 +156,7 @@ def start(self, mode): @raise SystemdError: Raised when mode is invalid. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: job_path = self.__interface.Start(mode) @@ -172,7 +172,7 @@ def stop(self, mode): @raise SystemdError: Raised when mode is invalid. - @rtype: systemd.job.Job + @rtype: systemd_dbus.job.Job """ try: job_path = self.__interface.Stop(mode) @@ -188,7 +188,7 @@ def try_restart(self,mode): @raise SystemdError: Raised when mode is invalid. - @rtype: L{systemd.job.Job} + @rtype: L{systemd_dbus.job.Job} """ try: job_path = self.__interface.TryRestart(mode) From 75a9d4fa199dfde4825f8a59a08fe789c9d04d6d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Braun Date: Wed, 31 Oct 2012 14:44:32 +0100 Subject: [PATCH 2/9] Fix packaging --- setup.py | 2 +- systemd_dbus/__init__.py | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index a417d83..81c0da0 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ data_files.append(os.path.join(prefix, f)) -setup(name='python-systemd-dbus-dbus', +setup(name='python-systemd-dbus', version=get_version().replace(' ', '-'), description='Systemd interfaces wrapper', author='Wiliam Souza', diff --git a/systemd_dbus/__init__.py b/systemd_dbus/__init__.py index 6d8f7ae..bc6ae04 100644 --- a/systemd_dbus/__init__.py +++ b/systemd_dbus/__init__.py @@ -1,12 +1,5 @@ -VERSION = (0, 1, 0, 'planning', 0) +VERSION = (0, 1) def get_version(): version = '%s.%s' % (VERSION[0], VERSION[1]) - if VERSION[2]: - version = '%s.%s' % (version, VERSION[2]) - if VERSION[3:] == ('alpha', 0): - version = '%s pre-alpha' % version - else: - if VERSION[3] != 'final': - version = '%s %s %s' % (version, VERSION[3], VERSION[4]) return version From 992373923adfc517a446a516abc35859eb486b2d Mon Sep 17 00:00:00 2001 From: Vyronas Tsingaras Date: Thu, 26 May 2016 12:22:19 +0300 Subject: [PATCH 3/9] Add property for dbus unit path and add get_service* Manager helper methods --- systemd/manager.py | 37 +++++++++++++++++++++++++++++++++++-- systemd/unit.py | 9 ++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/systemd/manager.py b/systemd/manager.py index 1fe1d32..523961f 100644 --- a/systemd/manager.py +++ b/systemd/manager.py @@ -22,6 +22,7 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) from systemd.unit import Unit +from systemd.service import Service from systemd.job import Job from systemd.property import Property from systemd.exceptions import SystemdError @@ -103,7 +104,7 @@ def get_job(self, ID): raise SystemdError(error) def get_unit(self, name): - """Get unit by it name. + """Get unit by its name. @param name: Unit name (ie: network.service). @@ -119,7 +120,7 @@ def get_unit(self, name): raise SystemdError(error) def get_unit_by_pid(self, pid): - """Get unit by it PID. + """Get unit by its PID. @param PID: Unit PID. @@ -134,6 +135,38 @@ def get_unit_by_pid(self, pid): except dbus.exceptions.DBusException, error: raise SystemdError(error) + def get_service(self, name): + """Get service by its name. + + @param name: Service name (ie: network.service). + + @raise SystemdError: Raised when no service is found with the given name. + + @rtype: systemd.service.Service + """ + try: + unit_path = self.__interface.GetUnit(name) + service = Service(unit_path) + return service + except dbus.exceptions.DBusException, error: + raise SystemdError(error) + + def get_service_by_pid(self, pid): + """Get service by its PID. + + @param PID: Service PID. + + @raise SystemdError: Raised when no service with that PID is found. + + @rtype: systemd.service.Service + """ + try: + unit_path = self.__interface.GetUnitByPID(pid) + service = Service(unit_path) + return service + except dbus.exceptions.DBusException, error: + raise SystemdError(error) + def halt(self): try: self.__interface.Halt() diff --git a/systemd/unit.py b/systemd/unit.py index 8bfbe02..775ff93 100644 --- a/systemd/unit.py +++ b/systemd/unit.py @@ -25,9 +25,12 @@ from systemd.exceptions import SystemdError from systemd.job import Job + class Unit(object): """Abstraction class to org.freedesktop.systemd1.Unit interface""" def __init__(self, unit_path): + self.__unit_path = unit_path + self.__bus = dbus.SystemBus() self.__proxy = self.__bus.get_object( @@ -54,11 +57,15 @@ def __on_properties_changed(self, *args, **kargs): def __properties(self): properties = self.__properties_interface.GetAll( self.__interface.dbus_interface) - attr_property = Property() + attr_property = Property() for key, value in properties.items(): setattr(attr_property, key, value) setattr(self, 'properties', attr_property) + @property + def unit_path(self): + return self.__unit_path + def kill(self, who, mode, signal): """Kill unit. From b94019ebeb52de81b9a96d250dcfae00a82631c0 Mon Sep 17 00:00:00 2001 From: SYNchroACK Date: Fri, 27 Jan 2017 07:18:45 +0000 Subject: [PATCH 4/9] FIX: add python3 support --- systemd_dbus/job.py | 2 +- systemd_dbus/manager.py | 66 ++++++++++++++++++++-------------------- systemd_dbus/snapshot.py | 2 +- systemd_dbus/unit.py | 20 ++++++------ tests/manager_test.py | 4 +-- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/systemd_dbus/job.py b/systemd_dbus/job.py index 970e15b..6e84303 100644 --- a/systemd_dbus/job.py +++ b/systemd_dbus/job.py @@ -61,5 +61,5 @@ def __properties(self): def cancel(self): try: self.__interface.Cancel() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) \ No newline at end of file diff --git a/systemd_dbus/manager.py b/systemd_dbus/manager.py index 8eae9a2..898a8aa 100644 --- a/systemd_dbus/manager.py +++ b/systemd_dbus/manager.py @@ -64,26 +64,26 @@ def __properties(self): def clear_jobs(self): try: self.__interface.ClearJobs() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def create_snapshot(self, name, cleanup): try: snapshot_path = self.__interface.CreateSnapshot(name, cleanup) return str(snapshot_path) - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def dump(self): try: self.__interface.Dump() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def exit(self): try: self.__interface.Exit() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def get_job(self, ID): @@ -99,7 +99,7 @@ def get_job(self, ID): job_path = self.__interface.GetJob(ID) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def get_unit(self, name): @@ -115,7 +115,7 @@ def get_unit(self, name): unit_path = self.__interface.GetUnit(name) unit = Unit(unit_path) return unit - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def get_unit_by_pid(self, pid): @@ -131,19 +131,19 @@ def get_unit_by_pid(self, pid): unit_path = self.__interface.GetUnitByPID(pid) unit = Unit(unit_path) return unit - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def halt(self): try: self.__interface.Halt() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def k_exec(self): try: self.__interface.KExec() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def kill_unit(self, name, who, mode, signal): @@ -161,8 +161,8 @@ def kill_unit(self, name, who, mode, signal): """ try: self.__interface.KillUnit(name, who, mode, signal) - except dbus.exceptions.DBusException, error: - print error + except dbus.exceptions.DBusException as error: + print(error) raise SystemdError(error) def list_jobs(self): @@ -178,7 +178,7 @@ def list_jobs(self): for job in self.__interface.ListJobs(): jobs.append(Job(job[4])) return tuple(jobs) - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def list_units(self): @@ -194,7 +194,7 @@ def list_units(self): for unit in self.__interface.ListUnits(): units.append(Unit(unit[6])) return tuple(units) - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def load_unit(self, name): @@ -210,31 +210,31 @@ def load_unit(self, name): unit_path = self.__interface.LoadUnit(name) unit = Unit(unit_path) return unit - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def power_off(self): try: self.__interface.PowerOff() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reboot(self): try: self.__interface.Reboot() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reexecute(self): try: self.__interface.Reexecute() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reload(self): try: self.__interface.Reload() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reload_or_restart_unit(self, name, mode): @@ -251,7 +251,7 @@ def reload_or_restart_unit(self, name, mode): job_path = self.__interface.ReloadOrRestartUnit(name, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reload_or_try_restart_unit(self, name, mode): @@ -268,7 +268,7 @@ def reload_or_try_restart_unit(self, name, mode): job_path = self.__interface.ReloadOrTryRestartUnit(name, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reload_unit(self, name, mode): @@ -286,19 +286,19 @@ def reload_unit(self, name, mode): job_path = self.__interface.ReloadUnit(name, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reset_failed(self): try: self.__interface.ResetFailed() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reset_failed_unit(self, name): try: self.__interface.ResetFailedUnit(name) - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def restart_unit(self, name, mode): @@ -315,13 +315,13 @@ def restart_unit(self, name, mode): job_path = self.__interface.RestartUnit(name, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def set_environment(self, names): try: self.__interface.SetEnvironment(names) - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def start_unit(self, name, mode): @@ -338,7 +338,7 @@ def start_unit(self, name, mode): job_path = self.__interface.StartUnit(name, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def start_unit_replace(self, old_unit, new_unit, mode): @@ -356,7 +356,7 @@ def start_unit_replace(self, old_unit, new_unit, mode): job_path = self.__interface.StartUnitReplace(old_unit, new_unit, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def stop_unit(self, name, mode): @@ -373,14 +373,14 @@ def stop_unit(self, name, mode): job_path = self.__interface.StopUnit(name, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def subscribe(self): try: self.__interface.Subscribe() - except dbus.exceptions.DBusException, error: - print error + except dbus.exceptions.DBusException as error: + print(error) raise SystemdError(error) def try_restart_unit(self, name, mode): @@ -398,17 +398,17 @@ def try_restart_unit(self, name, mode): job_path = self.__interface.TryRestartUnit(name, mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def unset_environment(self, names): try: self.__interface.UnsetEnvironment(names) - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def unsubscribe(self): try: self.__interface.Unsubscribe() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) \ No newline at end of file diff --git a/systemd_dbus/snapshot.py b/systemd_dbus/snapshot.py index 01ec8bb..94eebad 100644 --- a/systemd_dbus/snapshot.py +++ b/systemd_dbus/snapshot.py @@ -61,5 +61,5 @@ def __properties(self): def remove(self): try: self.__interface.Remove() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) \ No newline at end of file diff --git a/systemd_dbus/unit.py b/systemd_dbus/unit.py index 6248b2f..6a63d98 100644 --- a/systemd_dbus/unit.py +++ b/systemd_dbus/unit.py @@ -73,8 +73,8 @@ def kill(self, who, mode, signal): """ try: self.__interface.KillUnit(who, mode, signal) - except dbus.exceptions.DBusException, error: - print error + except dbus.exceptions.DBusException as error: + print(error) raise SystemdError(error) def reload(self, mode): @@ -90,7 +90,7 @@ def reload(self, mode): job_path = self.__interface.Reload(mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) @@ -108,7 +108,7 @@ def reload_or_restart(self, mode): job_path = self.__interface.ReloadOrRestart(mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reload_or_try_restart(self, mode): @@ -124,13 +124,13 @@ def reload_or_try_restart(self, mode): job_path = self.__interface.ReloadOrTryRestart(mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def reset_failed(self): try: self.__interface.ResetFailed() - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def restart(self, mode): @@ -146,7 +146,7 @@ def restart(self, mode): job_path = self.__interface.Restart(mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def start(self, mode): @@ -162,7 +162,7 @@ def start(self, mode): job_path = self.__interface.Start(mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def stop(self, mode): @@ -178,7 +178,7 @@ def stop(self, mode): job_path = self.__interface.Stop(mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def try_restart(self,mode): @@ -194,5 +194,5 @@ def try_restart(self,mode): job_path = self.__interface.TryRestart(mode) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) \ No newline at end of file diff --git a/tests/manager_test.py b/tests/manager_test.py index 22ac70c..cdbd693 100644 --- a/tests/manager_test.py +++ b/tests/manager_test.py @@ -15,7 +15,7 @@ def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs self.assertRaises(error, callable, *args, **kwargs) try: callable(*args, **kwargs) - except error, e: + except error as e: self.assertEqual(message, str(e)) def setUp(self): @@ -168,4 +168,4 @@ def test_reload_or_try_restart_unit(self): # self.assertRaisesErrorWithMessage( # SystemdError, # 'NotSubscribed(Client is not subscribed.)', - # self.manager.unsubscribe) \ No newline at end of file + # self.manager.unsubscribe) From 60075b8d3263f17da409611323ab0333e2133bd1 Mon Sep 17 00:00:00 2001 From: SYNchroACK Date: Fri, 27 Jan 2017 07:33:14 +0000 Subject: [PATCH 5/9] FIX: adapt documentation to new name --- README => README.md | 65 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 14 deletions(-) rename README => README.md (78%) diff --git a/README b/README.md similarity index 78% rename from README rename to README.md index dde8c10..739cee8 100644 --- a/README +++ b/README.md @@ -1,6 +1,5 @@ -============== python-systemd-dbus -============== +=================== python-systemd-dbus python wrapper for `systemd`_ system and session manager dbus interfaces. @@ -8,16 +7,22 @@ interfaces. .. systemd: http://www.freedesktop.org/wiki/Software/systemd Basic usage -=========== +----------- +Import and create a `manager`: + +``` >>> from systemd_dbus.manager import Manager >>> manager = Manager() +``` + +List all units: -# List all units +``` >>> for unit in manager.list_units(): ... print unit.properties.Id ... print unit.properties.Description -... +... nfs-server.service LSB: Kernel NFS server support virtualbox.service @@ -27,44 +32,76 @@ LSB: Network monitoring daemon crond.service LSB: run cron daemon ... +``` + +Get an unit: +``` >>> unit = manager.get_unit('crond.service') +``` -# crond is running +`crond` is running: + +``` >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState loaded active running +``` + +Let's stop `crond`: -# Let's stop crond +``` >>> unit.stop('fail') +``` + +Is crond running? why I stop it!!: -# is crond running? why I stop it!! +``` >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState loaded active running +``` -# We want o loop! +We want o loop!: + +``` >>> import gobject >>> gobject.MainLoop().run() ... KeyboardInterrupt +``` + +Now Unit properties is updated!: -# Now Unit properties is updated! +``` >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState loaded inactive dead +``` + +Let's start `crond`: -# Let's start crond +``` >>> unit.start('fail') +``` -# Remember we want o loop! +Remember we want o loop!: + +``` >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState loaded inactive dead +``` + +The loop!: -# The loop! +``` >>> gobject.MainLoop().run() ... KeyboardInterrupt +``` + +Updated!: -# Updated! +``` >>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState loaded active running +``` From 7340a1073f2b0b1a60fd8f8731247a70d9c00575 Mon Sep 17 00:00:00 2001 From: SyNchroAcK Date: Fri, 27 Jan 2017 08:09:28 +0000 Subject: [PATCH 6/9] DOC: adapt for compatibility v2 and v3 --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 739cee8..11c6a5f 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ List all units: ``` >>> for unit in manager.list_units(): -... print unit.properties.Id -... print unit.properties.Description +... print(unit.properties.Id) +... print(unit.properties.Description) ... nfs-server.service LSB: Kernel NFS server support @@ -43,7 +43,7 @@ Get an unit: `crond` is running: ``` ->>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState +>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState) loaded active running ``` @@ -57,7 +57,7 @@ Let's stop `crond`: Is crond running? why I stop it!!: ``` ->>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState +>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState) loaded active running ``` @@ -73,7 +73,7 @@ KeyboardInterrupt Now Unit properties is updated!: ``` ->>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState +>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState) loaded inactive dead ``` @@ -87,7 +87,7 @@ Let's start `crond`: Remember we want o loop!: ``` ->>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState +>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState) loaded inactive dead ``` @@ -102,6 +102,6 @@ KeyboardInterrupt Updated!: ``` ->>> print unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState +>>> print(unit.properties.LoadState, unit.properties.ActiveState, unit.properties.SubState) loaded active running ``` From 9047654a4654899a48bac08d196bd1334bccc26f Mon Sep 17 00:00:00 2001 From: Vyronas Tsingaras Date: Fri, 17 Feb 2017 11:54:38 +0200 Subject: [PATCH 7/9] Fix Python 3.6 --- systemd/manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemd/manager.py b/systemd/manager.py index 523961f..fb423d7 100644 --- a/systemd/manager.py +++ b/systemd/manager.py @@ -148,7 +148,7 @@ def get_service(self, name): unit_path = self.__interface.GetUnit(name) service = Service(unit_path) return service - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def get_service_by_pid(self, pid): @@ -164,7 +164,7 @@ def get_service_by_pid(self, pid): unit_path = self.__interface.GetUnitByPID(pid) service = Service(unit_path) return service - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def halt(self): From e983bc309eeef82c79fb9f8f3046e6ab8e9d5370 Mon Sep 17 00:00:00 2001 From: Vyronas Tsingaras Date: Thu, 26 May 2016 12:22:19 +0300 Subject: [PATCH 8/9] Add property for dbus unit path and add get_service* Manager helper methods --- systemd_dbus/manager.py | 37 +++++++++++++++++++++++++++++++++++-- systemd_dbus/unit.py | 9 ++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/systemd_dbus/manager.py b/systemd_dbus/manager.py index 898a8aa..a2307cc 100644 --- a/systemd_dbus/manager.py +++ b/systemd_dbus/manager.py @@ -22,6 +22,7 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) from systemd_dbus.unit import Unit +from systemd_dbus.service import Service from systemd_dbus.job import Job from systemd_dbus.property import Property from systemd_dbus.exceptions import SystemdError @@ -103,7 +104,7 @@ def get_job(self, ID): raise SystemdError(error) def get_unit(self, name): - """Get unit by it name. + """Get unit by its name. @param name: Unit name (ie: network.service). @@ -119,7 +120,7 @@ def get_unit(self, name): raise SystemdError(error) def get_unit_by_pid(self, pid): - """Get unit by it PID. + """Get unit by its PID. @param PID: Unit PID. @@ -134,6 +135,38 @@ def get_unit_by_pid(self, pid): except dbus.exceptions.DBusException as error: raise SystemdError(error) + def get_service(self, name): + """Get service by its name. + + @param name: Service name (ie: network.service). + + @raise SystemdError: Raised when no service is found with the given name. + + @rtype: systemd.service.Service + """ + try: + unit_path = self.__interface.GetUnit(name) + service = Service(unit_path) + return service + except dbus.exceptions.DBusException, error: + raise SystemdError(error) + + def get_service_by_pid(self, pid): + """Get service by its PID. + + @param PID: Service PID. + + @raise SystemdError: Raised when no service with that PID is found. + + @rtype: systemd.service.Service + """ + try: + unit_path = self.__interface.GetUnitByPID(pid) + service = Service(unit_path) + return service + except dbus.exceptions.DBusException, error: + raise SystemdError(error) + def halt(self): try: self.__interface.Halt() diff --git a/systemd_dbus/unit.py b/systemd_dbus/unit.py index 6a63d98..3ae22b2 100644 --- a/systemd_dbus/unit.py +++ b/systemd_dbus/unit.py @@ -25,9 +25,12 @@ from systemd_dbus.exceptions import SystemdError from systemd_dbus.job import Job + class Unit(object): """Abstraction class to org.freedesktop.systemd1.Unit interface""" def __init__(self, unit_path): + self.__unit_path = unit_path + self.__bus = dbus.SystemBus() self.__proxy = self.__bus.get_object( @@ -54,11 +57,15 @@ def __on_properties_changed(self, *args, **kargs): def __properties(self): properties = self.__properties_interface.GetAll( self.__interface.dbus_interface) - attr_property = Property() + attr_property = Property() for key, value in properties.items(): setattr(attr_property, key, value) setattr(self, 'properties', attr_property) + @property + def unit_path(self): + return self.__unit_path + def kill(self, who, mode, signal): """Kill unit. From f1fbe8f5754293cc2bb6edc1bff158da7b4bd02d Mon Sep 17 00:00:00 2001 From: Vyronas Tsingaras Date: Fri, 17 Feb 2017 11:54:38 +0200 Subject: [PATCH 9/9] Fix Python 3.6 --- systemd_dbus/manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemd_dbus/manager.py b/systemd_dbus/manager.py index a2307cc..2bc1b5e 100644 --- a/systemd_dbus/manager.py +++ b/systemd_dbus/manager.py @@ -148,7 +148,7 @@ def get_service(self, name): unit_path = self.__interface.GetUnit(name) service = Service(unit_path) return service - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def get_service_by_pid(self, pid): @@ -164,7 +164,7 @@ def get_service_by_pid(self, pid): unit_path = self.__interface.GetUnitByPID(pid) service = Service(unit_path) return service - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def halt(self):