def __setitem__(self, key, value): if key == "includes": if isinstance(value, list): value = value[0] for path in split(value): path = self._parser._interpolate("DEFAULT", None, path, self) path = posixpath.expanduser(path) if not posixpath.exists(path): raise Exception, "No such configuration file: %s" % path if posixpath.isdir(path): logging.info("Parsing config filenames from directory: %s", path) def walk_func(arg, directory, names): for name in names: path = posixpath.join(directory, name) if not posixpath.isdir(path): arg._parser.read(path) posixpath.walk(path, walk_func, self) else: logging.info("Parsing config filename: %s", path) self._parser.read(path) # Environment has precedence over configuration elif not key.startswith("CHECKBOX") or key.upper() not in os.environ: super(IncludeDict, self).__setitem__(key, value)
def coerce(self, values): item_factory = self._item_factory if isinstance(values, str): values = split(values, self._separator) if values else [] elif not isinstance(values, (list, tuple)): raise ValueError("%r is not a list or tuple" % (values, )) for i, v in enumerate(values): values[i] = item_factory(value=v).get() return values
def coerce(self, values): item_factory = self._item_factory if isinstance(values, str): values = split(values, self._separator) if values else [] elif not isinstance(values, (list, tuple)): raise ValueError("%r is not a list or tuple" % (values,)) for i, v in enumerate(values): values[i] = item_factory(value=v).get() return values
def create_application(self, args=sys.argv): # Create data directory data_directory = get_variable("CHECKBOX_DATA", ".") safe_make_directory(data_directory) # Prepend environment options string_options = get_variable("CHECKBOX_OPTIONS", "") args[:0] = split(string_options) (options, args) = self.parse_options(args) # Replace shorthands for shorthand in "blacklist", "blacklist_file", "whitelist", "whitelist_file": key = ".*/jobs_info/%s" % shorthand value = getattr(options, shorthand) if value: options.config.append("=".join([key, value])) # Set logging early set_logging(options.log_level, options.log) # Config setup if len(args) != 2: sys.stderr.write(_("Missing configuration file as argument.\n")) sys.exit(1) config = Config() config_filename = posixpath.expanduser(args[1]) config.read_filename(config_filename) config.read_configs(options.config) section_name = "checkbox/plugins/client_info" section = config.get_section(section_name) if not section: section = config.add_section(section_name) section.set("name", posixpath.basename(args[1]) \ .replace(".ini", "")) section.set("version", config.get_defaults().version) # Check options if options.version: print(config.get_defaults().version) sys.exit(0) return self.application_factory(config)
def __setitem__(self, key, value): if key == "includes": if isinstance(value, list): value = value[0] for path in split(value): path = self._parser._interpolation.before_get( self._parser, "DEFAULT", None, path, self) path = os.path.expanduser(path) if not os.path.exists(path): raise Exception("No such configuration file: %s" % path) if os.path.isdir(path): logging.info("Parsing config filenames from directory: %s", path) for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: path = os.path.join(dirpath, filename) self._parser.read(path) else: logging.info("Parsing config filename: %s", path) self._parser.read(path) # Environment has precedence over configuration elif not key.startswith("CHECKBOX") or key.upper() not in os.environ: super(IncludeDict, self).__setitem__(key, value)