Ejemplo n.º 1
0
    def parse(self, directory, input_text):
        data = parse_json(input_text)

        for task_key, v in data.iteritems():
            self.ast.add_node(self.wrapper.join_dir(directory, task_key))

            for kk, vv in v.iteritems():
                if kk == 'depends':
                    for child_key in vv:
                        self.ast.add_dependency(self.wrapper.join_dir(directory, task_key), self.wrapper.join_dir(directory, child_key))
                else:
                    task_kwargs = {kk : vv}
                    self.ast.add_node(self.wrapper.join_dir(directory, task_key), **task_kwargs)

        def children_for_allinputs(priority=None):
            children = []
            for k, v in self.ast.lookup_table.iteritems():
                if 'allinputs' in v:
                    if priority:
                        k_priority = v.get('priority', 10)
                        if k_priority < priority:
                            children.append(k)
                else:
                    children.append(k)
            return children

        # Make another pass to implement 'allinputs'
        for task_key, kwargs in self.ast.lookup_table.iteritems():
            if kwargs.get('allinputs', False):
                priority = kwargs.get('priority')
                for child_key in children_for_allinputs(priority):
                    # These keys are already adjusted for directory.
                    self.ast.add_dependency(task_key, child_key)
Ejemplo n.º 2
0
    def parse(self, directory, input_text):
        for line in input_text.splitlines():
            line = line.strip()

            # Throw away comments.
            if "#" in line:
                if line.startswith("#"):
                    line = ''
                else:
                    line = line.split("#", 0)

            if not re.match("^\s*$", line):
                if "{" in line:
                    # We have a task + some JSON arguments
                    key, raw_args = line.split("{", 1)
                    key = key.strip()
                    kwargs = parse_json("{" + raw_args)
                else:
                    key = line
                    kwargs = {}

                node_key = self.wrapper.join_dir(directory, key)
                self.ast.add_node(node_key, **kwargs)
                # all tasks already in the ast are children
                for child_key in self.ast.lookup_table.keys():
                    child_node_key = self.wrapper.join_dir(directory, child_key)
                    self.ast.add_dependency(node_key, child_node_key)
Ejemplo n.º 3
0
def config_args(modargs):
    cliargs = modargs.get("__cli_options", {})
    kwargs = modargs.copy()

    config_file = modargs.get('conf', dexy.utils.defaults['config_file'])

    # Update from config file
    if file_exists(config_file):
        with open(config_file, "r") as f:
            if config_file.endswith(".conf"):
                try:
                    conf_args = parse_yaml(f.read())
                except dexy.exceptions.UserFeedback as yaml_exception:
                    try:
                        conf_args = parse_json(f.read())
                    except dexy.exceptions.UserFeedback as json_exception:
                        print("--------------------------------------------------")
                        print("Tried to parse YAML:")
                        print(yaml_exception)
                        print("--------------------------------------------------")
                        print("Tried to parse JSON:")
                        print(json_exception)
                        print("--------------------------------------------------")
                        raise dexy.exceptions.UserFeedback("Unable to parse config file '%s' as YAML or as JSON." % config_file)

            elif config_file.endswith(".yaml"):
                conf_args = parse_yaml(f.read())
            elif config_file.endswith(".json"):
                conf_args = parse_json(f.read())
            else:
                raise dexy.exceptions.UserFeedback("Don't know how to load config from '%s'" % config_file)
            if conf_args:
                # TODO raise error if 
                kwargs.update(conf_args)

    if cliargs: # cliargs may be False
        for k in list(cliargs.keys()):
            try:
                kwargs[k] = modargs[k]
            except KeyError:
                msg = "This command does not take a '--%s' argument." % k
                raise dexy.exceptions.UserFeedback(msg)

    # TODO allow updating from env variables, e.g. DEXY_ARTIFACTS_DIR

    return kwargs
Ejemplo n.º 4
0
def config_args(modargs):
    cliargs = modargs.get("__cli_options", {})
    kwargs = modargs.copy()

    config_file = modargs.get('conf', dexy.utils.defaults['config_file'])

    # Update from config file
    if file_exists(config_file):
        with open(config_file, "rb") as f:
            if config_file.endswith(".conf"):
                try:
                    conf_args = parse_yaml(f.read())
                except dexy.exceptions.UserFeedback as yaml_exception:
                    try:
                        conf_args = parse_json(f.read())
                    except dexy.exceptions.UserFeedback as json_exception:
                        print "--------------------------------------------------"
                        print "Tried to parse YAML:"
                        print yaml_exception
                        print "--------------------------------------------------"
                        print "Tried to parse JSON:"
                        print json_exception
                        print "--------------------------------------------------"
                        raise dexy.exceptions.UserFeedback("Unable to parse config file '%s' as YAML or as JSON." % config_file)

            elif config_file.endswith(".yaml"):
                conf_args = parse_yaml(f.read())
            elif config_file.endswith(".json"):
                conf_args = parse_json(f.read())
            else:
                raise dexy.exceptions.UserFeedback("Don't know how to load config from '%s'" % config_file)
            if conf_args:
                kwargs.update(conf_args)

    if cliargs: # cliargs may be False
        for k in cliargs.keys():
            try:
                kwargs[k] = modargs[k]
            except KeyError:
                msg = "This command does not take a '--%s' argument." % k
                raise dexy.exceptions.UserFeedback(msg)

    # TODO allow updating from env variables, e.g. DEXY_ARTIFACTS_DIR

    return kwargs
Ejemplo n.º 5
0
def config_args(modargs):
    cliargs = modargs.get("__cli_options", {})
    kwargs = modargs.copy()

    config_file = modargs.get('conf', dexy.utils.defaults['config_file'])

    # Update from config file
    if file_exists(config_file):
        with open(config_file, "rb") as f:
            if config_file.endswith(".conf"):
                try:
                    conf_args = parse_yaml(f.read())
                except dexy.exceptions.UserFeedback as yaml_exception:
                    try:
                        conf_args = parse_json(f.read())
                    except dexy.exceptions.UserFeedback as json_exception:
                        print "--------------------------------------------------"
                        print "Tried to parse YAML:"
                        print yaml_exception
                        print "--------------------------------------------------"
                        print "Tried to parse JSON:"
                        print json_exception
                        print "--------------------------------------------------"
                        raise dexy.exceptions.UserFeedback(
                            "Unable to parse config file '%s' as YAML or as JSON."
                            % config_file)

            elif config_file.endswith(".yaml"):
                conf_args = parse_yaml(f.read())
            elif config_file.endswith(".json"):
                conf_args = parse_json(f.read())
            else:
                raise dexy.exceptions.UserFeedback(
                    "Don't know how to load config from '%s'" % config_file)
            if conf_args:
                kwargs.update(conf_args)

    if cliargs:  # cliargs may be False
        for k in cliargs.keys():
            kwargs[k] = modargs[k]

    # TODO allow updating from env variables, e.g. DEXY_ARTIFACTS_DIR

    return kwargs
Ejemplo n.º 6
0
 def parse_environment_from_text(klass, text):
     return parse_json(text)
Ejemplo n.º 7
0
 def parse_environment_from_text(klass, text):
     return parse_json(text)