def main(): parser = optparse.OptionParser() parser.add_option('-c', '--config', type=str, help='Path to the configuration file.') parser.add_option('-v', '--verbose', action='store_true', default=False, help='Add debugging log messages.') opts, args = parser.parse_args() config_file = opts.config assert config_file is not None, \ "Not given a configuration file for the server!" assert osp.exists(config_file), \ "Given config file path does not exist." assert not osp.isdir(config_file), \ "Given config file is a directory!" config = SafeConfigCommentParser() parsed = config.read(config_file) assert parsed, "Configuration file not parsed!" section = 'server' assert config.has_section(section), \ "No server section found!" assert config.has_option(section, 'port'), \ "No port option in config!" assert config.has_option(section, 'authkey'), \ "No authkey option in config!" port = config.getint(section, 'port') authkey = config.get(section, 'authkey') # Setup logging log_format_str = '%(levelname)7s - %(asctime)s - %(name)s.%(funcName)s - ' \ '%(message)s' if opts.verbose: log_level = logging.DEBUG else: log_level = logging.INFO logging.getLogger().setLevel(log_level) logging.basicConfig(format=log_format_str) mgr = FeatureManager(('', port), authkey) mgr.get_server().serve_forever()
# ================================================================ # Main entry # - Start the program # # TODO: Functionalize this and move this implementation into an importable # location, creating a wrapper script for bin. # - Will probably want to just use this as the VCD run system within the # SmqtkController/VCDSController instead of making two discrete run # subsystems. if __name__ == '__main__': # process options opts, _ = parse_options() # initially load config files if any given (potentially for output config) config = SafeConfigCommentParser() config.read(opts.config_files) ### # Config file output if requested # if opts.output_config: logging.basicConfig() log = logging.getLogger() log.setLevel(logging.WARNING - (10 * opts.verbosity)) log.info("Outputting configuration file@ %s", opts.output_config) if osp.exists(opts.output_config) and not opts.overwrite: log.error("Target already exists. Not overwriting.") exit(2) log.info("Generating config object")
# ================================================================ # Main entry # - Start the program # # TODO: Functionalize this and move this implementation into an importable # location, creating a wrapper script for bin. # - Will probably want to just use this as the VCD run system within the # SmqtkController/VCDSController instead of making two discrete run # subsystems. if __name__ == "__main__": # process options opts, _ = parse_options() # initially load config files if any given (potentially for output config) config = SafeConfigCommentParser() config.read(opts.config_files) ### # Config file output if requested # if opts.output_config: logging.basicConfig() log = logging.getLogger() log.setLevel(logging.WARNING - (10 * opts.verbosity)) log.info("Outputting configuration file@ %s", opts.output_config) if osp.exists(opts.output_config) and not opts.overwrite: log.error("Target already exists. Not overwriting.") exit(2) log.info("Generating config object")