def main(): configfilename = "/etc/spade/spade.xml" jabberxml = "/etc/spade/xmppd.xml" if sys.platform[:6] == 'netbsd': configfilename = os.sep + "usr" + os.sep + "pkg" + configfilename jabberxml = os.sep + "usr" + os.sep + "pkg" + jabberxml web = False if len(sys.argv) < 2: pass elif sys.argv[1] in ["--help", "-h"]: print_help() elif sys.argv[1] in ["--version", "-v"]: print_version() #elif sys.argv[1] in ["--web", "-w"]: web = True dbg = [] if os.name != "posix" or not os.path.exists(jabberxml) or not os.path.exists(configfilename): configfilename = "spade.xml" configfilename = os.path.abspath(configfilename) jabberxml = "xmppd.xml" jabberxml = os.path.abspath(jabberxml) try: for opt, arg in getopt(sys.argv[1:], "hvdwc:j:", ["help", "version", "debug", "web", "configfile=", "jabber="])[0]: if opt in ["-h", "--help"]: print_help() elif opt in ["-v", "--version"]: print_version() elif opt in ["-c", "--configfile"]: configfilename = arg elif opt in ["-j", "--jabber"]: jabberxml = arg #elif opt in ["-w", "--web"]: web = True elif opt in ["-d", "--debug"]: dbg = ['always'] except: pass print "SPADE ", colors.color_yellow + __version__ + colors.color_none, " <*****@*****.**> - http://spade2.googlecode.com" try: import psyco psyco.full() #psyco.profile() except ImportError: pass # print "W: Psyco optimizing compiler not found." sys.stdout.write("Starting SPADE") sys.stdout.flush() sys.stdout.write(".") sys.stdout.flush() jabberxml = os.path.abspath(jabberxml) if not os.path.exists(jabberxml): print '\n There is no jabber config file (xmppd.xml)' + colors.color_red + " [failed]" + colors.color_none print_help() raise SystemExit if sys.platform[:6] == 'netbsd': pyvers = 'python' + str(numb) path = "/usr/pkg/lib" + os.sep + pyvers + "/site-packages/xmppd/" os.chdir(path) else: pass # os.chdir("xmppd") s = Server(cfgfile=jabberxml, cmd_options={'enable_debug': dbg, 'enable_psyco': False}) sys.stdout.write(".") sys.stdout.flush() thread.start_new_thread(s.run, tuple()) try: sys.stdout.write(".") sys.stdout.flush() if not os.path.exists(configfilename): print '\n There is no SPADE config file (spade.xml)' + colors.color_red + " [failed]" + colors.color_none print_help() raise SystemExit if dbg==['always']: platform = spade_backend.SpadeBackend(s, configfilename, debug=True) else: platform = spade_backend.SpadeBackend(s, configfilename) sys.stdout.write(".") sys.stdout.flush() platform.start() sys.stdout.write(".") sys.stdout.flush() s.DEBUG = platform.DEBUG sys.stdout.write(".") sys.stdout.flush() except Exception, e: _exception = sys.exc_info() if _exception[0]: print '\n' + ''.join(traceback.format_exception(_exception[0], _exception[1], _exception[2])).rstrip() print str(e) print colors.color_red + " [failed]" + colors.color_none platform.shutdown() s.shutdown("Jabber server terminated...") raise SystemExit
def main(): configfilename = "/etc/spade/spade.xml" jabberxml = "/etc/spade/xmppd.xml" if sys.platform[:6] == 'netbsd': configfilename = os.sep + "usr" + os.sep + "pkg" + configfilename jabberxml = os.sep + "usr" + os.sep + "pkg" + jabberxml web = False if len(sys.argv) < 2: pass elif sys.argv[1] in ["--help", "-h"]: print_help() elif sys.argv[1] in ["--version", "-v"]: print_version() #elif sys.argv[1] in ["--web", "-w"]: web = True dbg = [] if os.name != "posix" or not os.path.exists( jabberxml) or not os.path.exists(configfilename): configfilename = "spade.xml" configfilename = os.path.abspath(configfilename) jabberxml = "xmppd.xml" jabberxml = os.path.abspath(jabberxml) try: for opt, arg in getopt( sys.argv[1:], "hvdwc:j:", ["help", "version", "debug", "web", "configfile=", "jabber="])[0]: if opt in ["-h", "--help"]: print_help() elif opt in ["-v", "--version"]: print_version() elif opt in ["-c", "--configfile"]: configfilename = arg elif opt in ["-j", "--jabber"]: jabberxml = arg #elif opt in ["-w", "--web"]: web = True elif opt in ["-d", "--debug"]: dbg = ['always'] except: pass print "SPADE ", colors.color_yellow + __version__ + colors.color_none, " <*****@*****.**> - https://github.com/javipalanca/SPADE" try: import psyco psyco.full() #psyco.profile() except ImportError: pass # print "W: Psyco optimizing compiler not found." sys.stdout.write("Starting SPADE") sys.stdout.flush() sys.stdout.write(".") sys.stdout.flush() jabberxml = os.path.abspath(jabberxml) if not os.path.exists(jabberxml): print '\n There is no jabber config file (xmppd.xml)' + colors.color_red + " [failed]" + colors.color_none print_help() raise SystemExit if sys.platform[:6] == 'netbsd': pyvers = 'python' + str(numb) path = "/usr/pkg/lib" + os.sep + pyvers + "/site-packages/xmppd/" os.chdir(path) else: pass # os.chdir("xmppd") s = Server(cfgfile=jabberxml, cmd_options={ 'enable_debug': dbg, 'enable_psyco': False }) sys.stdout.write(".") sys.stdout.flush() thread.start_new_thread(s.run, tuple()) try: sys.stdout.write(".") sys.stdout.flush() if not os.path.exists(configfilename): print '\n There is no SPADE config file (spade.xml)' + colors.color_red + " [failed]" + colors.color_none print_help() raise SystemExit if dbg == ['always']: platform = spade_backend.SpadeBackend(s, configfilename, debug=True) else: platform = spade_backend.SpadeBackend(s, configfilename) sys.stdout.write(".") sys.stdout.flush() platform.start() sys.stdout.write(".") sys.stdout.flush() s.DEBUG = platform.DEBUG sys.stdout.write(".") sys.stdout.flush() except Exception, e: _exception = sys.exc_info() if _exception[0]: print '\n' + ''.join( traceback.format_exception(_exception[0], _exception[1], _exception[2])).rstrip() print str(e) print colors.color_red + " [failed]" + colors.color_none platform.shutdown() s.shutdown("Jabber server terminated...") raise SystemExit
def main(): configfilename = "/etc/spade/spade.xml" jabberxml = "/etc/spade/xmppd.xml" if sys.platform[:6] == 'netbsd': configfilename = os.sep + "usr" + os.sep + "pkg" + configfilename jabberxml = os.sep + "usr" + os.sep + "pkg" + jabberxml web = False if len(sys.argv) < 2: pass elif sys.argv[1] in ["--help", "-h"]: print_help() elif sys.argv[1] in ["--version", "-v"]: print_version() #elif sys.argv[1] in ["--web", "-w"]: web = True dbg = [] if os.name != "posix" or not os.path.exists(jabberxml) or not os.path.exists(configfilename): configfilename = "spade.xml" configfilename = os.path.abspath(configfilename) jabberxml = "xmppd.xml" jabberxml = os.path.abspath(jabberxml) try: for opt, arg in getopt(sys.argv[1:], "hvdwc:j:", ["help", "version", "debug", "web", "configfile=", "jabber="])[0]: if opt in ["-h", "--help"]: print_help() elif opt in ["-v", "--version"]: print_version() elif opt in ["-c", "--configfile"]: configfilename = arg elif opt in ["-j", "--jabber"]: jabberxml = arg #elif opt in ["-w", "--web"]: web = True elif opt in ["-d", "--debug"]: dbg = ['always'] except: pass print(("SPADE ", colors.color_yellow + __version__ + colors.color_none, " <*****@*****.**> - http://spade2.googlecode.com")) try: import psyco psyco.full() #psyco.profile() except ImportError: pass # print "W: Psyco optimizing compiler not found." sys.stdout.write("Starting SPADE") sys.stdout.flush() sys.stdout.write(".") sys.stdout.flush() jabberxml = os.path.abspath(jabberxml) if not os.path.exists(jabberxml): print(('\n There is no jabber config file (xmppd.xml)' + colors.color_red + " [failed]" + colors.color_none)) print_help() raise SystemExit if sys.platform[:6] == 'netbsd': pyvers = 'python' + str(numb) path = "/usr/pkg/lib" + os.sep + pyvers + "/site-packages/xmppd/" os.chdir(path) else: pass # os.chdir("xmppd") s = Server(cfgfile=jabberxml, cmd_options={'enable_debug': dbg, 'enable_psyco': False}) sys.stdout.write(".") sys.stdout.flush() _thread.start_new_thread(s.run, tuple()) try: sys.stdout.write(".") sys.stdout.flush() if not os.path.exists(configfilename): print(('\n There is no SPADE config file (spade.xml)' + colors.color_red + " [failed]" + colors.color_none)) print_help() raise SystemExit if dbg==['always']: platform = spade_backend.SpadeBackend(s, configfilename, debug=True) else: platform = spade_backend.SpadeBackend(s, configfilename) sys.stdout.write(".") sys.stdout.flush() platform.start() sys.stdout.write(".") sys.stdout.flush() s.DEBUG = platform.DEBUG sys.stdout.write(".") sys.stdout.flush() except Exception as e: _exception = sys.exc_info() if _exception[0]: print(('\n' + ''.join(traceback.format_exception(_exception[0], _exception[1], _exception[2])).rstrip())) print((str(e))) print((colors.color_red + " [failed]" + colors.color_none)) platform.shutdown() s.shutdown("Jabber server terminated...") raise SystemExit print((colors.color_green + " [done]" + colors.color_none)) if platform.acc.wui: print(("\n " + colors.color_yellow + " [info] " + colors.color_none + "WebUserInterface serving at port " + str(platform.acc.wui.port) + "\n ")) alive = True while alive: try: time.sleep(1) if not platform.alive: #The platform died (probable restart). Let's start it over platform.shutdown() print(("\n " + colors.color_green + "SPADE Platform restarting..." + colors.color_none)) platform.start() print((colors.color_green + " [done]" + colors.color_none)) except KeyboardInterrupt: alive = False sys.stdout.write("Exiting") sys.stdout.flush() platform.shutdown() sys.stdout.write(".") sys.stdout.flush() s.shutdown("SPADE Jabber server terminated...") sys.stdout.write(".") sys.stdout.flush() time.sleep(1) del s sys.stdout.write(".") sys.stdout.flush() print((colors.color_green + " Bye." + colors.color_none)) #raise SystemExit sys.exit(0)