Ich hab ein paar Fragen zu einem Script, welches ich fuer mein ubuntu und debian geschrieben habe. Ich bin noch nicht lange mit python am arbeiten, also zerfetzt mich nicht gleich
1. muss ich \n\n schreiben um 2 absaetze zu machen oder gibts da was, damit ich
irgendwie \2n oder so schreiben kann?
2. kann ich das script so erweitern, dass wenn ich per 'apt-get nvidia-glx' den
grafiktreiber runterlad (im script eingebettet), es dann die xorg.conf editiert
und automatisch den "nv" Treiber durch "nvidia" ersetzt?(und evtl ein back up der
xorg.conf anlegt)
3. gibt es irgendwelche tipps was meinen Stil angeht? vor allem die vielen ''' kommen
mir komisch vor. Macht man nach Kommentarzeilen einen Absatz?
4. Kann ich die Schrift irgendwie einfaerben? (sodass dass die keywords zb. rot sind wenn das Script in der Bash ausgefuehr wird?
Vielen Dank im Vorraus.
mfg benny
Code: Alles auswählen
#!/usr/bin/python
#The universal script <version>
print '''
THE UNIVERSAL SCRIPT <version> 2006 by mary
Attention! this script requires root rights! '''
# Now we define the infoText function.
def infoText():
print '''
Usage: Type one of the following keywords and accept them by pressing the
enter key:
"update" -- for a system update
"upgrade" -- for a system upgrade
"sysupgrade -- for a full system upgrade
"help" -- for infotext
"exit" -- for to exit the program
"reboot" -- for to reboot the system
"shutdown" -- for to shutdown the system
'''
# There we go with echoing the infoText for the user
infoText()
# this while true is for starting again from the beginning
while True:
s = (raw_input('''Type now a keyword: '''))
if s == 'update':
print '\nthis may take a while...\n\n'
import os
os.system('apt-get update')
if s == 'upgrade':
print '\nthis may take a while...\n\n'
import os
os.system('apt-get upgrade')
if s == 'sysupgrade':
print '\nthis may take a while...\n\n'
import os
os.system ('apt-get dist-upgrade')
# Here comes the shutdown part:
# I have to check if it works with 'now' because it's int() and the %d
if s == 'shutdown':
time2shutdown = int(raw_input(r"Insert the shutdown delay in minutes (type 'now' for no delay): "))
import os
x = 'shutdown -h %d' %(time2shutdown)
os.system(x)
# And here is the reboot part:
# And here I have to check the same as above (if 'now' works because of the int and the %d)
if s == 'reboot':
time2reboot = int(raw_input(r"Insert the shutdown delay in minutes (type 'now' for no delay): "))
import os
z = 'shutdown -r %d' %(time2reboot)
os.system(z)
# this only repeats the infoText string we defined on the beginning of the program.
if s == 'help':
infoText()
# The following 'else' part is for reminding the user to enter one of the keywords
else:
print '\nPlease type one of the keywords !\n'
# This is for to exit by a break.
if s == 'exit':
print '\nHave a nice day !!! good bye! ;-)\n'
break
# This continue belongs to the while True above
continue