aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/ventoo/RcUpdateWindow.py')
-rw-r--r--src/ventoo/RcUpdateWindow.py123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/ventoo/RcUpdateWindow.py b/src/ventoo/RcUpdateWindow.py
new file mode 100644
index 0000000..5642c03
--- /dev/null
+++ b/src/ventoo/RcUpdateWindow.py
@@ -0,0 +1,123 @@
+"""
+
+ This file is part of the Ventoo program.
+
+ This is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ It 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this software. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Christopher Harvey
+
+
+"""
+
+import sys
+import pygtk
+pygtk.require('2.0')
+import gtk
+import gobject
+import os.path as osp
+import augeas_utils
+import subprocess
+import getpass
+import os
+import re
+import pdb
+
+class RcUpdateWindow(gtk.Window):
+ def __init__(self):
+ gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+ self.set_default_size(300, 500)
+ self.connect("delete_event", self.close)
+ self.runlevels = ["boot", "default", "nonetwork"]
+ # name boot default nonetwork
+ self.tv_store = gtk.ListStore(str, 'gboolean', 'gboolean', 'gboolean')
+ self.tv_store.set_sort_column_id(0, gtk.SORT_ASCENDING)
+ self.tv_view = gtk.TreeView(self.tv_store)
+
+ #renderers and columns
+ nameRenderer = gtk.CellRendererText()
+ nameColumn = gtk.TreeViewColumn("Script Name")
+ nameColumn.pack_start(nameRenderer, False)
+ nameColumn.add_attribute(nameRenderer, 'text', 0)
+ self.tv_view.append_column(nameColumn)
+ i = 1
+ for level in self.runlevels:
+ renderer = gtk.CellRendererToggle()
+ renderer.set_property("activatable", True)
+ renderer.connect("toggled", self.entry_toggled, i)
+ column = gtk.TreeViewColumn(level)
+ column.pack_start(renderer, False)
+ column.add_attribute(renderer, 'active', i)
+ self.tv_view.append_column(column)
+ i += 1
+
+ scrollWindow = gtk.ScrolledWindow()
+ scrollWindow.add(self.tv_view)
+ scrollWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
+ self.add(scrollWindow)
+
+ #fill model with data
+ reportedData = []
+ username = getpass.getuser()
+ if username == 'root':
+ process = subprocess.Popen("rc-update -s", stdout=subprocess.PIPE, shell=True)
+ os.waitpid(process.pid, 0)
+ output = process.stdout.read().strip()
+ output = output.split('\n')
+ for line in output:
+ datas = line.split(' ')
+ datas = filter(lambda a: a != '', datas) #remove all ''
+ datas = filter(lambda a: a != '|', datas) #remove the '|'
+ scriptName = datas[0]
+ reportedData.append(scriptName)
+ datas = datas[1:]
+ rowData = [scriptName]
+ for level in self.runlevels:
+ if level in datas:
+ rowData.append(True)
+ else:
+ rowData.append(False)
+ self.tv_store.append(rowData)
+
+ #fill in the rest of the data that rc-update -s hasn't reported.
+ allNames = os.listdir("/etc/init.d")
+ for name in allNames:
+ if not name in reportedData: #this name wasn't reported by rc-update -s
+ rowData = [False]*len(self.runlevels)
+ rowData.insert(0, name)
+ self.tv_store.append(rowData)
+ #TODO: sort the view.
+ else:
+ pass #say something about having to be a root user to rc-update
+
+ def entry_toggled(self, cell, path, column):
+ add = not self.tv_store[path][column]
+ scriptName = self.tv_store[path][0]
+ call = ["rc-update"]
+ if add:
+ call.append("add")
+ else:
+ call.append("del")
+ call.append(scriptName)
+ level = self.runlevels[column-1]
+ call.append(level)
+ retcode = subprocess.call(call)
+ if retcode == 0:
+ self.tv_store[path][column] = not self.tv_store[path][column]
+ else:
+ print "Call to rc-update failed." #TODO: print nice error.
+ #self.emit("entry-toggled", path)
+ pass
+
+ def close(self, widget, event, data=None):
+ pass