コード例 #1
0
def ask_user(d):
    """Wrap sphinx.cmd.quickstart.ask_user, and add additional questions."""

    # Print welcome message
    msg = bold('Welcome to the Hieroglyph %s quickstart utility.') % (
        version(), )
    print(msg)
    msg = """
This will ask questions for creating a Hieroglyph project, and then ask
some basic Sphinx questions.
"""
    print(msg)

    # set a few defaults that we don't usually care about for Hieroglyph
    d.update({
        'version': datetime.date.today().strftime('%Y.%m.%d'),
        'release': datetime.date.today().strftime('%Y.%m.%d'),
        'make_mode': True,
    })

    if 'project' not in d:
        print('''
The presentation title will be included on the title slide.''')
        d['project'] = sphinx_quickstart.do_prompt('Presentation title')
    if 'author' not in d:
        d['author'] = sphinx_quickstart.do_prompt('Author name(s)')

    # slide_theme
    theme_entrypoints = pkg_resources.iter_entry_points('hieroglyph.theme')

    themes = [t.load() for t in theme_entrypoints]

    msg = """
Available themes:

"""

    for theme in themes:
        msg += '\n'.join([
            bold(theme['name']),
            theme['desc'],
            '',
            '',
        ])

    msg += """Which theme would you like to use?"""
    print(msg)

    d['slide_theme'] = sphinx_quickstart.do_prompt(
        'Slide Theme',
        themes[0]['name'],
        sphinx_quickstart.choice(*[t['name'] for t in themes]),
    )

    # Ask original questions
    print("")
    sphinx_quickstart.ask_user(d)
コード例 #2
0
ファイル: test_quickstart.py プロジェクト: wwjiang007/sphinx
def test_do_prompt_inputstrip():
    answers = {
        'Q1': 'Y',
        'Q2': ' Yes ',
        'Q3': 'N',
        'Q4': 'N ',
    }
    qs.term_input = mock_input(answers)

    assert qs.do_prompt('Q1') == 'Y'
    assert qs.do_prompt('Q2') == 'Yes'
    assert qs.do_prompt('Q3') == 'N'
    assert qs.do_prompt('Q4') == 'N'
コード例 #3
0
ファイル: test_quickstart.py プロジェクト: sam-m888/sphinx
def test_do_prompt_inputstrip():
    answers = {
        'Q1': 'Y',
        'Q2': ' Yes ',
        'Q3': 'N',
        'Q4': 'N ',
    }
    qs.term_input = mock_input(answers)

    assert qs.do_prompt('Q1') == 'Y'
    assert qs.do_prompt('Q2') == 'Yes'
    assert qs.do_prompt('Q3') == 'N'
    assert qs.do_prompt('Q4') == 'N'
コード例 #4
0
ファイル: test_quickstart.py プロジェクト: wwjiang007/sphinx
def test_do_prompt_with_nonascii():
    answers = {
        'Q1': '\u30c9\u30a4\u30c4',
    }
    qs.term_input = mock_input(answers)
    result = qs.do_prompt('Q1', default='\u65e5\u672c')
    assert result == '\u30c9\u30a4\u30c4'
コード例 #5
0
def test_do_prompt_with_nonascii():
    answers = {
        'Q1': u'\u30c9\u30a4\u30c4',
    }
    qs.term_input = mock_input(answers)
    try:
        result = qs.do_prompt('Q1', default=u'\u65e5\u672c')
    except UnicodeEncodeError:
        raise pytest.skip.Exception(
            'non-ASCII console input not supported on this encoding: %s',
            qs.TERM_ENCODING)
    assert result == u'\u30c9\u30a4\u30c4'
コード例 #6
0
ファイル: test_quickstart.py プロジェクト: sam-m888/sphinx
def test_do_prompt_with_nonascii():
    answers = {
        'Q1': u'\u30c9\u30a4\u30c4',
    }
    qs.term_input = mock_input(answers)
    try:
        result = qs.do_prompt('Q1', default=u'\u65e5\u672c')
    except UnicodeEncodeError:
        raise pytest.skip.Exception(
            'non-ASCII console input not supported on this encoding: %s',
            qs.TERM_ENCODING)
    assert result == u'\u30c9\u30a4\u30c4'
コード例 #7
0
ファイル: test_quickstart.py プロジェクト: wwjiang007/sphinx
def test_do_prompt():
    answers = {
        'Q2': 'v2',
        'Q3': 'v3',
        'Q4': 'yes',
        'Q5': 'no',
        'Q6': 'foo',
    }
    qs.term_input = mock_input(answers)

    assert qs.do_prompt('Q1', default='v1') == 'v1'
    assert qs.do_prompt('Q3', default='v3_default') == 'v3'
    assert qs.do_prompt('Q2') == 'v2'
    assert qs.do_prompt('Q4', validator=qs.boolean) is True
    assert qs.do_prompt('Q5', validator=qs.boolean) is False
    with pytest.raises(AssertionError):
        qs.do_prompt('Q6', validator=qs.boolean)
コード例 #8
0
ファイル: test_quickstart.py プロジェクト: sam-m888/sphinx
def test_do_prompt():
    answers = {
        'Q2': 'v2',
        'Q3': 'v3',
        'Q4': 'yes',
        'Q5': 'no',
        'Q6': 'foo',
    }
    qs.term_input = mock_input(answers)

    assert qs.do_prompt('Q1', default='v1') == 'v1'
    assert qs.do_prompt('Q3', default='v3_default') == 'v3'
    assert qs.do_prompt('Q2') == 'v2'
    assert qs.do_prompt('Q4', validator=qs.boolean) is True
    assert qs.do_prompt('Q5', validator=qs.boolean) is False
    with pytest.raises(AssertionError):
        qs.do_prompt('Q6', validator=qs.boolean)
コード例 #9
0
ファイル: start.py プロジェクト: tg-m/ablog
def ask_user(d):
    """
    Borrowed from Sphinx 1.3b3.

    Ask the user for quickstart values missing from *d*.

    Values are:

    * path:      root path
    * project:   project name
    * author:    author names
    * version:   version of project
    * release:   release of project
    """

    d.update(CONF_DEFAULTS)

    print(bold(f"Welcome to the ABlog {__version__} quick start utility."))
    print("")
    print(
        w("Please enter values for the following settings (just press Enter "
          "to accept a default value, if one is given in brackets)."))

    print("")
    if "path" in d:
        print(bold(f"Selected root path: {d['path']}"))
    else:
        print("Enter the root path for your blog project (path has to exist).")
        d["path"] = do_prompt("Root path for your project (path has to exist)",
                              ".", is_path)

    while path.isfile(path.join(d["path"], "conf.py")) or path.isfile(
            path.join(d["path"], "source", "conf.py")):
        print("")
        print(
            bold(
                w("Error: an existing conf.py has been found in the "
                  "selected root path.")))
        print("ablog start will not overwrite existing Sphinx projects.")
        print("")
        d["path"] = do_prompt(
            "Please enter a new root path (or just Enter to exit)", ".",
            is_path)
        if not d["path"]:
            sys.exit(1)

    if "project" not in d:
        print("")
        print(
            w("Project name will occur in several places in the website, "
              "including blog archive pages and atom feeds. Later, you can "
              "set separate names for different parts of the website in "
              "configuration file."))
        d["project"] = do_prompt("Project name")

    if "author" not in d:
        print(
            w("This of author as the copyright holder of the content. "
              "If your blog has multiple authors, you might want to enter "
              "a team name here. Later, you can specify individual authors "
              "using `blog_authors` configuration option."))
        d["author"] = do_prompt("Author name(s)")

    d["release"] = d["version"] = ""

    while path.isfile(path.join(
            d["path"], d["master"] + d["suffix"])) or path.isfile(
                path.join(d["path"], "source", d["master"] + d["suffix"])):
        print("")
        print(
            bold(
                w(f"Error: the master file {d['master'] + d['suffix']} has already been found in the "
                  "selected root path.")))
        print("ablog-start will not overwrite the existing file.")
        print("")
        d["master"] = do_prompt(
            w("Please enter a new file name, or rename the "
              "existing file and press Enter"), d["master"])

    if "blog_baseurl" not in d:
        print("")
        print(
            w("Please enter the base URL for your project. Blog feeds will "
              "be generated relative to this URL. If you don't have one yet, "
              "you can set it in configuration file later."))
        d["blog_baseurl"] = do_prompt("Base URL for your project", None,
                                      lambda x: x)

    print("")