I love except! Do you?
This commit is contained in:
parent
743dbb6acf
commit
80e8e5a599
1 changed files with 45 additions and 30 deletions
21
cloudbot
21
cloudbot
|
@ -6,6 +6,7 @@ import subprocess
|
||||||
import re
|
import re
|
||||||
|
|
||||||
usage = "usage: ./cloudbot {start|stop|restart|status}"
|
usage = "usage: ./cloudbot {start|stop|restart|status}"
|
||||||
|
quit = "Goodbye! Thanks for using CloudBot!"
|
||||||
|
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
clearlog = ": >./bot.log && "
|
clearlog = ": >./bot.log && "
|
||||||
|
@ -19,13 +20,15 @@ daemon = re.match(r'^/usr/bin/screen$', screencheck)
|
||||||
error1 = "Neither screen nor daemon is installed! "\
|
error1 = "Neither screen nor daemon is installed! "\
|
||||||
"This script cannot run! {ERROR 1}"
|
"This script cannot run! {ERROR 1}"
|
||||||
error2 = "Could not find bot.py! Are you in the wrong folder? "\
|
error2 = "Could not find bot.py! Are you in the wrong folder? "\
|
||||||
(" + pwd + ") {ERROR 2}"
|
"(" + pwd + ") {ERROR 2}"
|
||||||
error3 = "Invalid choice, exiting! {ERROR 3}"
|
error3 = "Invalid choice, exiting! {ERROR 3}"
|
||||||
|
error4 = "Program killed by user! {ERROR 4}"
|
||||||
|
error5 = "Author error! We be derpin'! {ERROR 5}"
|
||||||
|
|
||||||
start = "echo " + error1
|
start = "echo " + error1
|
||||||
stop = "echo " + error1
|
stop = "echo " + error1
|
||||||
restart = "echo " + error1
|
restart = "echo " + error1
|
||||||
status = "ps aux|grep cloudbot"
|
status = "ps aux|grep cloudbot|grep -v grep|grep -v ./cloudbot"
|
||||||
|
|
||||||
if daemon:
|
if daemon:
|
||||||
start = "daemon -n cloudbot -O " + pwd + \
|
start = "daemon -n cloudbot -O " + pwd + \
|
||||||
|
@ -54,7 +57,7 @@ print " \______||_______| \______/ \______/ "\
|
||||||
"|_______/ |______/ \______/ |__| "
|
"|_______/ |______/ \______/ |__| "
|
||||||
print "http://git.io/cloudbot "\
|
print "http://git.io/cloudbot "\
|
||||||
" by lukeroge"
|
" by lukeroge"
|
||||||
|
try:
|
||||||
if (len(sys.argv) > 1):
|
if (len(sys.argv) > 1):
|
||||||
if (sys.argv[1] == 'start'):
|
if (sys.argv[1] == 'start'):
|
||||||
command = start
|
command = start
|
||||||
|
@ -83,10 +86,22 @@ else:
|
||||||
else:
|
else:
|
||||||
print error3
|
print error3
|
||||||
exit
|
exit
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
print error3
|
||||||
|
exit
|
||||||
|
except (KeyboardInterrupt):
|
||||||
|
print error4
|
||||||
|
exit
|
||||||
|
except (NameError, SyntaxError):
|
||||||
|
print error5
|
||||||
|
exit
|
||||||
|
|
||||||
if os.path.isfile("./bot.py"):
|
if os.path.isfile("./bot.py"):
|
||||||
command = command
|
command = command
|
||||||
else:
|
else:
|
||||||
print error2
|
print error2
|
||||||
exit
|
exit
|
||||||
|
|
||||||
subprocess.call(command, shell=True)
|
subprocess.call(command, shell=True)
|
||||||
|
print quit
|
||||||
exit
|
exit
|
||||||
|
|
Reference in a new issue