aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Harvey <chris@basementcode.com>2010-06-02 06:56:24 -0400
committerChristopher Harvey <chris@basementcode.com>2010-06-02 06:56:24 -0400
commit0d171afcaaa8d127a18eb6b27096d86605fd7b5e (patch)
tree0af28b516fa26e5d44db21fa28072fdbfe565862 /src
parentMerge branch 'internalDiff' (diff)
parentrc-update window now applies changes. (diff)
downloadventoo-0d171afcaaa8d127a18eb6b27096d86605fd7b5e.tar.gz
ventoo-0d171afcaaa8d127a18eb6b27096d86605fd7b5e.tar.bz2
ventoo-0d171afcaaa8d127a18eb6b27096d86605fd7b5e.zip
merged rcupdate brach...can now show and rc-update runlevels.
Diffstat (limited to 'src')
-rw-r--r--src/frontend/RcUpdateWindow.py124
-rw-r--r--src/frontend/main.py8
2 files changed, 132 insertions, 0 deletions
diff --git a/src/frontend/RcUpdateWindow.py b/src/frontend/RcUpdateWindow.py
new file mode 100644
index 0000000..29533f7
--- /dev/null
+++ b/src/frontend/RcUpdateWindow.py
@@ -0,0 +1,124 @@
+"""
+
+ 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, 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
diff --git a/src/frontend/main.py b/src/frontend/main.py
index de37b24..d12d8db 100644
--- a/src/frontend/main.py
+++ b/src/frontend/main.py
@@ -39,6 +39,7 @@ import difflib
from pygments import highlight
from pygments.lexers import DiffLexer
from pygments.formatters import HtmlFormatter
+import RcUpdateWindow
sandboxDir = '/'
@@ -57,9 +58,12 @@ class MainWindow(gtk.Window):
self.diffButton = gtk.ToolButton(None, "Diff!")
self.diffButton.connect("clicked", self.diffPressed, None)
self.showErrorsButton = gtk.ToolButton(None, "Augeas Errors")
+ self.showRCUpdateButton = gtk.ToolButton(None, "rc-update")
+ self.showRCUpdateButton.connect("clicked", self.showRCUpdate, None)
self.showErrorsButton.connect("clicked", self.showErrPressed, None)
self.mainToolbar.insert(self.diffButton, -1)
self.mainToolbar.insert(self.showErrorsButton, -1)
+ self.mainToolbar.insert(self.showRCUpdateButton, -1)
self.rootBox.pack_start(self.mainToolbar, False, False)
self.mainPaned = gtk.HPaned()
self.rootBox.pack_start(self.docBox)
@@ -183,6 +187,10 @@ class MainWindow(gtk.Window):
self.docWindow.load_url("file:///tmp/ventooDiff.html")
+ def showRCUpdate(self, button, data=None):
+ win = RcUpdateWindow.RcUpdateWindow()
+ win.show_all()
+
def showErrPressed(self, button, data=None):
d = ErrorDialog.ErrorDialog(augeas_utils.getFileErrorList(self.a))
d.show_all()