def generate_config(cls, config=None): """ Generate, define and return a configuration object for this descriptor worker. :param config: An optionally existing configuration object to update. :type config: None or SafeConfigCommentParser :return: Updated configuration object with this descriptor's specific configuration parameters. :rtype: SafeConfigCommentParser """ if config is None: config = SafeConfigCommentParser() # If the config sections for the utility methods are not present, add # them and their options. if not config.has_section(cls.EXTRACTOR_CONFIG_SECT): sect = cls.EXTRACTOR_CONFIG_SECT config.add_section(sect, "Options controlling how frames are extracted " "from videos when requested.\n" "\n" "The following are standard frame extraction " "configurations for configurable descriptor " "modules (in offset,interval,max_duration " "value order):\n" " - colordescriptor -> (0, 2, 10)\n" " - subattributes -> (3, 4, 0)\n") config.set(sect, 'frame_extractor_exe', 'frame_extractor', "The frame_extractor executable to use") config.set(sect, 'start_offset_seconds', '0.0', "The number of seconds after the start of the video to " "start extracting frames. This may be 0 or not provided " "to indicate no offset.") config.set(sect, 'second_interval', '2.0', "Extract frames, after the provided offset, every N " "seconds, where N is the value provided here. This may " "be floating point. This may be 0 or not provided to " "extract all frames after the given offset.") config.set(sect, 'max_duration_minutes', '10.0', "Maximum time which we are not to extract frames past. " "This should be provided in decimal minutes. This may " "be not provided (no value given), or set to 0, to " "indicate no maximum duration limit. ") if not config.has_section(cls.PROBE_CONFIG_SECT): sect = cls.PROBE_CONFIG_SECT config.add_section(sect) config.set(sect, 'ffprobe_exe', 'ffprobe', "The ffmpeg ffprobe executable to use when probing for " "video metadata.") config.set(sect, 'use_TBR_fallback', 'false', "Use or don't use the TBR value when the FPS value is " "not present when probing video metadata.") return config
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()
def generate_config(cls, config=None): """ Generate, define and return a configuration object for this descriptor worker. :param config: An optionally existing configuration object to update. :type config: None or SafeConfigCommentParser :return: Updated configuration object with this descriptor's specific configuration parameters. :rtype: SafeConfigCommentParser """ if config is None: config = SafeConfigCommentParser() # If the config sections for the utility methods are not present, add # them and their options. if not config.has_section(cls.EXTRACTOR_CONFIG_SECT): sect = cls.EXTRACTOR_CONFIG_SECT config.add_section( sect, "Options controlling how frames are extracted " "from videos when requested.\n" "\n" "The following are standard frame extraction " "configurations for configurable descriptor " "modules (in offset,interval,max_duration " "value order):\n" " - colordescriptor -> (0, 2, 10)\n" " - subattributes -> (3, 4, 0)\n") config.set(sect, 'frame_extractor_exe', 'frame_extractor', "The frame_extractor executable to use") config.set( sect, 'start_offset_seconds', '0.0', "The number of seconds after the start of the video to " "start extracting frames. This may be 0 or not provided " "to indicate no offset.") config.set( sect, 'second_interval', '2.0', "Extract frames, after the provided offset, every N " "seconds, where N is the value provided here. This may " "be floating point. This may be 0 or not provided to " "extract all frames after the given offset.") config.set( sect, 'max_duration_minutes', '10.0', "Maximum time which we are not to extract frames past. " "This should be provided in decimal minutes. This may " "be not provided (no value given), or set to 0, to " "indicate no maximum duration limit. ") if not config.has_section(cls.PROBE_CONFIG_SECT): sect = cls.PROBE_CONFIG_SECT config.add_section(sect) config.set( sect, 'ffprobe_exe', 'ffprobe', "The ffmpeg ffprobe executable to use when probing for " "video metadata.") config.set( sect, 'use_TBR_fallback', 'false', "Use or don't use the TBR value when the FPS value is " "not present when probing video metadata.") return config