fixed bug with screen, cleaned code

This commit is contained in:
neersighted 2012-03-01 10:02:21 -08:00
parent badee8baa7
commit b7dd069d82

View file

@ -21,7 +21,7 @@ green = "\033[1;32m"
firstrun = "Welclome to your first run of: " firstrun = "Welclome to your first run of: "
usage = "usage: ./cloudbot {start|stop|restart|status}" usage = "usage: ./cloudbot {start|stop|restart|status}"
iusage = "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" iusage = "{1|start} {2|stop} {3|restart} {4|status} {5|exit}"
quit = "Goodbye! Thanks for using CloudBot!" quit = "Thanks for using CloudBot!"
error1 = red + "Neither screen nor daemon is installed! "\ error1 = red + "Neither screen nor daemon is installed! "\
"This program cannot run! {ERROR 1}" + nocol "This program cannot run! {ERROR 1}" + nocol
@ -29,7 +29,8 @@ error2 = red + "Could not find bot.py! Are you in the wrong folder? "\
"{ERROR 2}" + nocol "{ERROR 2}" + nocol
error3 = red + "Invalid choice, exiting! {ERROR 3}" + nocol error3 = red + "Invalid choice, exiting! {ERROR 3}" + nocol
error4 = red + "Program killed by user! {ERROR 4}" + nocol error4 = red + "Program killed by user! {ERROR 4}" + nocol
error5 = red + "Invalid backend in config! {ERROR 5}" + nocol error5 = red + "Invalid backend in config! (Or, backend not installed)"\
" {ERROR 5}" + nocol
error6 = red + "Author error! We be derpin'! {ERROR 6}" + nocol error6 = red + "Author error! We be derpin'! {ERROR 6}" + nocol
@ -48,7 +49,7 @@ daemonstop = "daemon -n cloudbot --stop"
daemonrestart = "daemon -n cloudbot --restart" daemonrestart = "daemon -n cloudbot --restart"
daemonpid = "pidof /usr/bin/daemon" daemonpid = "pidof /usr/bin/daemon"
screenstart = "screen -S cloudbot -dm python" + pwd +\ screenstart = "screen -d -m -S cloudbot -t cloudbot python " + pwd +\
"/bot.py >> " + pwd + "/bot.log 2>&1" "/bot.py >> " + pwd + "/bot.log 2>&1"
screenstop = "kill `pidof /usr/bin/screen`" screenstop = "kill `pidof /usr/bin/screen`"
screenrestart = stop + " && " + start screenrestart = stop + " && " + start
@ -84,38 +85,26 @@ except (subprocess.CalledProcessError):
running = False running = False
# Set commands # Set commands
if (backend == "daemon"):
if daemon: if daemon:
if (backend == "daemon"):
start = daemonstart start = daemonstart
stop = daemonstop stop = daemonstop
restart = daemonrestart restart = daemonrestart
pid = daemonpid pid = daemonpid
else:
print error5
elif (backend == "screen"): elif (backend == "screen"):
if screen:
start = screenstart start = screenstart
stop = screenstop stop = screenstop
restart = screenrestart restart = screenrestart
pid = screenpid pid = screenpid
else:
print error5
elif (backend == False): elif (backend == False):
print firstrun print firstrun
else: else:
print error5 print error5
elif screen:
if (backend == "daemon"):
start = daemonstart
stop = daemonstop
restart = daemonrestart
pid = daemonpid
elif (backend == "screen"):
start = screenstart
stop = screenstop
restart = screenrestart
pid = screenpid
elif (backend == False):
print firstrun
else:
print error5
else:
command = command
# Fancy banner # Fancy banner
print " ______ __ ______ __ __ "\ print " ______ __ ______ __ __ "\
@ -147,6 +136,7 @@ try:
print "Bot is already running, cannot start!" print "Bot is already running, cannot start!"
else: else:
command = start command = start
print "Starting... (" + backend + ")"
elif (sys.argv[1] == "stop") or (read == 2): elif (sys.argv[1] == "stop") or (read == 2):
if running: if running:
command = stop command = stop
@ -167,14 +157,14 @@ try:
print red + "Bot is not running! " + nocol print red + "Bot is not running! " + nocol
elif (sys.argv[1] == "clear"): elif (sys.argv[1] == "clear"):
command = clearlog command = clearlog
elif (sys.argv[1] == "exit") or (read == 5) or (read == 0): elif (sys.argv[1] == "exit") or (read == 5):
exit exit
elif (sys.argv[1] == "interactive"): elif (sys.argv[1] == "interactive"):
pass pass
else: else:
command = command
print usage print usage
exit exit
# Pretify errors # Pretify errors
except (TypeError, ValueError), e: except (TypeError, ValueError), e:
print error3 print error3
@ -188,7 +178,7 @@ except (NameError, SyntaxError), e:
# Check for bot files # Check for bot files
if botfile: if botfile:
command = command pass
else: else:
print error2 print error2
exit exit