def init_evn(): """ 初始化环境 :return: """ logger.init(logging.INFO) account.load_user_info()
def run(): parser = argparse.ArgumentParser(prog='paste.py', description='Push to or pull from paste pads!', conflict_handler='resolve', add_help=False, formatter_class=_Smart_formatter) opt_common = parser.add_argument_group('Common Options') opt_common.add_argument('-h', '--help', action='help', help='Print this help message and exit.\n' 'Use `paste.py provider -h` for specific information.') opt_common.add_argument('-V', '--version', action='version', version='%(prog)s ' + _version) opt_log = parser.add_argument_group('Logging Options') opt_log.add_argument('--verbose', '-v', action='store_const', dest='log.level', const=logger.Level.INFO, default=logger.Level.WARN, help='Enable verbose output.') opt_log.add_argument('--debug', '-g', action='store_const', dest='log.level', const=logger.Level.DEBUG, help='Enable debug output. (VERY VERBOSE!)') opt_log.add_argument('--quiet', '-q', action='store_const', dest='log.level', const=logger.Level.ERROR, help='Just be quiet, output only error message.') opt_log.add_argument('--simple-log', action='store_const', dest='log.format', const='{message}', default=None, help='Output just simple message without timestamp, log level etc.') opt_log.add_argument('--no-color', action='store_const', dest='log.colorize', const=False, default=True, help='Disable colorful output. Note: colorful is always false if output file is not a terminal.') opt_action = parser.add_subparsers(title='Paste pads', help='introduction', metavar='provider', dest='provider') __import__('providers', globals(), locals()) for provider in ProviderBase.__subclasses__(): ins = provider() opt_ins = opt_action.add_parser(ins._name, help=ins._info, conflict_handler='resolve') ins.add_args(opt_ins) args = parser.parse_args() conf = config.getConfig() for arg in args._get_kwargs(): conf.set(arg[0], arg[1]) logger.init(colorize=conf.getboolean('log.colorize'), level=conf.getint('log.level'), log_format=conf.get('log.format')) getProvider(conf.get('provider')).run()
def main(): """Startup tasks, mainloop entry, and shutdown tasks. """ # Load the configuration. config = _config.ConfigManager(single=False) builtins.CONFIG = config print("Welcome to {0}, Multi-Player Server.".format(_config.VERSION)) print("Starting up...") # Initialize the logger. logger.init(config) log = logger.Logger("server") # Rotate database backups, if enabled. # Unfortunately this has to be done before loading the database, because Windows. if os.path.exists(config["database"]["filename"]): try: if config["database"]["backups"]: backupnumbers = sorted(range(1, config["database"]["backups"]), reverse=True) for bn in backupnumbers: if os.path.exists("{0}.bk{1}".format( config["database"]["filename"], bn)): shutil.copyfile( "{0}.bk{1}".format(config["database"]["filename"], bn), "{0}.bk{1}".format(config["database"]["filename"], bn + 1)) shutil.copyfile( config["database"]["filename"], "{0}.bk1".format(config["database"]["filename"])) except: log.error("Could not finish rotating backups for database: {file}", file=config["database"]["filename"]) log.error(traceback.format_exc(1)) # Initialize the Database Manager and load the world database. log.info("Initializing database manager...") dbman = database.DatabaseManager(config["database"]["filename"], config.defaults) _dbres = dbman._startup() if not _dbres: # On failure, only remove the lockfile if its existence wasn't the cause. if _dbres is not None: dbman._unlock() return 3 log.info("Finished initializing database manager.") # Initialize the router. router = Router(config, dbman) # initialize the command shell. command_shell = shell.Shell(dbman, router) router.shell = command_shell # Start the services. log.info("Initializing services...") if not init_services(config, router, log): dbman._unlock() return 4 log.info("Finished initializing services.") # Graceful shutdown on SIGINT (ctrl-c). # The shutdown command does the same thing. # To shut down quickly but cleanly, send the TERM signal. def shutdown(signal_received, frame): if not router.shutting_down: if config["shutdown_delay"]: command_shell.broadcast( "<<<DENNIS IS SHUTTING DOWN IN {0} SECONDS>>>".format( config["shutdown_delay"])) else: command_shell.broadcast("<<<DENNIS IS SHUTTING DOWN>>>") reactor.callLater(config["shutdown_delay"], reactor.stop) router.shutting_down = True signal.signal(signal.SIGINT, shutdown) # Start the Twisted Reactor. log.info("Finished startup tasks.") router._reactor = reactor reactor.run() # Shutting down. dbman._unlock() print("End Program.") return 0
parser.add_argument("-d","--destAddresses", action="store", help='List of e-mail addresses to be used as destination for any EWS service that needs it.' ' Must be separated by a comma.') parser.add_argument("-m","--message", action="store", help='Message File containing the body of the message as an HTML file') parser.add_argument("-s","--subject", action="store", help='Message subject') parser.add_argument("-f","--folder", action="store", choices=['inbox', 'sentitem', 'deleteditems', 'tasks','calendar','contacts'], help='The Exchange folder name to list') parser.add_argument("-u","--url", action="store", help='URL to be used for the setHomePage request') try: args = parser.parse_args() except Exception, e: print helper.color("[!] " + str(e)) sys.exit(1) # Set output verbosity if args.verbose: logger.init() #----------------------------------------------------------------- # Preparing the SOAPXMLRequest for the send eMail EWS Service #----------------------------------------------------------------- if args.request == "sendMail": if args.destAddresses and args.message and args.subject: #--- Get the message from file try: with open(args.message) as fileHandle: message = cgi.escape(fileHandle.read()) fileHandle.close() print helper.color("[+] File [{}] successfully loaded !".format(args.message)) except IOError: print color("[!] Could not open or read file [{}]".format(args.message)) sys.exit(1)
], help='The Exchange folder name to list') parser.add_argument("-u", "--url", action="store", help='URL to be used for the setHomePage request') try: args = parser.parse_args() except Exception, e: print helper.color("[!] " + str(e)) sys.exit(1) # Set output verbosity if args.verbose: logger.init() #----------------------------------------------------------------- # Preparing the SOAPXMLRequest for the send eMail EWS Service #----------------------------------------------------------------- if args.request == "sendMail": if args.destAddresses and args.message and args.subject: #--- Get the message from file try: with open(args.message) as fileHandle: message = cgi.escape(fileHandle.read()) fileHandle.close() print helper.color( "[+] File [{}] successfully loaded !".format( args.message)) except IOError:
# print("audacity project for sync:", aup_project) # load and accumulate hints for all dirs hint_dict = {} for dir in work_dirs: hint_dict.update( hints.load(dir) ) log("hints:", hint_dict) # make results directory (if it doesn't exist) results_dir = os.path.join(args.project, "results") if not os.path.exists(results_dir): print("Creating:", results_dir) os.makedirs(results_dir) # initialize logger logger.init( os.path.join(results_dir, "report.txt") ) for dir in work_dirs: if dir == work_dirs[-1]: # last dir (top level) group_file = os.path.join(results_dir, "full-mix.mp3") clean = 0.1 suppress_silent_zones = False else: group_file = os.path.join(dir + "-mix.mp3") clean = 0.25 suppress_silent_zones = True #print("group_file:", group_file) if not scan.check_for_newer(dir, group_file): # nothing changed, so skip processing continue
def main(): # When this is False, Dennis will shut down. _running = True # Load the configuration. config = _config.ConfigManager(single=True) builtins.CONFIG = config print("Welcome to {0}, Single User Mode.".format(_config.VERSION)) print("Starting up...") # Initialize the logger. logger.init(config) log = logger.Logger("singleuser") # Rotate database backups, if enabled. # Unfortunately this has to be done before loading the database, because Windows. if os.path.exists(config["database"]["filename"]): try: if config["database"]["backups"]: backupnumbers = sorted(range(1, config["database"]["backups"]), reverse=True) for bn in backupnumbers: if os.path.exists("{0}.bk{1}".format(config["database"]["filename"], bn)): shutil.copyfile("{0}.bk{1}".format(config["database"]["filename"], bn), "{0}.bk{1}".format(config["database"]["filename"], bn + 1)) shutil.copyfile(config["database"]["filename"], "{0}.bk1".format(config["database"]["filename"])) except: log.error("Could not finish rotating backups for database: {0}".format(config["database"]["filename"])) log.error(traceback.format_exc(1)) # Initialize the database manager, and create the "database" alias for use in Debug Mode. log.info("Initializing database manager...") dbman = _database.DatabaseManager(config["database"]["filename"], config.defaults) if not dbman._startup(): return 3 log.info("Finished initializing database manager.") database = dbman # Initialize the router. router = Router(log) # Initialize the command shell, and create the "shell" alias for use in Debug Mode. command_shell = _shell.Shell(dbman, router) router.shell = command_shell shell = command_shell # Initialize the command console, and log in as the root user. Promote to wizard if it was somehow demoted. # Create the "console" alias for use in Debug Mode. Also add us to the current room. dennis = _console.Console(router, command_shell, "<world>", dbman, log) dennis.user = dbman.user_by_name("<world>") dbman._users_online.append("<world>") thisroom = dbman.room_by_id(dennis.user["room"]) if thisroom and "<world>" not in thisroom["users"]: thisroom["users"].append("<world>") dbman.upsert_room(thisroom) if not dennis.user["wizard"]: dennis.user["wizard"] = True dbman.upsert_user(dennis.user) console = dennis # Register our console with the router. router.users["<world>"] = {"service": "singleuser", "console": dennis} # Try to start a command prompt session with a history file. # Otherwise start a sessionless prompt without history. try: command_prompt = PromptSession(history=FileHistory(config["prompt"]["history"])).prompt except: log.error("Could not open prompt history file: {0}".format(config["prompt"]["history"])) log.error(traceback.format_exc(1)) command_prompt = prompt # Stop Dennis. We use this instead of just a variable so that Dennis can be stopped from within a Python file # executed by load() in debug mode. def shutdown(): """Stop Dennis.""" nonlocal _running _running = False # Insert a simplified wrapper around dennis.shell.call() here so that it can access the current console # without us having to pass it as an argument. def call(command, args): """Simplified wrapper around dennis.shell.call(). This shorthand function allows calling a command from Debug Mode without having to pass the current console as an argument. It can also take either a list or a string for args. :param command: The name of the command to call. :param args: A list or string of args to pass. :return: True if succeeded, False if failed. """ if type(args) is str: args = args.split(' ') return dennis.shell.call(dennis, command, args) # Save the main scope for load(). mainscope = locals() # Insert a function for Debug Mode to load and execute a Python file inside the main scope. def load(filename): """Load and execute a Python file inside the main scope. This is the same as running a series of lines in Debug mode. It can be called as a function from Debug mode, or as a command. Usage: `load <filename>`. :param filename: The filename of the Python file to execute. :return: True if succeeded, False if failed. """ # Try to evaluate the given file. try: file = open(filename) except: log.write("[singleuser#error] load: Failed to load Python file: {0}".format(filename)) log.write(traceback.format_exc(1)) return False try: exec(file.read(), globals(), mainscope) except: log.write("[singleuser#error] load: Execution error inside file: {0}".format(filename)) log.write(traceback.format_exc(1)) return False return True # Welcome! log.write("You are now logged in as the administrative user \"<world>\".") # # # # # # # # # # # This is the command loop for the Single User Mode Command Line Interface. It works almost the same as connecting # to a Multi User server through Telnet, with a few differences: # * The return status of commands will echo in the console. # * You play as the system administrator user <world>, who is always a wizard, and owns the first room. # * Other users can't share the session with you. # * You have access to the following special commands: # - `quit` : Quits the CLI. # - `debug` : Enters a PDB Debug Mode session inside the main scope. # - `load <filename>` : Loads and executes an external Python file inside the main scope. # # * You have access to the following special functions inside Debug Mode: # - shutdown() : Cleanly shuts down the engine. # - call(command, args) : Calls the named command with a string or list of arguments. # - load(filename) : Same as the `load <filename>` command. # # * You have access to the following special keypress actions: # - Ctrl+C : Cleanly shuts down the engine. # - Ctrl+D : Enters a PDB Debug Mode session inside the main scope. # # * You can return from Debug Mode to normal operation by entering "continue". # # # # # # # # # # while _running: try: cmd = command_prompt("> ") if cmd == "quit": break elif cmd.startswith("quit ") or cmd == "help quit": log.write("Usage: quit") continue elif cmd == "debug": pdb.set_trace() continue elif cmd.startswith("debug ") or cmd == "help debug": log.write("Usage: debug") continue elif cmd.startswith("load "): log.write(load(cmd[5:])) continue elif cmd == "load" or cmd == "help load": log.write("Usage: load <filename>") continue log.write(command_shell.command(dennis, cmd)) except KeyboardInterrupt: break except EOFError: pdb.set_trace() continue # Just before shutdown. dbman._unlock() log.write("End Program.") return 0