From e1d3e2075866ef62d82b685278e191bd834e6200 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 01:12:17 -0800 Subject: [PATCH 01/12] added basic wrapper --- cloudbot | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 cloudbot diff --git a/cloudbot b/cloudbot new file mode 100755 index 0000000..d182608 --- /dev/null +++ b/cloudbot @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# Bot Wrapper by neersighted +import sys +import os +import subprocess + +pwd = os.getcwd() +clearlog = ": >./bot.log && " +start = "daemon -n cloudbot -O " + pwd + "/bot.log -r python " + pwd + "/bot.py" +stop = clearlog + "daemon -n cloudbot --stop" +restart = clearlog + "daemon -n cloudbot --restart" +command = ":" + +print " ______ __ ______ __ __ _______ .______ ______ .___________." +print " / || | / __ \ | | | | | \ | _ \ / __ \ | |" +print "| ,----'| | | | | | | | | | | .--. || |_) | | | | | `---| |----`" +print "| | | | | | | | | | | | | | | || _ < | | | | | | " +print "| `----.| `----.| `--' | | `--' | | '--' || |_) | | `--' | | | " +print " \______||_______| \______/ \______/ |_______/ |______/ \______/ |__| " + +if (len(sys.argv) > 1): + if( sys.argv[1] == 'start' ): + command = start + elif( sys.argv[1] == 'stop' ): + command = stop + elif( sys.argv[1] == 'restart' ): + command = restart + else: + print "usage: ./cloudbot {start|stop|restart}" +else: + print "usage: ./cloudbot {start|stop|restart}" +''' +if os.path.isfile("./control.sh"): + command = "./control.sh command" +elif os.path.isfile("./bot.sh"): + command = "./bot.sh command" +else: + command = "./bot.py" +''' +subprocess.call(command, shell=True) +sys.exit() From d4a930dffb537795fb6997381b655e10456d9262 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 01:16:21 -0800 Subject: [PATCH 02/12] Getting the skeleton together --- cloudbot | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cloudbot b/cloudbot index d182608..5b47e2a 100755 --- a/cloudbot +++ b/cloudbot @@ -17,6 +17,7 @@ print "| ,----'| | | | | | | | | | | .--. || |_) | | | | | `- print "| | | | | | | | | | | | | | | || _ < | | | | | | " print "| `----.| `----.| `--' | | `--' | | '--' || |_) | | `--' | | | " print " \______||_______| \______/ \______/ |_______/ |______/ \______/ |__| " +print "http://git.io/cloudbot by lukeroge" if (len(sys.argv) > 1): if( sys.argv[1] == 'start' ): @@ -27,15 +28,16 @@ if (len(sys.argv) > 1): command = restart else: print "usage: ./cloudbot {start|stop|restart}" + sys.exit() else: print "usage: ./cloudbot {start|stop|restart}" -''' -if os.path.isfile("./control.sh"): - command = "./control.sh command" -elif os.path.isfile("./bot.sh"): - command = "./bot.sh command" + sys.exit() + +if os.path.isfile("./bot.py"): + command = command else: - command = "./bot.py" -''' + print "Could not find bot.py! Are you in the wrong folder? (" + pwd + ")" + sys.exit() + subprocess.call(command, shell=True) sys.exit() From 743dbb6acf9593f556506b9d79dd7c1d355a9070 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 09:44:05 -0800 Subject: [PATCH 03/12] Wrapper comming together --- cloudbot | 93 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/cloudbot b/cloudbot index 5b47e2a..86bcb22 100755 --- a/cloudbot +++ b/cloudbot @@ -3,41 +3,90 @@ import sys import os import subprocess +import re + +usage = "usage: ./cloudbot {start|stop|restart|status}" pwd = os.getcwd() clearlog = ": >./bot.log && " -start = "daemon -n cloudbot -O " + pwd + "/bot.log -r python " + pwd + "/bot.py" -stop = clearlog + "daemon -n cloudbot --stop" -restart = clearlog + "daemon -n cloudbot --restart" command = ":" -print " ______ __ ______ __ __ _______ .______ ______ .___________." -print " / || | / __ \ | | | | | \ | _ \ / __ \ | |" -print "| ,----'| | | | | | | | | | | .--. || |_) | | | | | `---| |----`" -print "| | | | | | | | | | | | | | | || _ < | | | | | | " -print "| `----.| `----.| `--' | | `--' | | '--' || |_) | | `--' | | | " -print " \______||_______| \______/ \______/ |_______/ |______/ \______/ |__| " -print "http://git.io/cloudbot by lukeroge" +daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) +daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) +screencheck = subprocess.check_output("locate /usr/bin/screen", shell=True) +daemon = re.match(r'^/usr/bin/screen$', screencheck) + +error1 = "Neither screen nor daemon is installed! "\ + "This script cannot run! {ERROR 1}" +error2 = "Could not find bot.py! Are you in the wrong folder? "\ + (" + pwd + ") {ERROR 2}" +error3 = "Invalid choice, exiting! {ERROR 3}" + +start = "echo " + error1 +stop = "echo " + error1 +restart = "echo " + error1 +status = "ps aux|grep cloudbot" + +if daemon: + start = "daemon -n cloudbot -O " + pwd + \ + "/bot.log -r python " + pwd + "/bot.py" + stop = clearlog + "daemon -n cloudbot --stop" + restart = stop + " && " + start +elif screen: + start = "screen -S cloudbot -dm python" + pwd +\ + "/bot.py >>" + pwd + "/bot.log 2>&1" + stop = clearlog + "kill `pidof /usr/bin/screen`" + restart = stop + " && " + start +else: + print error1 + +print " ______ __ ______ __ __ "\ +" _______ .______ ______ .___________." +print " / || | / __ \ | | | | "\ +"| \ | _ \ / __ \ | |" +print "| ,----'| | | | | | | | | | "\ +"| .--. || |_) | | | | | `---| |----`" +print "| | | | | | | | | | | | "\ +"| | | || _ < | | | | | | " +print "| `----.| `----.| `--' | | `--' | "\ +"| '--' || |_) | | `--' | | | " +print " \______||_______| \______/ \______/ "\ +"|_______/ |______/ \______/ |__| " +print "http://git.io/cloudbot "\ +" by lukeroge" if (len(sys.argv) > 1): - if( sys.argv[1] == 'start' ): + if (sys.argv[1] == 'start'): command = start - elif( sys.argv[1] == 'stop' ): + elif (sys.argv[1] == 'stop'): command = stop - elif( sys.argv[1] == 'restart' ): + elif (sys.argv[1] == 'restart'): command = restart + elif (sys.argv[1] == 'status'): + command = status else: - print "usage: ./cloudbot {start|stop|restart}" - sys.exit() + print usage + exit else: - print "usage: ./cloudbot {start|stop|restart}" - sys.exit() - + print "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" + read = int(raw_input('Please choose a option: ')) + if read == 1: + command = start + elif read == 2: + command = stop + elif read == 3: + command = restart + elif read == 4: + command = status + elif read == 5: + exit + else: + print error3 + exit if os.path.isfile("./bot.py"): command = command else: - print "Could not find bot.py! Are you in the wrong folder? (" + pwd + ")" - sys.exit() - + print error2 + exit subprocess.call(command, shell=True) -sys.exit() +exit From 80e8e5a599cd527425206a816bf1aabecd035397 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 09:59:18 -0800 Subject: [PATCH 04/12] I love except! Do you? --- cloudbot | 75 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/cloudbot b/cloudbot index 86bcb22..2857b20 100755 --- a/cloudbot +++ b/cloudbot @@ -6,6 +6,7 @@ import subprocess import re usage = "usage: ./cloudbot {start|stop|restart|status}" +quit = "Goodbye! Thanks for using CloudBot!" pwd = os.getcwd() clearlog = ": >./bot.log && " @@ -19,13 +20,15 @@ daemon = re.match(r'^/usr/bin/screen$', screencheck) error1 = "Neither screen nor daemon is installed! "\ "This script cannot run! {ERROR 1}" error2 = "Could not find bot.py! Are you in the wrong folder? "\ - (" + pwd + ") {ERROR 2}" + "(" + pwd + ") {ERROR 2}" error3 = "Invalid choice, exiting! {ERROR 3}" +error4 = "Program killed by user! {ERROR 4}" +error5 = "Author error! We be derpin'! {ERROR 5}" start = "echo " + error1 stop = "echo " + error1 restart = "echo " + error1 -status = "ps aux|grep cloudbot" +status = "ps aux|grep cloudbot|grep -v grep|grep -v ./cloudbot" if daemon: start = "daemon -n cloudbot -O " + pwd + \ @@ -54,39 +57,51 @@ print " \______||_______| \______/ \______/ "\ "|_______/ |______/ \______/ |__| " print "http://git.io/cloudbot "\ " by lukeroge" +try: + if (len(sys.argv) > 1): + if (sys.argv[1] == 'start'): + command = start + elif (sys.argv[1] == 'stop'): + command = stop + elif (sys.argv[1] == 'restart'): + command = restart + elif (sys.argv[1] == 'status'): + command = status + else: + print usage + exit + else: + print "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" + read = int(raw_input('Please choose a option: ')) + if read == 1: + command = start + elif read == 2: + command = stop + elif read == 3: + command = restart + elif read == 4: + command = status + elif read == 5: + exit + else: + print error3 + exit +except (TypeError, ValueError): + print error3 + exit +except (KeyboardInterrupt): + print error4 + exit +except (NameError, SyntaxError): + print error5 + exit -if (len(sys.argv) > 1): - if (sys.argv[1] == 'start'): - command = start - elif (sys.argv[1] == 'stop'): - command = stop - elif (sys.argv[1] == 'restart'): - command = restart - elif (sys.argv[1] == 'status'): - command = status - else: - print usage - exit -else: - print "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" - read = int(raw_input('Please choose a option: ')) - if read == 1: - command = start - elif read == 2: - command = stop - elif read == 3: - command = restart - elif read == 4: - command = status - elif read == 5: - exit - else: - print error3 - exit if os.path.isfile("./bot.py"): command = command else: print error2 exit + subprocess.call(command, shell=True) +print quit exit From 1bc186338e423a92b887d314898ccda37854c153 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 10:30:31 -0800 Subject: [PATCH 05/12] color and status! --- cloudbot | 115 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 34 deletions(-) diff --git a/cloudbot b/cloudbot index 2857b20..8d4cc18 100755 --- a/cloudbot +++ b/cloudbot @@ -12,34 +12,46 @@ pwd = os.getcwd() clearlog = ": >./bot.log && " command = ":" +nocol = "\033[1;m" +red = "\033[1;31m" +green = "\033[1;32m" + daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) screencheck = subprocess.check_output("locate /usr/bin/screen", shell=True) -daemon = re.match(r'^/usr/bin/screen$', screencheck) +screen = re.match(r'^/usr/bin/screen$', screencheck) -error1 = "Neither screen nor daemon is installed! "\ - "This script cannot run! {ERROR 1}" -error2 = "Could not find bot.py! Are you in the wrong folder? "\ - "(" + pwd + ") {ERROR 2}" -error3 = "Invalid choice, exiting! {ERROR 3}" -error4 = "Program killed by user! {ERROR 4}" -error5 = "Author error! We be derpin'! {ERROR 5}" +try: + runningcheck = subprocess.check_output("ps ax|grep cloudbot|"\ + "grep -v grep|grep -v ./cloudbot", shell=True) + running = re.match(r'^[1-9]+', runningcheck) +except (subprocess.CalledProcessError): + running = False + +error1 = red + "Neither screen nor daemon is installed! "\ + "This script cannot run! {ERROR 1}" + nocol +error2 = red + "Could not find bot.py! Are you in the wrong folder? "\ + "(" + pwd + ") {ERROR 2}" + nocol +error3 = red + "Invalid choice, exiting! {ERROR 3}" + nocol +error4 = red + "Program killed by user! {ERROR 4}" + nocol +error5 = red + "Author error! We be derpin'! {ERROR 5}" + nocol start = "echo " + error1 stop = "echo " + error1 restart = "echo " + error1 -status = "ps aux|grep cloudbot|grep -v grep|grep -v ./cloudbot" if daemon: start = "daemon -n cloudbot -O " + pwd + \ "/bot.log -r python " + pwd + "/bot.py" stop = clearlog + "daemon -n cloudbot --stop" restart = stop + " && " + start + pid = subprocess.check_output("pidof /usr/bin/daemon", shell=True) elif screen: start = "screen -S cloudbot -dm python" + pwd +\ "/bot.py >>" + pwd + "/bot.log 2>&1" stop = clearlog + "kill `pidof /usr/bin/screen`" restart = stop + " && " + start + pid = subprocess.check_output("pidof /usr/bin/screen", shell=True) else: print error1 @@ -58,34 +70,69 @@ print " \______||_______| \______/ \______/ "\ print "http://git.io/cloudbot "\ " by lukeroge" try: - if (len(sys.argv) > 1): - if (sys.argv[1] == 'start'): - command = start - elif (sys.argv[1] == 'stop'): - command = stop - elif (sys.argv[1] == 'restart'): - command = restart - elif (sys.argv[1] == 'status'): - command = status + if running: + if (len(sys.argv) > 1): + if (sys.argv[1] == 'start'): + print "Bot is alread running, cannot start!" + elif (sys.argv[1] == 'stop'): + command = stop + print "Stopping with: " + command + elif (sys.argv[1] == 'restart'): + command = restart + print "Restarting with: " + command + elif (sys.argv[1] == 'status'): + print green + "Bot is running! " + pid + nocol + else: + print usage + exit else: - print usage - exit + print "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" + read = int(raw_input('Please choose a option: ')) + if read == 1: + print "Bot is alread running, cannot start!" + elif read == 2: + command = stop + print "Stopping with: " + command + elif read == 3: + command = restart + print "Restarting with: " + command + elif read == 4: + print green + "Bot is running! " + pid + nocol + elif read == 5: + print quit + else: + print error3 else: - print "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" - read = int(raw_input('Please choose a option: ')) - if read == 1: - command = start - elif read == 2: - command = stop - elif read == 3: - command = restart - elif read == 4: - command = status - elif read == 5: - exit + if (len(sys.argv) > 1): + if (sys.argv[1] == 'start'): + command = start + print "Starting with: " + command + elif (sys.argv[1] == 'stop'): + print "Bot is not running, cannot stop!" + elif (sys.argv[1] == 'restart'): + print "Bot is not running, cannot restart!" + elif (sys.argv[1] == 'status'): + print red + "Bot is not running!" +nocol + else: + print usage + exit else: - print error3 - exit + print "{1|start} {2|stop} {3|restart} {4|status} {5|exit}" + read = int(raw_input('Please choose a option: ')) + if read == 1: + command = start + print "Starting with: " + command + elif read == 2: + print "Bot is not running, cannot stop!" + elif read == 3: + command = restart + elif read == 4: + print red + "Bot is not running, cannot restart!" + nocol + elif read == 5: + print quit + else: + print error3 + exit except (TypeError, ValueError): print error3 exit From 30726de5ba937d3f84792278baa37c4599ad5255 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 10:38:50 -0800 Subject: [PATCH 06/12] Tweaked errors, pep8 --- cloudbot | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cloudbot b/cloudbot index 8d4cc18..c0d42f1 100755 --- a/cloudbot +++ b/cloudbot @@ -5,17 +5,16 @@ import os import subprocess import re -usage = "usage: ./cloudbot {start|stop|restart|status}" -quit = "Goodbye! Thanks for using CloudBot!" - -pwd = os.getcwd() -clearlog = ": >./bot.log && " -command = ":" - nocol = "\033[1;m" red = "\033[1;31m" green = "\033[1;32m" +usage = "usage: ./cloudbot {start|stop|restart|status}" +quit = nocol + "Goodbye! Thanks for using CloudBot!" + +pwd = os.getcwd() +clearlog = ": >./bot.log && " + daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) screencheck = subprocess.check_output("locate /usr/bin/screen", shell=True) @@ -29,7 +28,7 @@ except (subprocess.CalledProcessError): running = False error1 = red + "Neither screen nor daemon is installed! "\ - "This script cannot run! {ERROR 1}" + nocol + "This program cannot run! {ERROR 1}" + nocol error2 = red + "Could not find bot.py! Are you in the wrong folder? "\ "(" + pwd + ") {ERROR 2}" + nocol error3 = red + "Invalid choice, exiting! {ERROR 3}" + nocol @@ -45,16 +44,16 @@ if daemon: "/bot.log -r python " + pwd + "/bot.py" stop = clearlog + "daemon -n cloudbot --stop" restart = stop + " && " + start - pid = subprocess.check_output("pidof /usr/bin/daemon", shell=True) + pid = "pidof /usr/bin/daemon" elif screen: start = "screen -S cloudbot -dm python" + pwd +\ "/bot.py >>" + pwd + "/bot.log 2>&1" stop = clearlog + "kill `pidof /usr/bin/screen`" restart = stop + " && " + start - pid = subprocess.check_output("pidof /usr/bin/screen", shell=True) + pid = "pidof /usr/bin/screen" else: - print error1 - + command = ":" + print " ______ __ ______ __ __ "\ " _______ .______ ______ .___________." print " / || | / __ \ | | | | "\ @@ -81,7 +80,8 @@ try: command = restart print "Restarting with: " + command elif (sys.argv[1] == 'status'): - print green + "Bot is running! " + pid + nocol + command = pid + print green + "Bot is running! " + nocol else: print usage exit @@ -97,7 +97,8 @@ try: command = restart print "Restarting with: " + command elif read == 4: - print green + "Bot is running! " + pid + nocol + command = pid + print green + "Bot is running! " + nocol elif read == 5: print quit else: @@ -112,7 +113,7 @@ try: elif (sys.argv[1] == 'restart'): print "Bot is not running, cannot restart!" elif (sys.argv[1] == 'status'): - print red + "Bot is not running!" +nocol + print red + "Bot is not running!" + nocol else: print usage exit From cbe02f005a3c8c450711127ddb920f39b95b24a5 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 11:01:31 -0800 Subject: [PATCH 07/12] Added config! --- cloudbot | 56 ++++++++++++++++++++++++++++++++++++-------------- core/config.py | 4 ++++ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/cloudbot b/cloudbot index c0d42f1..63ecccb 100755 --- a/cloudbot +++ b/cloudbot @@ -4,6 +4,11 @@ import sys import os import subprocess import re +import json +try: + config = json.load(open('config')) +except ValueError, e: + print 'error: malformed config', e nocol = "\033[1;m" red = "\033[1;31m" @@ -19,6 +24,7 @@ daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) screencheck = subprocess.check_output("locate /usr/bin/screen", shell=True) screen = re.match(r'^/usr/bin/screen$', screencheck) +backgrounder = config.get("wrapper", {}).get("backgrounder", "daemon") try: runningcheck = subprocess.check_output("ps ax|grep cloudbot|"\ @@ -33,24 +39,44 @@ error2 = red + "Could not find bot.py! Are you in the wrong folder? "\ "(" + pwd + ") {ERROR 2}" + nocol error3 = red + "Invalid choice, exiting! {ERROR 3}" + nocol error4 = red + "Program killed by user! {ERROR 4}" + nocol -error5 = red + "Author error! We be derpin'! {ERROR 5}" + nocol +error5 = red + "Invalid backgrounder in config! {ERROR 5}" + nocol +error6 = red + "Author error! We be derpin'! {ERROR 6}" + nocol start = "echo " + error1 stop = "echo " + error1 restart = "echo " + error1 +pid = "echo 'Cannot get pid'" if daemon: - start = "daemon -n cloudbot -O " + pwd + \ - "/bot.log -r python " + pwd + "/bot.py" - stop = clearlog + "daemon -n cloudbot --stop" - restart = stop + " && " + start - pid = "pidof /usr/bin/daemon" -elif screen: - start = "screen -S cloudbot -dm python" + pwd +\ + if backgrounder == "daemon": + start = "daemon -n cloudbot -O " + pwd + \ + "/bot.log -r python " + pwd + "/bot.py" + stop = clearlog + "daemon -n cloudbot --stop" + restart = stop + " && " + start + pid = "pidof /usr/bin/daemon" + elif backgrounder == "screen": + start = "screen -S cloudbot -dm python" + pwd +\ "/bot.py >>" + pwd + "/bot.log 2>&1" - stop = clearlog + "kill `pidof /usr/bin/screen`" - restart = stop + " && " + start - pid = "pidof /usr/bin/screen" + stop = clearlog + "kill `pidof /usr/bin/screen`" + restart = stop + " && " + start + pid = "pidof /usr/bin/screen" + else: + print error5 +elif screen: + if backgrounder == "daemon": + start = "daemon -n cloudbot -O " + pwd + \ + "/bot.log -r python " + pwd + "/bot.py" + stop = clearlog + "daemon -n cloudbot --stop" + restart = stop + " && " + start + pid = "pidof /usr/bin/daemon" + elif backgrounder == "screen": + start = "screen -S cloudbot -dm python" + pwd +\ + "/bot.py >>" + pwd + "/bot.log 2>&1" + stop = clearlog + "kill `pidof /usr/bin/screen`" + restart = stop + " && " + start + pid = "pidof /usr/bin/screen" + else: + print error5 else: command = ":" @@ -134,14 +160,14 @@ try: else: print error3 exit -except (TypeError, ValueError): +except (TypeError, ValueError), e: print error3 exit -except (KeyboardInterrupt): +except (KeyboardInterrupt), e: print error4 exit -except (NameError, SyntaxError): - print error5 +except (NameError, SyntaxError), e: + print error6 exit if os.path.isfile("./bot.py"): diff --git a/core/config.py b/core/config.py index 72f41d6..431a867 100755 --- a/core/config.py +++ b/core/config.py @@ -41,6 +41,10 @@ if not os.path.exists('config'): "mc_user": "INSERT MINECRAFT USERNAME HERE", "mc_pass": "INSERT MINECRAFT PASSWORD HERE" }, + "wrapper": + { + "backgrounder": "screen" + }, "censored_strings": [ "mypass", From 068f97005db94461503be3da17d546f370f3805a Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 11:11:10 -0800 Subject: [PATCH 08/12] fixed backgrounder code, added default, and made start/stop specify backend --- cloudbot | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cloudbot b/cloudbot index 63ecccb..26f0f81 100755 --- a/cloudbot +++ b/cloudbot @@ -19,6 +19,7 @@ quit = nocol + "Goodbye! Thanks for using CloudBot!" pwd = os.getcwd() clearlog = ": >./bot.log && " +command = ":" daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) @@ -78,8 +79,8 @@ elif screen: else: print error5 else: - command = ":" - + command = command + print " ______ __ ______ __ __ "\ " _______ .______ ______ .___________." print " / || | / __ \ | | | | "\ @@ -101,10 +102,10 @@ try: print "Bot is alread running, cannot start!" elif (sys.argv[1] == 'stop'): command = stop - print "Stopping with: " + command + print "Stopping... (" + backgrounder + ")" elif (sys.argv[1] == 'restart'): command = restart - print "Restarting with: " + command + print "Restarting... (" + backgrounder + ")" elif (sys.argv[1] == 'status'): command = pid print green + "Bot is running! " + nocol @@ -118,10 +119,10 @@ try: print "Bot is alread running, cannot start!" elif read == 2: command = stop - print "Stopping with: " + command + print "Stopping... (" + backgrounder + ")" elif read == 3: command = restart - print "Restarting with: " + command + print "Restarting... (" + backgrounder + ")" elif read == 4: command = pid print green + "Bot is running! " + nocol @@ -133,7 +134,7 @@ try: if (len(sys.argv) > 1): if (sys.argv[1] == 'start'): command = start - print "Starting with: " + command + print "Starting... (" + backgrounder + ")" elif (sys.argv[1] == 'stop'): print "Bot is not running, cannot stop!" elif (sys.argv[1] == 'restart'): @@ -148,7 +149,7 @@ try: read = int(raw_input('Please choose a option: ')) if read == 1: command = start - print "Starting with: " + command + print "Starting... (" + backgrounder + ")" elif read == 2: print "Bot is not running, cannot stop!" elif read == 3: From 7d545fd10065c78aa9b6f02a8e2f078f7a547078 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 11:12:23 -0800 Subject: [PATCH 09/12] renamed function from backgrounder to backend --- cloudbot | 24 ++++++++++++------------ core/config.py | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cloudbot b/cloudbot index 26f0f81..2308667 100755 --- a/cloudbot +++ b/cloudbot @@ -25,7 +25,7 @@ daemoncheck = subprocess.check_output("locate /usr/bin/daemon", shell=True) daemon = re.match(r'^/usr/bin/daemon$', daemoncheck) screencheck = subprocess.check_output("locate /usr/bin/screen", shell=True) screen = re.match(r'^/usr/bin/screen$', screencheck) -backgrounder = config.get("wrapper", {}).get("backgrounder", "daemon") +backend = config.get("wrapper", {}).get("backend", "daemon") try: runningcheck = subprocess.check_output("ps ax|grep cloudbot|"\ @@ -40,7 +40,7 @@ error2 = red + "Could not find bot.py! Are you in the wrong folder? "\ "(" + pwd + ") {ERROR 2}" + nocol error3 = red + "Invalid choice, exiting! {ERROR 3}" + nocol error4 = red + "Program killed by user! {ERROR 4}" + nocol -error5 = red + "Invalid backgrounder in config! {ERROR 5}" + nocol +error5 = red + "Invalid backend in config! {ERROR 5}" + nocol error6 = red + "Author error! We be derpin'! {ERROR 6}" + nocol start = "echo " + error1 @@ -49,13 +49,13 @@ restart = "echo " + error1 pid = "echo 'Cannot get pid'" if daemon: - if backgrounder == "daemon": + if backend == "daemon": start = "daemon -n cloudbot -O " + pwd + \ "/bot.log -r python " + pwd + "/bot.py" stop = clearlog + "daemon -n cloudbot --stop" restart = stop + " && " + start pid = "pidof /usr/bin/daemon" - elif backgrounder == "screen": + elif backend == "screen": start = "screen -S cloudbot -dm python" + pwd +\ "/bot.py >>" + pwd + "/bot.log 2>&1" stop = clearlog + "kill `pidof /usr/bin/screen`" @@ -64,13 +64,13 @@ if daemon: else: print error5 elif screen: - if backgrounder == "daemon": + if backend == "daemon": start = "daemon -n cloudbot -O " + pwd + \ "/bot.log -r python " + pwd + "/bot.py" stop = clearlog + "daemon -n cloudbot --stop" restart = stop + " && " + start pid = "pidof /usr/bin/daemon" - elif backgrounder == "screen": + elif backend == "screen": start = "screen -S cloudbot -dm python" + pwd +\ "/bot.py >>" + pwd + "/bot.log 2>&1" stop = clearlog + "kill `pidof /usr/bin/screen`" @@ -102,10 +102,10 @@ try: print "Bot is alread running, cannot start!" elif (sys.argv[1] == 'stop'): command = stop - print "Stopping... (" + backgrounder + ")" + print "Stopping... (" + backend + ")" elif (sys.argv[1] == 'restart'): command = restart - print "Restarting... (" + backgrounder + ")" + print "Restarting... (" + backend + ")" elif (sys.argv[1] == 'status'): command = pid print green + "Bot is running! " + nocol @@ -119,10 +119,10 @@ try: print "Bot is alread running, cannot start!" elif read == 2: command = stop - print "Stopping... (" + backgrounder + ")" + print "Stopping... (" + backend + ")" elif read == 3: command = restart - print "Restarting... (" + backgrounder + ")" + print "Restarting... (" + backend + ")" elif read == 4: command = pid print green + "Bot is running! " + nocol @@ -134,7 +134,7 @@ try: if (len(sys.argv) > 1): if (sys.argv[1] == 'start'): command = start - print "Starting... (" + backgrounder + ")" + print "Starting... (" + backend + ")" elif (sys.argv[1] == 'stop'): print "Bot is not running, cannot stop!" elif (sys.argv[1] == 'restart'): @@ -149,7 +149,7 @@ try: read = int(raw_input('Please choose a option: ')) if read == 1: command = start - print "Starting... (" + backgrounder + ")" + print "Starting... (" + backend + ")" elif read == 2: print "Bot is not running, cannot stop!" elif read == 3: diff --git a/core/config.py b/core/config.py index 431a867..6159b90 100755 --- a/core/config.py +++ b/core/config.py @@ -43,7 +43,7 @@ if not os.path.exists('config'): }, "wrapper": { - "backgrounder": "screen" + "backend": "screen" }, "censored_strings": [ From d453dfefb79363dd3ca2bbdad904fcbca86305a1 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 11:13:20 -0800 Subject: [PATCH 10/12] whoops, forgot to change default --- core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/config.py b/core/config.py index 6159b90..96f2302 100755 --- a/core/config.py +++ b/core/config.py @@ -43,7 +43,7 @@ if not os.path.exists('config'): }, "wrapper": { - "backend": "screen" + "backend": "daemon" }, "censored_strings": [ From 13990495e60ac67ecf633a92efc6c7a8830b12a6 Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 11:14:10 -0800 Subject: [PATCH 11/12] Changed README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index abb56f9..df71b1c 100755 --- a/README.md +++ b/README.md @@ -48,13 +48,13 @@ In addition, for `.whois` to work optimally, you must have `whois` installed. Ag If you are a user of another Linux disto, use your package manager to install the dependencies, or, for other operating systems, use **Google** to locate source packages you can install. -Once you have installed the required dependencies, run the bot with +Once you have installed the required dependencies, run the wrapper -`python bot.py` +`python cloudbot` It will generate a default config for you. Once you have edited the config, run it again with -`python bot.py` +`python cloudbot` and it will connect to any server(s) you have added to the config. (Config docs at the [wiki](http://git.io/cloudbotconfig)) From cf7ea53c5d8e13f908e8cba27dcf0f8e0a96190e Mon Sep 17 00:00:00 2001 From: neersighted Date: Wed, 29 Feb 2012 11:42:56 -0800 Subject: [PATCH 12/12] updated Gitignore --- .gitignore | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 3f2e438..bd69f72 100755 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,7 @@ +persist +config +*.db +*.log .*.swp *.pyc *.orig -persist -config -pep8.py -.project -.pydevproject -*.db -web -control.sh -bot.log \ No newline at end of file