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()
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()
print "ERROR - no configuration file(s) given. (no '-c')" exit(1) else: # Check if files even existed since config read will not error if a file # given didn't actually exist. But, I believe the user should know if # they're trying to supply a config file that doesn't actually exist... for cf in opts.config_files: if not osp.isfile(cf): print "ERROR - Configuration file doesn't exist." print "ERROR - Given:", opts.config_files print "ERROR - Doesn't exist:", cf exit(1) # Taking out some variables we want here in the main function pnorm = lambda p: osp.abspath(osp.expanduser(p)) img_dir = pnorm(config.get(MPIS_CONFIG_SECT, 'image_directory')) work_dir = pnorm(config.get(MPIS_CONFIG_SECT, 'run_work_directory')) log_dir = pnorm(config.get(MPIS_CONFIG_SECT, 'log_dir')) work_list_file = pnorm(config.get(MPIS_CONFIG_SECT, 'video_work_list')) descr_module = config.get(MPIS_CONFIG_SECT, 'descriptor_mode') # obviously need a work file if not (work_list_file and osp.isfile(work_list_file)): print "ERROR - Must specify work-list file in config" print "ERROR - Given: %s" % work_list_file sys.exit(1) ### # Making sure required directories exist. #
print "ERROR - no configuration file(s) given. (no '-c')" exit(1) else: # Check if files even existed since config read will not error if a file # given didn't actually exist. But, I believe the user should know if # they're trying to supply a config file that doesn't actually exist... for cf in opts.config_files: if not osp.isfile(cf): print "ERROR - Configuration file doesn't exist." print "ERROR - Given:", opts.config_files print "ERROR - Doesn't exist:", cf exit(1) # Taking out some variables we want here in the main function pnorm = lambda p: osp.abspath(osp.expanduser(p)) img_dir = pnorm(config.get(MPIS_CONFIG_SECT, "image_directory")) work_dir = pnorm(config.get(MPIS_CONFIG_SECT, "run_work_directory")) log_dir = pnorm(config.get(MPIS_CONFIG_SECT, "log_dir")) work_list_file = pnorm(config.get(MPIS_CONFIG_SECT, "video_work_list")) descr_module = config.get(MPIS_CONFIG_SECT, "descriptor_mode") # obviously need a work file if not (work_list_file and osp.isfile(work_list_file)): print "ERROR - Must specify work-list file in config" print "ERROR - Given: %s" % work_list_file sys.exit(1) ### # Making sure required directories exist. #