Index: EasyUbuntu/detect.py =================================================================== --- EasyUbuntu/detect.py (revision 216) +++ EasyUbuntu/detect.py (working copy) @@ -179,10 +179,6 @@ sourcelist.close() targetlist.close() unduplicate(os.path.join(confdir, 'sources.list')) - #os.popen("chown -R "+os.getlogin()+":"+os.getlogin()+" "+confdir) - user = os.getenv('SUDO_USER') - cmd = "chown -R " + user + ":" + user + " " + confdir - subprocess.Popen(cmd, shell=True) def unduplicate(sourcefile): """ Index: EasyUbuntu/gtkpermission.py =================================================================== --- EasyUbuntu/gtkpermission.py (revision 0) +++ EasyUbuntu/gtkpermission.py (revision 0) @@ -0,0 +1,94 @@ +import gtk +import subprocess + +class PermissionDialog(gtk.Dialog): + def __init__(self, packages): + gtk.Dialog.__init__(self, "EasyUbuntu: Permission required to install", None, gtk.DIALOG_MODAL, buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) + permission_required = gtk.Label("EasyUbuntu needs your" + " permission to install" + " the following packages:") + self.packages = packages + package_list = gtk.ListStore(str) + for package in packages: + package_list.append([package]) + self.treeview = gtk.TreeView(package_list) + tvcolumn = gtk.TreeViewColumn('Packages') + # add tvcolumn to treeview + self.treeview.append_column(tvcolumn) + # create a CellRendererText to render the data + cell = gtk.CellRendererText() + # add the cell to the tvcolumn and allow it to expand + tvcolumn.pack_start(cell, True) + # set the cell "text" attribute to column 0 - retrieve text + # from that column in treestore + tvcolumn.add_attribute(cell, 'text', 0) + + how_to = gtk.Label("Enter your password to give permission" + " to EasyUbuntu to install the above packages" + " and press the OK button. To deny permission," + " press the Cancel button") + + self.hbox = gtk.HBox(spacing=10) + + password_label = gtk.Label("Password: ") + self.password_entry = gtk.Entry() + self.password_entry.set_visibility(False) + self.password_wrong = gtk.Label() + self.hbox.pack_start(password_label, expand=False) + self.hbox.pack_start(self.password_entry, expand=False) + self.hbox.pack_start(self.password_wrong, expand=False) + # now we need to add all the visible widgets created to the dialog vbox + self.vbox.pack_start(permission_required, expand=False) + self.vbox.pack_start(self.treeview, expand=False) + self.vbox.pack_start(how_to, expand=False) + self.vbox.pack_start(self.hbox, expand=False) + + permission_required.show() + self.treeview.show() + how_to.show() + self.hbox.show_all() + self.vbox.show() + +def check_sudo(password): + if not password: + return False + command = "/usr/bin/sudo -S -v" # -S means read from stdin, -v means verify + sudo = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + sudo.stdin.write(password + '\n') + sudo.stdin.close() + sts = sudo.wait() + + if sts > 0: + return False + else: + return True + +def sudo_command(password, command): + if check_sudo(password): + command = 'sudo -S ' + command + p = subprocess.Popen(command, shell=True) + p.stdin.write(password + '\n') + p.stdin.close() + + sts = p.wait() + if sts > 0: return False + else: return True + else: + return False +def run_permission_dialog(packages, when_permitted=None): + pd = PermissionDialog(packages) + def f(d, response_id, *user_data): + if response_id == gtk.RESPONSE_OK: + pd.password_wrong.set_text("") + password = pd.password_entry.get_text() + result = check_sudo(password) + if not result: + pd.password_wrong.set_text("Wrong password!") + else: + pd.destroy() + if when_permitted: + when_permitted(pd.packages, password) + else: + pd.destroy() + pd.connect("response", f) + pd.run() Index: EasyUbuntu/gtkprocess.py =================================================================== --- EasyUbuntu/gtkprocess.py (revision 216) +++ EasyUbuntu/gtkprocess.py (working copy) @@ -38,10 +38,11 @@ class PackageManager: - def __init__(self, packageslist, confdir): + def __init__(self, packageslist, confdir, password): """ Call Synaptic with different configuration options """ + self.password = password self.packageslist = packageslist - self.manager = ["/usr/sbin/synaptic", "--hide-main-window", "--non-interactive"] + self.manager = ["/usr/bin/sudo -S /usr/sbin/synaptic", "--hide-main-window", "--non-interactive"] self.manager.append("-o=dir::etc="+confdir) self.manager.append("-o=dir::etc::sourcelist=sources.list") print self.manager @@ -52,24 +53,31 @@ self.manager.append("--update-at-startup") print "In update", self.manager process = os.popen(" ".join(self.manager), "w") + process.write(self.password + '\n') process.close() # Run it def install(self, Packages = None): """ Install packages """ + f = open("f", "w") + for s in Packages: + f.write("%s install\n" % str(s)) + f.close() + self.manager.remove("--update-at-startup") self.manager.append("--set-selections") - print "In Install", self.manager - process = os.popen(" ".join(self.manager), "w") - for s in Packages: - process.write("%s install\n" % str(s)) + e = "cat f | %s" % (" ".join(self.manager),) + + process = os.popen(e, "w") + + process.write(self.password + '\n') process.close() class gtkLogger: - def __init__(self, packageslist, configslist, confdir): + def __init__(self, packageslist, configslist, confdir, password): self.commandslist = [] - synaptic =PackageManager(packageslist, confdir) + synaptic =PackageManager(packageslist, confdir, password) synaptic.update() synaptic.install(Packages = packageslist) Index: EasyUbuntu/gtkfrontend.py =================================================================== --- EasyUbuntu/gtkfrontend.py (revision 216) +++ EasyUbuntu/gtkfrontend.py (working copy) @@ -23,7 +23,7 @@ from backend import * from detect import * from gtkprocess import gtkLogger - +import gtkpermission import gtk, gtk.glade import os import sys @@ -155,9 +155,9 @@ def on_ok_button_clicked(self, gui): self.tree.get_widget('mainwindow').hide() - - logger = gtkLogger(self.packageslist, self.configslist, self.confdir) - + def f(packages, password): + gtkLogger(self.packageslist, self.configslist, self.confdir, password) + gtkpermission.run_permission_dialog(self.packageslist, f) self.tree.get_widget('mainwindow').show() self.tree.get_widget('ok_button').set_sensitive(False)