diff options
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/RcUpdateWindow.py | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/frontend/RcUpdateWindow.py b/src/frontend/RcUpdateWindow.py new file mode 100644 index 0000000..a9653e1 --- /dev/null +++ b/src/frontend/RcUpdateWindow.py @@ -0,0 +1,111 @@ +""" + + 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 +sys.path.append('../backend') +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) + 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 = int(path) + #self.tv_store[path][0] = not self.tv_store[path][0] + #self.emit("entry-toggled", path) + pass + + def close(self, widget, event, data=None): + pass |