Esempio n. 1
0
class Cli(object):
    """ Command Line Interface for ansible-docgen """

    def __init__(self):
        """ Setup Arguments and Options for CLI """
        # Parse CLI Arguments
        parser = argparse.ArgumentParser()
        parser.add_argument("-p", "--project", dest="project",
                          help="Path to Ansible project",
                          metavar="PROJECT",
                          default="./")
        parser.add_argument("-s", "--style", dest="style",
                          help="Choose the format for the documentation.\
                          Default is markdown. Example: --style=[markdown]",
                          metavar="STYLE",
                          default="markdown")
        parser.add_argument("-n", "--no-tags", dest="show_tags",                          
                          help="This option disables show tags in the documentation",
                           default=True, action='store_false')
        args = parser.parse_args()
        # Make sure there is a trailing /
        self.project = os.path.join(args.project, "")
        self.style = args.style
        self.params = {}
        self.params['show_tags'] = args.show_tags

        # Used to Parse Roles and Playbooks
        self.dirparser = None
        self.formatter = None

    def run(self):
        """ EntryPoint Of Application """
        # Parse Project for Roles and Playbooks
        self.dirparser = DirParser(self.project)

        # Based on chosen style, use the associated formatter
        parserdata = self.dirparser.get_parserdata()
        
        paths = self.dirparser.get_paths()
        if self.style == "markdown":
            self.formatter = Formatter('markdown', parserdata, paths,\
                                        self.project, self.params)
            self.formatter.parse_data()
            self.formatter.write_files()
        else:
            print("Error: Use of an unsupported style.\
                The supported styles are: markdown")
            sys.exit(1)
Esempio n. 2
0
class Cli(object):
    """ Command Line Interface for ansible-docgen """
    def __init__(self):
        """ Setup Arguments and Options for CLI """
        # Parse CLI Arguments
        parser = optparse.OptionParser()
        parser.add_option("-p",
                          "--project",
                          dest="project",
                          help="Path to Ansible project",
                          metavar="PROJECT",
                          default="./")
        parser.add_option("-s",
                          "--style",
                          dest="style",
                          help="Choose the format for the documentation.\
                          Default is markup. Example: --style=[markup]",
                          metavar="STYLE",
                          default="markup")
        (self.options, self.args) = parser.parse_args()

        # Used to Parse Roles and Playbooks
        self.dirparser = None
        self.formatter = None

    def run(self):
        """ Entry Point Of Application """
        # Make sure there is a trailing /
        project = os.path.join(self.options.project, "")

        # Parse Project for Roles and Playbooks
        self.dirparser = DirParser(project)

        # Based on chosen style, use the associated formatter
        if self.options.style == "markup":
            self.formatter = FormatterMarkup(self.dirparser.get_parserdata(),
                                             project)
            self.formatter.parse_data()
            self.formatter.write_files()
        else:
            print("Error: Use of an unsupported style.\
                The supported styles are: markup")
            sys.exit(1)

        sys.exit(0)
Esempio n. 3
0
class Cli(object):
    """ Command Line Interface for ansible-docgen """

    def __init__(self):
        """ Setup Arguments and Options for CLI """
        # Parse CLI Arguments
        parser = optparse.OptionParser()
        parser.add_option("-p", "--project", dest="project",
                          help="Path to Ansible project",
                          metavar="PROJECT",
                          default="./")
        parser.add_option("-s", "--style", dest="style",
                          help="Choose the format for the documentation.\
                          Default is markup. Example: --style=[markup]",
                          metavar="STYLE",
                          default="markup")
        (self.options, self.args) = parser.parse_args()

        # Used to Parse Roles and Playbooks
        self.dirparser = None
        self.formatter = None

    def run(self):
        """ Entry Point Of Application """
        # Make sure there is a trailing /
        project = os.path.join(self.options.project, "")

        # Parse Project for Roles and Playbooks
        self.dirparser = DirParser(project)

        # Based on chosen style, use the associated formatter
        if self.options.style == "markup":
            self.formatter = FormatterMarkup(
                self.dirparser.get_parserdata(), project)
            self.formatter.parse_data()
            self.formatter.write_files()
        else:
            print("Error: Use of an unsupported style.\
                The supported styles are: markup")
            sys.exit(1)

        sys.exit(0)
Esempio n. 4
0
    def test_parserdata(self):
        localdir = os.path.dirname(os.path.realpath(__file__))
        projectunit = os.path.join(localdir, "../integration/projectunit")
        dirparser = DirParser(projectunit)
        parserdata = dirparser.get_parserdata()

        # Check for expected attributes in sourcedata
        assert ("playbooks" in parserdata)
        for folder_content, sourcedata in parserdata["playbooks"].items():
            assert ("name" in sourcedata[0])
            assert ("relative_path" in sourcedata[0])
        assert ("roles" in parserdata)
        for folder_content, sourcedata in parserdata["roles"].items():
            assert ("name" in sourcedata[0])
            assert ("relative_path" in sourcedata[0])
        assert ("host_vars" in parserdata)
        for hostname, contents in parserdata["host_vars"].items():
            assert ("host_1" in hostname)
            assert ("position" in contents)
            assert ("relative_path" in contents["position"])