diff --git a/README.md b/README.md index f914754..11c6a5f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -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 @@ -12,7 +12,7 @@ Basic usage Import and create a `manager`: ``` ->>> from systemd.manager import Manager +>>> from systemd_dbus.manager import Manager >>> manager = Manager() ``` @@ -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 ``` @@ -51,13 +51,13 @@ Let's stop `crond`: ``` >>> unit.stop('fail') - + ``` 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 ``` @@ -81,13 +81,13 @@ Let's start `crond`: ``` >>> unit.start('fail') - + ``` 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 ``` 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..81c0da0 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', 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/__init__.py deleted file mode 100644 index 6d8f7ae..0000000 --- a/systemd/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -VERSION = (0, 1, 0, 'planning', 0) - -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 diff --git a/systemd_dbus/__init__.py b/systemd_dbus/__init__.py new file mode 100644 index 0000000..bc6ae04 --- /dev/null +++ b/systemd_dbus/__init__.py @@ -0,0 +1,5 @@ +VERSION = (0, 1) + +def get_version(): + version = '%s.%s' % (VERSION[0], VERSION[1]) + return version 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 84% rename from systemd/job.py rename to systemd_dbus/job.py index 3d1ae18..6e84303 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""" @@ -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/manager.py b/systemd_dbus/manager.py similarity index 68% rename from systemd/manager.py rename to systemd_dbus/manager.py index 1fe1d32..5f8898c 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,11 @@ 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.service import Service +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""" @@ -64,26 +65,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): @@ -93,57 +94,121 @@ 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) 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): - """Get unit by it name. + """Get unit by its name. @param name: Unit name (ie: network.service). @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) 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): - """Get unit by it PID. + """Get unit by its PID. @param PID: Unit 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) unit = Unit(unit_path) return unit - except dbus.exceptions.DBusException, error: + 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 as 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 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 as 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 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): @@ -157,12 +222,12 @@ 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) - except dbus.exceptions.DBusException, error: - print error + except dbus.exceptions.DBusException as error: + print(error) raise SystemdError(error) def list_jobs(self): @@ -171,14 +236,14 @@ 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 = [] 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): @@ -187,14 +252,14 @@ 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 = [] 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): @@ -204,37 +269,37 @@ 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) 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): @@ -245,13 +310,13 @@ 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) 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): @@ -262,13 +327,13 @@ 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) 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): @@ -280,25 +345,25 @@ 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) 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): @@ -309,19 +374,19 @@ 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) 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): @@ -332,13 +397,13 @@ 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) 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): @@ -350,13 +415,13 @@ 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) 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): @@ -367,20 +432,20 @@ 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) 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): @@ -392,23 +457,23 @@ 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) 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/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 84% rename from systemd/snapshot.py rename to systemd_dbus/snapshot.py index 66ed8b2..94eebad 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""" @@ -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/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 79% rename from systemd/unit.py rename to systemd_dbus/unit.py index 8bfbe02..337c61a 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,13 +21,17 @@ 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""" def __init__(self, unit_path): + self.__unit_path = unit_path + self.__bus = dbus.SystemBus() self.__proxy = self.__bus.get_object( @@ -54,11 +58,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. @@ -69,12 +77,12 @@ 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) - except dbus.exceptions.DBusException, error: - print error + except dbus.exceptions.DBusException as error: + print(error) raise SystemdError(error) def reload(self, mode): @@ -84,13 +92,13 @@ 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) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) @@ -102,13 +110,13 @@ 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) 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): @@ -118,19 +126,19 @@ 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) 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): @@ -140,13 +148,13 @@ 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) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def start(self, mode): @@ -156,13 +164,13 @@ 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) job = Job(job_path) return job - except dbus.exceptions.DBusException, error: + except dbus.exceptions.DBusException as error: raise SystemdError(error) def stop(self, mode): @@ -172,13 +180,13 @@ 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) 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): @@ -188,11 +196,11 @@ 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) 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)