def on_reload(ctx=None): for key in ('THEME', 'FS_HIDE_FILES', 'OPTION_STYLE', 'PAGE_OPEN', 'RECENT_SEARCH_LIMIT', "PAGE_SIZE", "RECENT_SIZE"): value = cacheutil.hget('sys.config', key) xutils.trace("HGET", "key=%s, value=%s" % (key, value)) if value is not None: setattr(xconfig, key, value) path = os.path.join(xconfig.SCRIPTS_DIR, "user.css") if not os.path.exists(path): return xconfig.set("USER_CSS", xutils.readfile(path))
def handle_args(): parser = argparse.ArgumentParser() parser.add_argument("--data", default="./data") parser.add_argument("--delay", default="0") parser.add_argument("--ringtone", default="no") parser.add_argument("--port", default=DEFAULT_PORT) parser.add_argument("--webbrowser", default="no") parser.add_argument("--debug", default="yes") parser.add_argument("--minthreads", default="10") parser.add_argument("--useCacheSearch", default="no") parser.add_argument("--useUrlencode", default="no") parser.add_argument("--devMode", default="no") parser.add_argument("--initScript", default="init.py") parser.add_argument("--master", default="no") parser.add_argument("--test", default="no") web.config.debug = False args = parser.parse_args(sys.argv[1:]) # 处理Data目录,创建各种目录 try: xconfig.init(args.data) except Exception as e: xconfig.errors.append("创建目录失败") xutils.print_exc() # 端口号 xconfig.PORT = args.port # 延迟加载,避免定时任务重复执行 delay = int(args.delay) time.sleep(delay) # 启动提醒 if args.ringtone == "yes": xutils.say("系统启动") if args.webbrowser == "yes": xconfig.OPEN_IN_BROWSER = True if args.debug == "yes": xconfig.DEBUG = True web.config.debug = True if args.useCacheSearch == "yes": xconfig.USE_CACHE_SEARCH = True if args.useUrlencode == "yes": xconfig.USE_URLENCODE = True if args.devMode == "yes": xconfig.DEV_MODE = True if args.test == "yes": xconfig.IS_TEST = True xconfig.MIN_THREADS = int(args.minthreads) xconfig.INIT_SCRIPT = args.initScript web.config.minthreads = xconfig.MIN_THREADS port = xconfig.PORT if port != DEFAULT_PORT: # 指定端口优先级最高 os.environ["PORT"] = port if not os.environ.get("PORT"): os.environ["PORT"] = port xconfig.set("port", port) xconfig.set("start_time", xutils.format_datetime())