How to use the hacking.build_library.build_ansible.commands.Command function in hacking

To help you get started, we’ve selected a few hacking examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / ansible / hacking / build_library / build_ansible / command_plugins / porting_guide.py View on Github external
version_list = version.split('.')
    version_list[-1] = str(int(version_list[-1]) - 1)
    previous_version = '.'.join(version_list)

    content = template.render(ver=version, prev_ver=previous_version)
    return content


def write_guide(version, guide_content):
    filename = 'porting_guide_{0}.rst'.format(version)
    with open(filename, 'w') as out_file:
        out_file.write(guide_content)


class PortingGuideCommand(Command):
    name = 'porting-guide'

    @classmethod
    def init_parser(cls, add_parser):
        parser = add_parser(cls.name, description="Generate a fresh porting guide template")
        parser.add_argument("--version", dest="version", type=str, required=True, action='store',
                            help="Version of Ansible to write the porting guide for")

    @staticmethod
    def main(args):
        guide_content = generate_porting_guide(args.version)
        write_guide(args.version, guide_content)
        return 0
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / plugin_formatter.py View on Github external
text = templates['support_list'].render(template_data)
        write_data(text, output_dir, data['output'])


def validate_options(options):
    ''' validate option parser options '''

    if not options.module_dir:
        sys.exit("--module-dir is required", file=sys.stderr)
    if not os.path.exists(options.module_dir):
        sys.exit("--module-dir does not exist: %s" % options.module_dir, file=sys.stderr)
    if not options.template_dir:
        sys.exit("--template-dir must be specified")


class DocumentPlugins(Command):
    name = 'document-plugins'

    @classmethod
    def init_parser(cls, add_parser):
        parser = add_parser(cls.name, description='Generate module documentation from metadata')

        parser.add_argument("-A", "--ansible-version", action="store", dest="ansible_version",
                            default="unknown", help="Ansible version number")
        parser.add_argument("-M", "--module-dir", action="store", dest="module_dir",
                            default=MODULEDIR, help="Ansible library path")
        parser.add_argument("-P", "--plugin-type", action="store", dest="plugin_type",
                            default='module', help="The type of plugin (module, lookup, etc)")
        parser.add_argument("-T", "--template-dir", action="append", dest="template_dir",
                            help="directory containing Jinja2 templates")
        parser.add_argument("-t", "--type", action='store', dest='type', choices=['rst'],
                            default='rst', help="Document type")
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / dump_keywords.py View on Github external
def generate_page(pb_keywords, template_dir):
    env = Environment(loader=FileSystemLoader(template_dir), trim_blocks=True,)
    template = env.get_template(TEMPLATE_FILE)
    tempvars = {'pb_keywords': pb_keywords, 'playbook_class_names': PLAYBOOK_CLASS_NAMES}

    keyword_page = template.render(tempvars)
    if LooseVersion(jinja2.__version__) < LooseVersion('2.10'):
        # jinja2 < 2.10's indent filter indents blank lines.  Cleanup
        keyword_page = re.sub(' +\n', '\n', keyword_page)

    return keyword_page


class DocumentKeywords(Command):
    name = 'document-keywords'

    @classmethod
    def init_parser(cls, add_parser):
        parser = add_parser(cls.name, description='Generate playbook keyword documentation from'
                            ' code and descriptions')
        parser.add_argument("-T", "--template-dir", action="store", dest="template_dir",
                            default=DEFAULT_TEMPLATE_DIR,
                            help="directory containing Jinja2 templates")
        parser.add_argument("-o", "--output-dir", action="store", dest="output_dir",
                            default='/tmp/', help="Output directory for rst files")
        parser.add_argument("keyword_defs", metavar="KEYWORD-DEFINITIONS.yml", type=str,
                            help="Source for playbook keyword docs")

    @staticmethod
    def main(args):
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / collection_meta.py View on Github external
from ..commands import Command  # pylint: disable=relative-beyond-top-level
from ..jinja2.filters import documented_type, rst_ify  # pylint: disable=relative-beyond-top-level


DEFAULT_TEMPLATE_FILE = 'collections_galaxy_meta.rst.j2'
DEFAULT_TEMPLATE_DIR = pathlib.Path(__file__).parents[4] / 'docs/templates'


def normalize_options(options):
    """Normalize the options to make for easy templating"""
    for opt in options:
        if isinstance(opt['description'], string_types):
            opt['description'] = [opt['description']]


class DocumentCollectionMeta(Command):
    name = 'collection-meta'

    @classmethod
    def init_parser(cls, add_parser):
        parser = add_parser(cls.name, description='Generate collection galaxy.yml documentation from shared metadata')
        parser.add_argument("-t", "--template-file", action="store", dest="template_file",
                            default=DEFAULT_TEMPLATE_FILE,
                            help="Jinja2 template to use for the config")
        parser.add_argument("-T", "--template-dir", action="store", dest="template_dir",
                            default=DEFAULT_TEMPLATE_DIR,
                            help="directory containing Jinja2 templates")
        parser.add_argument("-o", "--output-dir", action="store", dest="output_dir", default='/tmp/',
                            help="Output directory for rst files")
        parser.add_argument("collection_defs", metavar="COLLECTION-OPTION-DEFINITIONS.yml", type=str,
                            help="Source for collection metadata option docs")
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / generate_man.py View on Github external
action_info['options'] = uncommon_options

            depth = 1 + get_actions(parser, action_info)

            docs['actions'][action] = action_info

        return depth

    action_depth = get_actions(cli.parser, docs)
    docs['content_depth'] = action_depth + 1

    docs['options'] = opt_doc_list(cli.parser)
    return docs


class GenerateMan(Command):
    name = 'generate-man'

    @classmethod
    def init_parser(cls, add_parser):
        parser = add_parser(name=cls.name,
                            description='Generate cli documentation from cli docstrings')

        parser.add_argument("-t", "--template-file", action="store", dest="template_file",
                            default=DEFAULT_TEMPLATE_FILE, help="path to jinja2 template")
        parser.add_argument("-o", "--output-dir", action="store", dest="output_dir",
                            default='/tmp/', help="Output directory for rst files")
        parser.add_argument("-f", "--output-format", action="store", dest="output_format",
                            default='man',
                            help="Output format for docs (the default 'man' or 'rst')")
        parser.add_argument('cli_modules', help='CLI module name(s)', metavar='MODULE_NAME', nargs='*')
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / release_announcement.py View on Github external
new_versions.append(VersionStr(version))
    args.versions = new_versions

    return args


def write_message(filename, message):
    if filename != '-':
        with open(filename, 'w') as out_file:
            out_file.write(message)
    else:
        sys.stdout.write('\n\n')
        sys.stdout.write(message)


class ReleaseAnnouncementCommand(Command):
    name = 'release-announcement'

    @classmethod
    def init_parser(cls, add_parser):
        parser = add_parser(cls.name,
                            description="Generate email and twitter announcements from template")

        parser.add_argument("--version", dest="versions", type=str, required=True, action='append',
                            help="Versions of Ansible to announce")
        parser.add_argument("--name", type=str, required=True, help="Real name to use on emails")
        parser.add_argument("--email-out", type=str, default="-",
                            help="Filename to place the email announcement into")
        parser.add_argument("--twitter-out", type=str, default="-",
                            help="Filename to place the twitter announcement into")

    @classmethod
github ansible / ansible / hacking / build_library / build_ansible / command_plugins / dump_config.py View on Github external
def fix_description(config_options):
    '''some descriptions are strings, some are lists. workaround it...'''

    for config_key in config_options:
        description = config_options[config_key].get('description', [])
        if isinstance(description, list):
            desc_list = description
        else:
            desc_list = [description]
        config_options[config_key]['description'] = desc_list
    return config_options


class DocumentConfig(Command):
    name = 'document-config'

    @classmethod
    def init_parser(cls, add_parser):
        parser = add_parser(cls.name, description='Generate module documentation from metadata')
        parser.add_argument("-t", "--template-file", action="store", dest="template_file",
                            default=DEFAULT_TEMPLATE_FILE,
                            help="Jinja2 template to use for the config")
        parser.add_argument("-T", "--template-dir", action="store", dest="template_dir",
                            default=DEFAULT_TEMPLATE_DIR,
                            help="directory containing Jinja2 templates")
        parser.add_argument("-o", "--output-dir", action="store", dest="output_dir", default='/tmp/',
                            help="Output directory for rst files")
        parser.add_argument("config_defs", metavar="CONFIG-OPTION-DEFINITIONS.yml", type=str,
                            help="Source for config option docs")