# Path: flo/parser.py
# @memoize
# def load_task_graph(config=None):
#     """Load the task graph from the configuration file located at
#     config_path
#     """
# 
#     config_path = find_config_path(config=config)
# 
#     # convert each task_kwargs into a Task object and add it to the
#     # TaskGraph
#     return TaskGraph(config_path, get_task_kwargs_list(config_path))
# 
# @memoize
# def get_task_kwargs_list(config=None):
#     """Get a list of dictionaries that are read from the flo.yaml
#     file and collapse the global variables into each task.
#     """
# 
#     # get workflow configuration file
#     config_path = find_config_path(config=config)
# 
#     # load the data
#     with open(config_path) as stream:
#         config_yaml = yaml.load_all(stream.read())
#     try:
#         return config_yaml2task_kwargs_list(config_yaml)
#     except yaml.constructor.ConstructorError, error:
#         raise exceptions.YamlError(config_path, error)
# 
# Path: flo/exceptions.py
# class ConfigurationNotFound(CommandLineException):
#     def __init__(self, config_filename, cwd):
#         self.config_filename = config_filename
#         self.cwd = cwd
# 
#     def __str__(self):
#         return "No configuration file called '%s' found in directory\n'%s'" % (
#             self.config_filename,
#             self.cwd,
#         )
# 
# class YamlError(CommandLineException):
#     def __init__(self, config_filename, yaml_error):
#         self.config_filename = config_filename
#         self.yaml_error = yaml_error
# 
#     def __str__(self):
#         msg = "There was an error loading your YAML configuration file "
#         msg += "located at\n%s:\n\n" % self.config_filename
#         msg += str(self.yaml_error)
# 
#         # provide useful hints here for common problems
#         if "{{" in str(self.yaml_error):
#             msg += "\n\n"
#             msg += "Try quoting your jinja templates if they start with '{{'\n"
#             msg += "because YAML interprets an unquoted '{' as the start of\n"
#             msg += "a new YAML object."
#         return msg


from ..parser import load_task_graph, get_task_kwargs_list
from ..exceptions import ConfigurationNotFound, YamlError
    help_text = ''

    def __init__(self, subcommand_creator):

        # keep a local copy of the config file which is useful during
        # autocompletion
        self.config = None

        # set up the subcommand options
        self.subcommand_creator = subcommand_creator
        self.option_parser = self.subcommand_creator.add_parser(
            self.get_command_name(),
            help=self.help_text,
            description=self.help_text,
        )
        self.add_command_line_options()

    def get_command_name(self):
        """The command name defaults to the name of the module."""
        return self.__module__.rsplit('.', 1)[1]

    def add_command_line_options(self):
        self.option_parser.add_argument(
            '-c', '--config',
            type=str,
            help='Specify a particular YAML configuration file.',
        )

    def execute(self, config=None):
        self.config = config

# Path: flo/parser.py
# @memoize
# def load_task_graph(config=None):
#     """Load the task graph from the configuration file located at
#     config_path
#     """
# 
#     config_path = find_config_path(config=config)
# 
#     # convert each task_kwargs into a Task object and add it to the
#     # TaskGraph
#     return TaskGraph(config_path, get_task_kwargs_list(config_path))
# 
# @memoize
# def get_task_kwargs_list(config=None):
#     """Get a list of dictionaries that are read from the flo.yaml
#     file and collapse the global variables into each task.
#     """
# 
#     # get workflow configuration file
#     config_path = find_config_path(config=config)
# 
#     # load the data
#     with open(config_path) as stream:
#         config_yaml = yaml.load_all(stream.read())
#     try:
#         return config_yaml2task_kwargs_list(config_yaml)
#     except yaml.constructor.ConstructorError, error:
#         raise exceptions.YamlError(config_path, error)
# 
# Path: flo/exceptions.py
# class ConfigurationNotFound(CommandLineException):
#     def __init__(self, config_filename, cwd):
#         self.config_filename = config_filename
#         self.cwd = cwd
# 
#     def __str__(self):
#         return "No configuration file called '%s' found in directory\n'%s'" % (
#             self.config_filename,
#             self.cwd,
#         )
# 
# class YamlError(CommandLineException):
#     def __init__(self, config_filename, yaml_error):
#         self.config_filename = config_filename
#         self.yaml_error = yaml_error
# 
#     def __str__(self):
#         msg = "There was an error loading your YAML configuration file "
#         msg += "located at\n%s:\n\n" % self.config_filename
#         msg += str(self.yaml_error)
# 
#         # provide useful hints here for common problems
#         if "{{" in str(self.yaml_error):
#             msg += "\n\n"
#             msg += "Try quoting your jinja templates if they start with '{{'\n"
#             msg += "because YAML interprets an unquoted '{' as the start of\n"
#             msg += "a new YAML object."
#         return msg


# Path: flo/commands/base.py
from ..parser import load_task_graph, get_task_kwargs_list
from ..exceptions import ConfigurationNotFound, YamlError

    help_text = ''

    def __init__(self, subcommand_creator):

        # keep a local copy of the config file which is useful during
        # autocompletion
        self.config = None

        # set up the subcommand options
        self.subcommand_creator = subcommand_creator
        self.option_parser = self.subcommand_creator.add_parser(
            self.get_command_name(),
            help=self.help_text,
            description=self.help_text,
        )
        self.add_command_line_options()

    def get_command_name(self):
        """The command name defaults to the name of the module."""
        return self.__module__.rsplit('.', 1)[1]

    def add_command_line_options(self):
        self.option_parser.add_argument(
            '-c', '--config',
            type=str,
            help='Specify a particular YAML configuration file.',
        )

    def execute(self, config=None):
        self.config = config

        self.task_graph = load_task_graph(config=config)