Beispiel #1
0
    def get_names(self):
        """
        Get all the module names contained in the filenames or directories
        for this section.
        """
        whitelist_patterns = [re.compile(r"^%s$" % r) for r in self.whitelist]
        blacklist_patterns = [re.compile(r"^%s$" % r) for r in self.blacklist]

        # Determine names
        names = set()
        filenames = itertools.chain(*[path_expand_recursive(m)
            for m in self.modules])
        for filename in filenames:
            name = posixpath.basename(filename)
            if not name.endswith(".py") or name == "__init__.py":
                # Ignore silently
                continue

            name = name.replace(".py", "")
            if whitelist_patterns:
                if not [name for p in whitelist_patterns if p.match(name)]:
                    logging.info("Not whitelisted module: %s", name)
                    continue
            elif blacklist_patterns:
                if [name for p in blacklist_patterns if p.match(name)]:
                    logging.info("Blacklisted module: %s", name)
                    continue

            names.add(name)

        return list(names)
Beispiel #2
0
    def load_module(self, name):
        """
        Load a single module by name from this section.
        """
        logging.info("Loading module %s from section %s",
            name, self.name)

        if not self.has_module(name):
            raise Exception("No such such module: %s" % name)

        filenames = itertools.chain(*[path_expand_recursive(m)
            for m in self.modules])
        for filename in filenames:
            if filename.endswith(".py") and posixpath.exists(filename):
                basename = posixpath.basename(filename)
                basename = basename.replace(".py", "")
                if basename == name:
                    globals = {}
                    exec(open(filename).read(), globals)
                    if "factory" not in globals:
                        raise Exception("Variable 'factory' not found in: %s" \
                            % filename)

                    module = globals["factory"]()
                    module.__module__ = name

                    config_name = "/".join([self.name, name])
                    config = self._config.parent.get_section(config_name)

                    # Set configuration values
                    variables = get_variables(module)
                    environ = dict([(k.lower(), v) for k, v in os.environ.items()])
                    for attribute, variable in variables.items():
                        if config and attribute.name in config:
                            value = config.get(attribute.name)
                            variable.set(value)
                        else:
                            value = variable.get()
                            if isinstance(value, str):
                                value = value % environ
                                variable.set(value)
                            elif isinstance(value, list):
                                value = [v % environ for v in value]
                                variable.set(value)

                    # Check required attributes
                    for attribute, variable in variables.items():
                        value = variable.get()
                        if value is None and variable._required:
                            raise Exception("Configuration '%s' missing " \
                                "required attribute: %s" \
                                % (config_name, attribute.name))

                    return module

        raise Exception("Failed to find module '%s' in: %s" % (name, filenames))
    def read_jobs(self):
        messages = []
        if os.environ.get("CHECKBOX_PACKAGING", 0):
            jobs_path = "./build/share/checkbox/jobs"
        else:
            jobs_path = "./jobs"

        for filename in path_expand_recursive(jobs_path):
            basename = os.path.basename(filename)
            if not basename.startswith(".") and not basename.endswith("~"):
                template = TemplateI18n()
                messages += template.load_filename(filename)

        return messages
Beispiel #4
0
    def read_jobs(self):
        messages = []
        if os.environ.get("CHECKBOX_PACKAGING", 0):
            jobs_path = "./build/share/checkbox/jobs"
        else:
            jobs_path = "./jobs"

        for filename in path_expand_recursive(jobs_path):
            basename = os.path.basename(filename)
            if not basename.startswith(".") and not basename.endswith("~"):
                template = TemplateI18n()
                messages += template.load_filename(filename)

        return messages
Beispiel #5
0
    def message_directory(self, directory, blacklist=[], whitelist=[]):
        whitelist_patterns = [re.compile(r"^%s$" % r) for r in whitelist if r]
        blacklist_patterns = [re.compile(r"^%s$" % r) for r in blacklist if r]

        for filename in path_expand_recursive(directory):
            name = posixpath.basename(filename)
            if name.startswith(".") or name.endswith("~"):
                continue

            if whitelist_patterns:
                if not [name for p in whitelist_patterns if p.match(name)]:
                    continue
            elif blacklist_patterns:
                if [name for p in blacklist_patterns if p.match(name)]:
                    continue

            self._manager.reactor.fire("message-filename", filename)
Beispiel #6
0
    def message_directory(self, directory, blacklist=[], whitelist=[]):
        whitelist_patterns = [re.compile(r"^%s$" % r) for r in whitelist if r]
        blacklist_patterns = [re.compile(r"^%s$" % r) for r in blacklist if r]

        for filename in path_expand_recursive(directory):
            name = posixpath.basename(filename)
            if name.startswith(".") or name.endswith("~"):
                continue

            if whitelist_patterns:
                if not [name for p in whitelist_patterns if p.match(name)]:
                    continue
            elif blacklist_patterns:
                if [name for p in blacklist_patterns if p.match(name)]:
                    continue

            self._manager.reactor.fire("message-filename", filename)