Exemple #1
0
    def __init__(self, args=None):

        if args is None:
            args = sys.argv[1:]

        p = argparse.ArgumentParser(prog='XDM')
        p.add_argument('-d', '--daemonize', action="store_true", dest='daemonize', help="Run the server as a daemon.")
        p.add_argument('-v', '--version', action="store_true", dest='version', help="Print Version and exit.")
        p.add_argument('-D', '--debug', action="store_true", dest='debug', help="Print debug log to screen.")
        p.add_argument('-p', '--pidfile', dest='pidfile', default=None, help="Store the process id in the given file.")
        p.add_argument('-P', '--port', dest='port', type=int, default=None, help="Force webinterface to listen on this port.")
        p.add_argument('-n', '--nolaunch', action="store_true", dest='nolaunch', help="Don't start the browser.")
        p.add_argument('-b', '--datadir', dest='datadir', default=None, help="Set the directory for created data.")
        p.add_argument('--config_db', dest='config_db', default=None, help="Path to config database")
        p.add_argument('--data_db', dest='data_db', default=None, help="Path to data database")
        p.add_argument('--history_db', dest='history_db', default=None, help="Path to history database")
        p.add_argument('--dev', action="store_true", dest='dev', default=None, help="Developer mode. Disables the censoring during log and the plugin manager follows symlinks")
        p.add_argument('--noApi', action="store_true", dest='noApi', default=None, help="Disable the api")
        p.add_argument('--apiPort', dest='apiPort', type=int, default=None, help="Port the api runs on")
        p.add_argument('--noWebServer', action="store_true", dest='noWebServer', help="Don't start the webserver")
        p.add_argument('--pluginImportDebug', action="store_true", dest='pluginImportDebug', help="Extra verbosy debug during plugin import is printed.")
        p.add_argument('--profile', dest='profile', nargs='*', default=None, help="Wrap a decorated(!) function in a profiler. By default all decorated functions are profiled. Decorate your function with @profileMeMaybe")

        options = p.parse_args(args)
        self.options = options
        common.STARTOPTIONS = options

        if options.version:
            print common.getVersionHuman()
            exit()
        log.info('Starting XDM %s' % common.getVersionHuman())

        #Set the Paths
        if options.datadir:
            datadir = options.datadir
            if not os.path.isdir(datadir):
                os.makedirs(datadir)
        elif hasattr(sys, 'frozen'):
            datadir = helper.getSystemDataDir(app_path)
            if not os.path.isdir(datadir):
                os.makedirs(datadir)
        else:
            datadir = app_path
        datadir = os.path.abspath(datadir)

        if not os.access(datadir, os.W_OK):
            raise SystemExit("Data dir must be writeable '" + datadir + "'")

        # setup file logger with datadir
        xdm.LOGPATH = os.path.join(datadir, xdm.LOGFILE)
        hdlr = logging.handlers.RotatingFileHandler(xdm.LOGPATH, maxBytes=10 * 1024 * 1024, backupCount=5)
        xdm.logger.fLogger.addHandler(hdlr)
        log.info("Logfile path is %s" % xdm.LOGPATH)
        

        # Daemonize
        if options.daemonize:
            if sys.platform == 'win32':
                log.error("Daemonize not supported under Windows, starting normally")
            else:
                log.info("Preparing to run in daemon mode")
                logger.cLogger.setLevel(logging.CRITICAL)
                daemonize()

        # Debug
        if options.debug:
            logger.cLogger.setLevel(logging.DEBUG)
            log.info('XDM Debug mode ON')
        # Profile
        if options.profile is not None:
            log.info('XDM profiling mode ON')
            common.RUNPROFILER = True

        # PIDfile
        if options.pidfile:
            log.info("Set PIDfile to %s" % options.pidfile)
            PIDFile(cherrypy.engine, options.pidfile).subscribe()
        if options.pidfile:
            pid = str(os.getpid())
            log(u"Writing PID %s to %s" % (pid, options.pidfile))
            file(os.path.abspath(options.pidfile), 'w').write("%s\n" % pid)

        init.preDB(app_path, datadir)
        init.db()
        init.postDB()
        init.schedule()
        init.runTasks()

        # Set port
        if options.port:
            log.info("Port manual set to %d" % (options.port))
            port = options.port
            server.socket_port = port
        else:
            port = common.SYSTEM.c.port
            server.socket_port = port
        self.port = server.socket_port
        # Set api port
        if options.apiPort:
            log.info("Api port manual set to %d" % (options.apiPort))
            self.port_api = options.apiPort
        else:
            self.port_api = common.SYSTEM.c.port_api

        # update config for cherrypy
        cherrypy.config.update({'global': {'server.socket_port': port}})
Exemple #2
0
    def __init__(self):

        p = argparse.ArgumentParser(prog='XDM')
        p.add_argument('-d', '--daemonize', action="store_true", dest='daemonize', help="Run the server as a daemon.")
        p.add_argument('-v', '--version', action="store_true", dest='version', help="Print Version and exit.")
        p.add_argument('-D', '--debug', action="store_true", dest='debug', help="Print debug log to screen.")
        p.add_argument('-p', '--pidfile', dest='pidfile', default=None, help="Store the process id in the given file.")
        p.add_argument('-P', '--port', dest='port', default=None, help="Force webinterface to listen on this port.")
        p.add_argument('-n', '--nolaunch', action="store_true", dest='nolaunch', help="Don't start the browser.")
        p.add_argument('-b', '--datadir', dest='datadir', default=None, help="Set the directory for the database.")
        p.add_argument('-c', '--config', dest='config', default=None, help="Path to config file")
        p.add_argument('--dev', action="store_true", dest='dev', default=None, help="Developer mode. Disables the censoring during log and the plugin manager follows symlinks")
        p.add_argument('--noApi', action="store_true", dest='noApi', default=None, help="Disable the api")
        p.add_argument('--apiPort', dest='apiPort', default=None, help="Port the api runs on")
        p.add_argument('--noWebServer', action="store_true", dest='noWebServer', help="Port the api runs on")
        p.add_argument('--pluginImportDebug', action="store_true", dest='pluginImportDebug', help="Extra verbosy debug during plugin import is printed.")
        p.add_argument('--profile', dest='profile', nargs='*', default=None, help="Wrap a decorated(!) function in a profiler. By default all decorated functions are profiled. Decorate your function with @profileMeMaybe")

        options = p.parse_args()
        self.options = options
        common.STARTOPTIONS = options

        if options.version:
            print common.getVersionHuman()
            exit()
        log.info('Starting XDM %s' % common.getVersionHuman())

        #Set the Paths
        if options.datadir:
            datadir = options.datadir
            if not os.path.isdir(datadir):
                os.makedirs(datadir)
        elif hasattr(sys, 'frozen'):
            datadir = helper.getSystemDataDir(app_path)
            if not os.path.isdir(datadir):
                os.makedirs(datadir)
        else:
            datadir = app_path
        datadir = os.path.abspath(datadir)

        if not os.access(datadir, os.W_OK):
            raise SystemExit("Data dir must be writeable '" + datadir + "'")

        # setup file logger with datadir
        hdlr = logging.handlers.RotatingFileHandler(os.path.join(datadir, 'xdm.log'), maxBytes=10 * 1024 * 1024, backupCount=5)
        xdm.logger.fLogger.addHandler(hdlr)


        #TODO: rewrite for the config.db
        """if options.config:
            config_path = options.config
        else:
            config_path = os.path.join(datadir, 'Gamez.ini')"""

        # Daemonize
        if options.daemonize:
            if sys.platform == 'win32':
                print "Daemonize not supported under Windows, starting normally"
            else:
                print "------------------- Preparing to run in daemon mode (screen logging is now OFF) -------------------"
                log.info("Preparing to run in daemon mode")
                logger.cLogger.setLevel(logging.CRITICAL)
                daemonize()

        # Debug
        if options.debug:
            print "------------------- XDM Debug Messages ON -------------------"
            logger.cLogger.setLevel(logging.DEBUG)
            log.info('XDM Debug mode ON')
        # Profile
        if options.profile is not None:
            print "------------------- XDM Profiling ON -------------------"
            log.info('XDM profiling mode ON')
            common.RUNPROFILER = True
            print common.RUNPROFILER

        init.preDB(app_path, datadir)
        init.db()
        init.postDB()
        init.schedule()
        init.runTasks()

        self.pluginResPaths = {}
        for pType, path in common.PM.path_cache.items():
            self.pluginResPaths['/' + pType] = {'tools.staticdir.on': True, 'tools.staticdir.dir': os.path.abspath(path)}

        # Set port
        if options.port:
            print "------------------- Port manual set to " + options.port + " -------------------"
            port = int(options.port)
            server.socket_port = port
        else:
            port = common.SYSTEM.c.port
            server.socket_port = port
        self.port = server.socket_port
        # Set api port
        if options.apiPort:
            print "------------------- Api port manual set to " + options.apiPort + " -------------------"
            self.port_api = int(options.apiPort)
        else:
            self.port_api = common.SYSTEM.c.port_api

        # PIDfile
        if options.pidfile:
            print "------------------- Set PIDfile to " + options.pidfile + " -------------------"
            PIDFile(cherrypy.engine, options.pidfile).subscribe()


        # update config for cherrypy
        cherrypy.config.update({'global': {'server.socket_port': port}})
Exemple #3
0
    def __init__(self):

        p = argparse.ArgumentParser(prog='XDM')
        p.add_argument('-d',
                       '--daemonize',
                       action="store_true",
                       dest='daemonize',
                       help="Run the server as a daemon.")
        p.add_argument('-v',
                       '--version',
                       action="store_true",
                       dest='version',
                       help="Print Version and exit.")
        p.add_argument('-D',
                       '--debug',
                       action="store_true",
                       dest='debug',
                       help="Print debug log to screen.")
        p.add_argument('-p',
                       '--pidfile',
                       dest='pidfile',
                       default=None,
                       help="Store the process id in the given file.")
        p.add_argument('-P',
                       '--port',
                       dest='port',
                       default=None,
                       help="Force webinterface to listen on this port.")
        p.add_argument('-n',
                       '--nolaunch',
                       action="store_true",
                       dest='nolaunch',
                       help="Don't start the browser.")
        p.add_argument('-b',
                       '--datadir',
                       dest='datadir',
                       default=None,
                       help="Set the directory for the database.")
        p.add_argument('-c',
                       '--config',
                       dest='config',
                       default=None,
                       help="Path to config file")
        p.add_argument('--noApi',
                       action="store_true",
                       dest='noApi',
                       default=None,
                       help="Disable the api")
        p.add_argument('--apiPort',
                       dest='apiPort',
                       default=None,
                       help="Port the api runs on")
        p.add_argument('--noWebServer',
                       action="store_true",
                       dest='noWebServer',
                       help="Port the api runs on")
        p.add_argument(
            '--pluginImportDebug',
            action="store_true",
            dest='pluginImportDebug',
            help="Extra verbosy debug during plugin import is printed.")
        p.add_argument(
            '--profile',
            dest='profile',
            nargs='*',
            default=None,
            help=
            "Wrap a decorated(!) function in a profiler. By default all decorated functions are profiled. Decorate your function with @profileMeMaybe"
        )

        options = p.parse_args()
        self.options = options
        common.STARTOPTIONS = options

        if options.version:
            print common.getVersionHuman()
            exit()
        log.info('Starting XDM %s' % common.getVersionHuman())

        #Set the Paths
        if options.datadir:
            datadir = options.datadir
            if not os.path.isdir(datadir):
                os.makedirs(datadir)
        elif hasattr(sys, 'frozen'):
            datadir = helper.getSystemDataDir(app_path)
            if not os.path.isdir(datadir):
                os.makedirs(datadir)
        else:
            datadir = app_path
        datadir = os.path.abspath(datadir)

        if not os.access(datadir, os.W_OK):
            raise SystemExit("Data dir must be writeable '" + datadir + "'")

        # setup file logger with datadir
        hdlr = logging.handlers.RotatingFileHandler(os.path.join(
            datadir, 'xdm.log'),
                                                    maxBytes=10 * 1024 * 1024,
                                                    backupCount=5)
        xdm.logger.fLogger.addHandler(hdlr)

        #TODO: rewrite for the config.db
        """if options.config:
            config_path = options.config
        else:
            config_path = os.path.join(datadir, 'Gamez.ini')"""

        # Daemonize
        if options.daemonize:
            if sys.platform == 'win32':
                print "Daemonize not supported under Windows, starting normally"
            else:
                print "------------------- Preparing to run in daemon mode (screen logging is now OFF) -------------------"
                log.info("Preparing to run in daemon mode")
                logger.cLogger.setLevel(logging.CRITICAL)
                daemonize()

        # Debug
        if options.debug:
            print "------------------- XDM Debug Messages ON -------------------"
            logger.cLogger.setLevel(logging.DEBUG)
            log.info('XDM Debug mode ON')
        # Profile
        if options.profile is not None:
            print "------------------- XDM Profiling ON -------------------"
            log.info('XDM profiling mode ON')
            common.RUNPROFILER = True
            print common.RUNPROFILER

        init.preDB(app_path, datadir)
        init.db()
        init.postDB()
        init.schedule()
        init.runTasks()

        self.pluginResPaths = {}
        for pType, path in common.PM.path_cache.items():
            self.pluginResPaths['/' + pType] = {
                'tools.staticdir.on': True,
                'tools.staticdir.dir': os.path.abspath(path)
            }

        # Set port
        if options.port:
            print "------------------- Port manual set to " + options.port + " -------------------"
            port = int(options.port)
            server.socket_port = port
        else:
            port = common.SYSTEM.c.port
            server.socket_port = port
        self.port = server.socket_port
        # Set api port
        if options.apiPort:
            print "------------------- Api port manual set to " + options.apiPort + " -------------------"
            self.port_api = int(options.apiPort)
        else:
            self.port_api = common.SYSTEM.c.port_api

        # PIDfile
        if options.pidfile:
            print "------------------- Set PIDfile to " + options.pidfile + " -------------------"
            PIDFile(cherrypy.engine, options.pidfile).subscribe()

        # update config for cherrypy
        cherrypy.config.update({'global': {'server.socket_port': port}})