[kupfer: 16/20] + services plugin



commit c0ca3d9cb1c82bef93f06e3cff529658783f3a16
Author: Karol BÄ?dkowski <karol bedkowsk+gh gmail com>
Date:   Tue Oct 6 22:33:44 2009 +0200

    + services plugin
    
    Plugin allow start, stop and restart system services via scripts
    in /etc/*/init.d/ and gksu (or other sudo-like program).

 kupfer/plugin/services.py |  130 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 130 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/plugin/services.py b/kupfer/plugin/services.py
new file mode 100644
index 0000000..9be988c
--- /dev/null
+++ b/kupfer/plugin/services.py
@@ -0,0 +1,130 @@
+# -*- coding: utf8 -*-
+import os
+
+from kupfer import plugin_support
+from kupfer.objects import Leaf, Action, Source 
+from kupfer.helplib import FilesystemWatchMixin, PicklingHelperMixin
+from kupfer import utils
+
+__kupfer_name__ = _("System Services")
+__kupfer_sources__ = ("SystemServicesSource", )
+__description__ = _("Start/stop/restart System Services via scripts in /etc/*/init.d/ and *sudo")
+__version__ = "0.2"
+__author__ = "Karol BÄ?dkowski <karol bedkowski gmail com>"
+__kupfer_settings__ = plugin_support.PluginSettings(
+		plugin_support.SETTING_PREFER_CATALOG,
+		dict(key='sudo_cmd', label=_("Sudo-like Command"), type=str, value="gksu"),
+)
+
+
+# skip this services
+_SERVICES_BLACK_LIST = [
+		"acpid", "acpi-support", "alsa-utils", "apmd", "binfmt-support",
+		"bootlogd", "bootmisc.sh", "checkfs.sh", "checkroot.sh",
+		"console-screen.kbd.sh", "console-setup", "dbus", "dns-clean", "glibc.sh", 
+		"hal", "halt", "hostname.sh", "hotkey-setup", "hwclockfirst.sh", 
+		"hwclock.sh", "keyboard-setup", "killprocs", "klogd", "laptop-mode", 
+		"linux-restricted-modules-common", "module-init-tools", 
+		"mountall-bootclean.sh", "mountall.sh", "mountdevsubfs.sh", "mountkernfs.sh", 
+		"mountnfs-bootclean.sh", "mountnfs.sh", "mountoverflowtmp", "mtab.sh",
+		"policykit", "pppd-dns", "procps", "rc", "rc.local", "rcS", "reboot",   
+		"readahead", "readahead-desktop", "rmnologin", "screen-cleanup", "sendsigs", 
+		"single", "stop-bootlogd", "stop-bootlogd-single", "stop-readahead",
+		"sysklogd", "system-tools-backends", "udev", "udev-finish", "umountfs", 
+		"umountnfs.sh", "umountroot", "urandom", "vbesave", "wpa-ifupdown", "x11-common", 
+		'README'
+]
+
+
+class Service(Leaf):
+	""" Represent system service """
+	def get_actions(self):
+		yield StartService()
+		yield StopService()
+		yield RestartService()
+
+	def get_description(self):
+		return self.object
+
+	def get_icon_name(self):
+		return "applications-system"
+
+
+class _ServiceAction(Action):
+	def __init__(self, name, icon, command):
+		Action.__init__(self, name)
+		self._icon = icon
+		self._command = command
+
+	def get_icon_name(self):
+		return self._icon
+
+	def activate(self, leaf):
+		sudo_cmd = __kupfer_settings__["sudo_cmd"]
+		utils.launch_commandline(sudo_cmd + " " + leaf.object + " " + self._command, \
+				in_terminal=True)
+
+	def item_types(self):
+		yield Service
+
+
+class StartService(_ServiceAction):
+	""" Start service action """
+	def __init__(self):
+		_ServiceAction.__init__(self, _('Start Service'), 'start', 'start')
+
+
+class RestartService(_ServiceAction):
+	""" restart service action """
+	def __init__(self):
+		_ServiceAction.__init__(self, _('Restart Service'), 'reload', 'restart')
+
+
+class StopService(_ServiceAction):
+	""" restart service action """
+	def __init__(self):
+		_ServiceAction.__init__(self, _('Stop Service'), 'stop', 'stop')
+
+
+class SystemServicesSource(Source, FilesystemWatchMixin, PicklingHelperMixin):
+	''' Index system services from /etc/*/init.d/ '''
+
+	def __init__(self, name=_("System Services")):
+		Source.__init__(self, name)
+		self._initd_path = None
+		self.unpickle_finish()
+
+	def unpickle_finish(self):
+		# path to file with list notebooks
+		for initd_path in ('/etc/init.d/', '/etc/rc/init.d'):
+			if os.path.exists(initd_path) and os.path.isdir(initd_path):
+				self._initd_path = initd_path
+				break
+
+		self.monitor_token = self.monitor_directories(self._initd_path)
+
+	def monitor_include_file(self, gfile):
+		return gfile and not gfile.get_basename() in self.BLACK_LIST
+
+	def get_items(self):
+		if self._initd_path is None:
+			return
+
+		for filename in os.listdir(self._initd_path):
+			if (filename in _SERVICES_BLACK_LIST \
+					or filename.find('dpkg-') > 0 or filename.endswith('~') \
+					or filename.startswith('.')):
+				continue
+
+			file_path = os.path.join(self._initd_path, filename)
+			if not os.path.isfile(file_path):
+				continue
+
+			yield Service(file_path, _("%s Service") % filename)
+
+	def get_icon_name(self):
+		return "applications-system"
+
+	def provides(self):
+		yield Service
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]