Exemplo n.º 1
0
Arquivo: XDM.py Projeto: chr1831/XDM
    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}})
Exemplo n.º 2
0
Arquivo: XDM.py Projeto: Torf/XDM
    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="version", version='%s' % common.getVersionHuman())
        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")
        p.add_argument('--installType', dest='installType', default=None, type=int, help="Force the install type")

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

        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)

        # 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)
        log.info("Logfile path is %s" % xdm.LOGPATH)
        init.db()
        init.postDB()
        init.schedule()

        # 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}})
Exemplo n.º 3
0
Arquivo: XDM.py Projeto: Trixter69/XDM
    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="version", version="%s" % common.getVersionHuman())
        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(
            "--configJSON",
            dest="configJSON",
            default=None,
            help="Set the path to the config JSON file (or folder with then) to read from",
        )
        p.add_argument(
            "--systemIdentifer",
            dest="systemIdentifer",
            default="de.lad1337.systemconfig",
            help="Set the identifier for the system plugin",
        )
        p.add_argument("--resetWizard", dest="reset_wizard", action="store_true", help="reset the wizard state")

        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",
        )
        p.add_argument("--installType", dest="installType", default=None, type=int, help="Force the install type")
        p.add_argument(
            "--config", dest="config", default=None, type=json.loads, help="Update the config with this json object"
        )

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

        log.info("Starting XDM %s" % common.getVersionHuman())

        if options.configJSON:
            config_files = []
            if os.path.isdir(options.configJSON):
                import glob

                config_files = [os.path.abspath(p) for p in glob.glob(os.path.join(options.configJSON, "*.json"))]
            else:
                config_files.append(os.path.abspath(options.configJSON))
            for config_file in config_files:
                log.info("Loading config from file {}".format(config_file))
                options = helper.spreadConfigsFromFile(options, config_file)

        if options.config:
            common.updateConfigOverwrite(options.config)

        # 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)

        # 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()
            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)
        log.info("Logfile path is %s" % xdm.LOGPATH)
        init.db()
        init.postDB()
        init.schedule()

        if options.reset_wizard:
            common.SYSTEM.hc.setup_wizard_step = 0

        # 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}})