Exemple #1
0
def main():
    parser = argparse.ArgumentParser(
        description='Generate Content Docs',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("-t",
                        "--target",
                        help="Target dir to generate docs at.",
                        required=True)
    parser.add_argument("-d", "--dir", help="Content repo dir.", required=True)
    args = parser.parse_args()
    print(f'Using multiprocess pool size: {POOL_SIZE}')
    print('Starting MDX server...')
    start_mdx_server()
    prefix = os.path.basename(args.target)
    integrations_full_prefix = f'{prefix}/{INTEGRATIONS_PREFIX}'
    scripts_full_prefix = f'{prefix}/{SCRIPTS_PREFIX}'
    playbooks_full_prefix = f'{prefix}/{PLAYBOOKS_PREFIX}'
    releases_full_prefix = f'{prefix}/{RELEASES_PREFIX}'
    articles_full_prefix = f'{prefix}/{ATRICLES_PREFIX}'
    integration_doc_infos = create_docs(args.dir, args.target,
                                        INTEGRATION_DOCS_MATCH,
                                        INTEGRATIONS_PREFIX)
    playbooks_doc_infos = create_docs(args.dir, args.target,
                                      PLAYBOOKS_DOCS_MATCH, PLAYBOOKS_PREFIX)
    script_doc_infos = create_docs(args.dir, args.target, SCRIPTS_DOCS_MATCH,
                                   SCRIPTS_PREFIX)
    release_doc_infos = create_releases(args.target)
    article_doc_infos = create_articles(args.target)
    index_base = f'{os.path.dirname(os.path.abspath(__file__))}/reference-index.md'
    index_target = args.target + '/index.md'
    shutil.copy(index_base, index_target)
    with open(index_target, 'a', encoding='utf-8') as f:
        if MAX_FILES > 0:
            f.write(
                f'\n\n# =====<br/>BUILD PREVIEW only {MAX_FILES} files from each category! <br/>=====\n\n'
            )
        f.write("\n\n## Integrations\n\n")
        f.write(index_doc_infos(integration_doc_infos, INTEGRATIONS_PREFIX))
        f.write("\n\n## Playbooks\n\n")
        f.write(index_doc_infos(playbooks_doc_infos, PLAYBOOKS_PREFIX))
        f.write("\n\n## Scripts\n\n")
        f.write(index_doc_infos(script_doc_infos, SCRIPTS_PREFIX))
        f.write("\n\n## Articles\n\n")
        f.write(index_doc_infos(article_doc_infos, ATRICLES_PREFIX))
        f.write("\n\n## Content Release Notes\n\n")
        f.write(
            index_doc_infos(release_doc_infos,
                            RELEASES_PREFIX,
                            headers=('Name', 'Date')))
    integration_items = [
        f'{integrations_full_prefix}/{d.id}' for d in integration_doc_infos
    ]
    playbook_items = [
        f'{playbooks_full_prefix}/{d.id}' for d in playbooks_doc_infos
    ]
    script_items = [f'{scripts_full_prefix}/{d.id}' for d in script_doc_infos]
    article_items = [
        f'{articles_full_prefix}/{d.id}' for d in article_doc_infos
    ]
    release_items = [
        f'{releases_full_prefix}/{d.id}' for d in release_doc_infos
    ]
    sidebar = [
        {
            "type": "doc",
            "id": f'{prefix}/index'
        },
        {
            "type": "category",
            "label": "Integrations",
            "items": integration_items
        },
        {
            "type": "category",
            "label": "Playbooks",
            "items": playbook_items
        },
        {
            "type": "category",
            "label": "Scripts",
            "items": script_items
        },
        {
            "type": "category",
            "label": "Articles",
            "items": article_items
        },
        {
            "type": "category",
            "label": "Content Release Notes",
            "items": release_items
        },
    ]
    with open(f'{args.target}/sidebar.json', 'w') as f:
        json.dump(sidebar, f, indent=4)
    print('Stopping mdx server ...')
    stop_mdx_server()
Exemple #2
0
def mdx_server():
    yield start_mdx_server()
    print('Cleaning up MDX server')
    stop_mdx_server()
Exemple #3
0
def main():
    parser = argparse.ArgumentParser(
        description=
        '''Generate Content Docs. You should probably not call this script directly.
See: https://github.com/demisto/content-docs/#generating-reference-docs''',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("-t",
                        "--target",
                        help="Target dir to generate docs at.",
                        required=True)
    parser.add_argument("-d", "--dir", help="Content repo dir.", required=True)
    args = parser.parse_args()
    print(f'Using multiprocess pool size: {POOL_SIZE}')
    print('Starting MDX server...')
    start_mdx_server()
    prefix = os.path.basename(args.target)
    integrations_full_prefix = f'{prefix}/{INTEGRATIONS_PREFIX}'
    scripts_full_prefix = f'{prefix}/{SCRIPTS_PREFIX}'
    playbooks_full_prefix = f'{prefix}/{PLAYBOOKS_PREFIX}'
    releases_full_prefix = f'{prefix}/{RELEASES_PREFIX}'
    articles_full_prefix = f'{prefix}/{ARTICLES_PREFIX}'
    packs_articles_full_prefix = f'{prefix}/{PACKS_PREFIX}'
    integration_doc_infos = create_docs(
        args.dir,
        args.target,
        INTEGRATION_DOCS_MATCH,
        INTEGRATIONS_PREFIX,
        private_pack_prefix=PRIVATE_PACKS_INTEGRATIONS_PREFIX)
    playbooks_doc_infos = create_docs(
        args.dir,
        args.target,
        PLAYBOOKS_DOCS_MATCH,
        PLAYBOOKS_PREFIX,
        private_pack_prefix=PRIVATE_PACKS_PLAYBOOKS_PREFIX)
    script_doc_infos = create_docs(
        args.dir,
        args.target,
        SCRIPTS_DOCS_MATCH,
        SCRIPTS_PREFIX,
        private_pack_prefix=PRIVATE_PACKS_SCRIPTS_PREFIX)
    release_doc_infos = create_releases(args.target)
    article_doc_infos = create_articles(args.target, ARTICLES_PREFIX)
    packs_articles_doc_infos = create_articles(args.target, PACKS_PREFIX)
    if os.getenv('SKIP_DEPRECATED') not in ('true', 'yes', '1'):
        add_deprected_integrations_info(
            args.dir, f'{args.target}/{ARTICLES_PREFIX}/deprecated.md',
            DEPRECATED_INFO_FILE, f'{args.target}/../../static/assets')
    index_base = f'{os.path.dirname(os.path.abspath(__file__))}/reference-index.md'
    index_target = args.target + '/index.md'
    articles_index_target = args.target + '/articles-index.md'
    articles_index_base = f'{os.path.dirname(os.path.abspath(__file__))}/articles-index.md'
    shutil.copy(index_base, index_target)
    shutil.copy(articles_index_base, articles_index_target)
    with open(index_target, 'a', encoding='utf-8') as f:
        if MAX_FILES > 0:
            f.write(
                f'\n\n# =====<br/>BUILD PREVIEW only {MAX_FILES} files from each category! <br/>=====\n\n'
            )
        f.write("\n\n## Integrations\n\n")
        f.write(index_doc_infos(integration_doc_infos, INTEGRATIONS_PREFIX))
        f.write("\n\n## Playbooks\n\n")
        f.write(index_doc_infos(playbooks_doc_infos, PLAYBOOKS_PREFIX))
        f.write("\n\n## Scripts\n\n")
        f.write(index_doc_infos(script_doc_infos, SCRIPTS_PREFIX))
        f.write("\n\n## API Reference\n\n")
        api_docs: List[DocInfo] = [
            DocInfo(
                'demisto-class', 'Demisto Class',
                'The object exposes a series of API methods which are used to retrieve and send data to the Cortex XSOAR Server.',
                ''),
            DocInfo(
                'common-server-python', 'Common Server Python',
                'Common functions that will be appended to the code of each integration/script before being executed.',
                ''),
        ]
        f.write(index_doc_infos(api_docs, 'api'))
        f.write("\n\n## Content Release Notes\n\n")
        f.write(
            index_doc_infos(release_doc_infos,
                            RELEASES_PREFIX,
                            headers=('Name', 'Date')))
        f.write(
            "\n\nAdditional archived release notes are available"
            " [here](https://github.com/demisto/content-docs/tree/master/content-repo/extra-docs/releases)."
        )
    with open(articles_index_target, 'a', encoding='utf-8') as f:
        if MAX_FILES > 0:
            f.write(
                f'\n\n# =====<br/>BUILD PREVIEW only {MAX_FILES} files from each category! <br/>=====\n\n'
            )
        f.write(index_doc_infos(article_doc_infos, ARTICLES_PREFIX))

    integration_items = generate_items(integration_doc_infos,
                                       integrations_full_prefix)
    playbook_items = generate_items(playbooks_doc_infos, playbooks_full_prefix)
    script_items = generate_items(script_doc_infos, scripts_full_prefix)
    packs_articles_items = [
        f'{packs_articles_full_prefix}/{d.id}'
        for d in packs_articles_doc_infos
    ]

    article_items = [
        f'{articles_full_prefix}/{d.id}' for d in article_doc_infos
    ]
    article_items.insert(0, f'{prefix}/articles-index')
    release_items = [
        f'{releases_full_prefix}/{d.id}' for d in release_doc_infos
    ]
    sidebar = [
        {
            "type": "doc",
            "id": f'{prefix}/index'
        },
        {
            "type": "category",
            "label": "Packs",
            "items": packs_articles_items
        },
        {
            "type": "category",
            "label": "Integrations",
            "items": integration_items
        },
        {
            "type": "category",
            "label": "Playbooks",
            "items": playbook_items
        },
        {
            "type": "category",
            "label": "Scripts",
            "items": script_items
        },
        {
            "type": "category",
            "label": "Content Release Notes",
            "items": release_items
        },
    ]
    with open(f'{args.target}/sidebar.json', 'w') as f:
        json.dump(sidebar, f, indent=4)
    articles_sidebar = article_items
    with open(f'{args.target}/articles-sidebar.json', 'w') as f:
        json.dump(articles_sidebar, f, indent=4)
    print('Stopping mdx server ...')
    stop_mdx_server()
    if os.getenv('UPDATE_PACK_DOCS') or os.getenv('CI'):
        # to avoid cases that in local dev someone might checkin the modifed pack-docs.md we do this only if explicityl asked for or in CI env
        insert_approved_tags_and_usecases()

    print("Writing json links into contentItemsDocsLinks.json")
    with open('contentItemsDocsLinks.json', 'w') as file:
        json.dump(DOCS_LINKS_JSON, file)