Python


6 posts
by Protheuz » Sun May 12, 2013 6:56 pm
Hey! Sorry for noobish question, but can i do (for example)
os.system("apt-get update")
then wait until it finished, when its done do
os.system("apt-get upgrade")
wait again, when done do
os.system("apt-get install something")
and so on, i really need to know.

//Protheuz
Wiizard/Protheuz, just call me Kev.
User avatar
Posts: 80
Joined: Sat May 11, 2013 5:24 pm
Location: In my chair, bed or sofa.
by rurwin » Sun May 12, 2013 7:08 pm
Yes you can, but you would have to run Python as root, because apt-get requires root access permissions.

pi@RaspberryPi ~/ $ sudo python
User avatar
Forum Moderator
Forum Moderator
Posts: 2913
Joined: Mon Jan 09, 2012 3:16 pm
by davef21370 » Mon May 13, 2013 4:58 pm
Would os.system("sudo apt-get whatever") work instead of running as root?

Dave.
Please feel free to tap into my abundant lack of knowledge.
User avatar
Posts: 515
Joined: Fri Sep 21, 2012 4:13 pm
Location: Up North
by rurwin » Mon May 13, 2013 7:40 pm
Maybe. Try it and see.

But that is sudo by the back-door. If an app needs root privileges I want to know about it and make the decision myself. On a RaspPi it would grab extra privileges silently, which I don't like, but on Ubuntu it would ask for a password, and if it is a GUI app, that would fail.
User avatar
Forum Moderator
Forum Moderator
Posts: 2913
Joined: Mon Jan 09, 2012 3:16 pm
by Protheuz » Fri May 24, 2013 7:49 am
I think, if im not wrong, that sudo wont help. It would still open all of the commands at once
Wiizard/Protheuz, just call me Kev.
User avatar
Posts: 80
Joined: Sat May 11, 2013 5:24 pm
Location: In my chair, bed or sofa.
by gkreidl » Fri May 24, 2013 8:39 am
import subprocess

retcode = subprocess.call(["sudo", "apt-get","update"])

and so on ....

subprocess.call() will wait for the commands to finish.
Minimal Kiosk Browser
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer
Posts: 1297
Joined: Thu Jan 26, 2012 1:07 pm