Beispiel #1
0
    def option_config(cls, session, action, file_type=None):
        """Get a config option for this entity class for the given action."""

        app_name = session.app_name
        id_str = app_name + action + cls.category + str(file_type)

        if id_str in cls._option_configs:
            return cls._option_configs[id_str]

        ptask_type_lookup = session.ptask.types

        rel_config = os.path.join('config', app_name, cls.category, action)
        if file_type:
            rel_config += "_" + file_type
        rel_config += '.cfg'

        ptask_area = session.ptask_area
        action_config = ptask_area.config(rel_config, composite_ancestors=True)

        configs_to_composite = []

        for (section_name, section_config) in action_config.iteritems():

            if section_name == "global":
                configs_to_composite.append(
                    section_config.get('options', Config()))
            else:
                match = True
                for (filter_name, val) in section_config.iteritems():
                    if filter_name == 'options':
                        continue
                    
                    if not filter_name in ptask_type_lookup:
                        match = False
                        break

                    if not ptask_type_lookup[filter_name] == val:
                        match = False
                        break

                if match:
                    configs_to_composite.append(
                        section_config.get('options', Config())
                    )

        composited = Config.composite(configs_to_composite)

        config = Config()
        config.add('options', composited)

        cls._option_configs[id_str] = config

        return config
Beispiel #2
0
    def config(self, config_file, composite_ancestors=False,
        composite_method="override"):

        if not composite_ancestors:
            config_path = os.path.join(self.path, config_file)
            return Config.read(config_path)

        # ---- look up the hierarchy and composite config files

        config_paths = self.ancestor_paths(
            relative_file=config_file, include_install=True)
        config_paths.reverse()
        config = Config.composite(config_paths, method=composite_method)

        return config
Beispiel #3
0
    def config(self,
               config_file,
               composite_ancestors=False,
               composite_method="override"):

        if not composite_ancestors:
            config_path = os.path.join(self.path, config_file)
            return Config.read(config_path)

        # ---- look up the hierarchy and composite config files

        config_paths = self.ancestor_paths(relative_file=config_file,
                                           include_install=True)
        config_paths.reverse()
        config = Config.composite(config_paths, method=composite_method)

        return config
Beispiel #4
0
    def _process_config(self, shell=None, ptask=None):

        # get all ancestor ptask config files         
        ancestor_paths = self.ancestor_paths()
        filename = self.__class__._PTASK_SET_CONFIG

        # reverse order for compositing
        config_files = reversed(
            [os.path.join(p, filename) for p in ancestor_paths])
        config = Config.composite(config_files)

        for (key, value) in config.iteritems():
                
            # echo to shell
            if shell and key.startswith('echo'):
                try:
                    value = value.format(
                        ptask=ptask,
                        style=Style,
                        bg=Bg,
                        fg=Fg,
                    )
                    print shell.echo(value)
                except:
                    pass

            # run command
            if shell and key.startswith("cmd"):

                for cmd in value:
                    try:
                        cmd = cmd.format(ptask=ptask)
                        print shell.command(cmd)
                    except Exception as e:
                        print shell.echo("ERROR: " + str(e))

            # change directory
            elif shell and key == "cd":
                
                print shell.cd(value)

            # set env var
            elif key.startswith("env"):
                
                # the value is another config object with env vars
                for (var_key, var_value) in value.iteritems():

                    try:
                        custom_vars = self.env.custom_vars
                    except:
                        # add a variable that remembers per-ptask custom
                        # variables.  we'll use this to know what to unset when
                        # setting a new ptask.
                        self.env.add(
                            DpaVars.ptask_custom_vars(), name='custom_vars')

                    var = EnvVar(var_key) 
                    var.value = var_value
                    var.set(shell=shell)

                    # remember this variable name for unsetting
                    if not var_key in self.env.custom_vars.list:
                        self.env.custom_vars.append(var_key)
Beispiel #5
0
    def _process_config(self, shell=None, ptask=None):

        # get all ancestor ptask config files
        ancestor_paths = self.ancestor_paths()
        filename = self.__class__._PTASK_SET_CONFIG

        # reverse order for compositing
        config_files = reversed(
            [os.path.join(p, filename) for p in ancestor_paths])
        config = Config.composite(config_files)

        for (key, value) in config.iteritems():

            # echo to shell
            if shell and key.startswith('echo'):
                try:
                    value = value.format(
                        ptask=ptask,
                        style=Style,
                        bg=Bg,
                        fg=Fg,
                    )
                    print shell.echo(value)
                except:
                    pass

            # run command
            if shell and key.startswith("cmd"):

                for cmd in value:
                    try:
                        cmd = cmd.format(ptask=ptask)
                        print shell.command(cmd)
                    except Exception as e:
                        print shell.echo("ERROR: " + str(e))

            # change directory
            elif shell and key == "cd":

                print shell.cd(value)

            # set env var
            elif key.startswith("env"):

                # the value is another config object with env vars
                for (var_key, var_value) in value.iteritems():

                    try:
                        custom_vars = self.env.custom_vars
                    except:
                        # add a variable that remembers per-ptask custom
                        # variables.  we'll use this to know what to unset when
                        # setting a new ptask.
                        self.env.add(DpaVars.ptask_custom_vars(),
                                     name='custom_vars')

                    var = EnvVar(var_key)
                    var.value = var_value
                    var.set(shell=shell)

                    # remember this variable name for unsetting
                    if not var_key in self.env.custom_vars.list:
                        self.env.custom_vars.append(var_key)