I am creating an Ubuntu App using quickly on ubuntu 12.10. Its a simple GUI for starting, stopping and restarting Apache2 web server.
Let me first give the part of the code in which I am facing problem -
# handler for restart apache button
def on_button_restart_clicked(self, button):
self.label = self.builder.get_object("labelStatus")
self.label.set_text("Restarting web server apache2")
os.system("gksudo /etc/init.d/apache2 restart")
self.label.set_text("Web server apache2 Restarted")
As soon as the button is clicked the method is invoked but the label is not showing - Restarting web server apache2 In the terminal the output at this time is - * Restarting web server apache2 [ OK ] ... waiting and as soon as the apache is restared the next line is displayed which is - Web server apache2 Restarted
How can I solve the issues -
- I don't want to hard code the message in the label text. So how can I keep a track on the terminal output and capture it to the python variable so that I can set the label text.
- Since I am using gksudo the popup is coming to enter the password, but the problem is that it is showing the command. How can I gracefully use sudo in python?
I am totally new to python. Thanks in advance