Пример #1
0
def get_clear_path(fields):
    while os.path.isfile(os.path.join(fields['path'], 'conf.py')):
        print bold('\nError: your path already has a conf.py.')
        print 'sffms-quickstart will not overwrite existing projects.\n'
        do_prompt(fields, 'path', 'Please enter a new path (or just Enter to exit)', '', is_path)
        if not fields['path']:
            sys.exit(1)
Пример #2
0
def test_do_prompt_with_multibyte():
    d = {}
    answers = {
        'Q1': u'\u30c9\u30a4\u30c4',
    }
    qs.term_input = mock_raw_input(answers)
    qs.do_prompt(d, 'k1', 'Q1', default=u'\u65e5\u672c')
    assert d['k1'] == u'\u30c9\u30a4\u30c4'
Пример #3
0
def test_do_prompt_with_nonascii():
    d = {}
    answers = {
        'Q1': u'\u30c9\u30a4\u30c4',
    }
    qs.term_input = mock_input(answers)
    try:
        qs.do_prompt(d, 'k1', 'Q1', default=u'\u65e5\u672c')
    except UnicodeEncodeError:
        raise SkipTest(
            'non-ASCII console input not supported on this encoding: %s',
            qs.TERM_ENCODING)
    assert d['k1'] == u'\u30c9\u30a4\u30c4'
Пример #4
0
def ask_user(d):
    """Wrap sphinx_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'),
        'ext_autodoc': False,
        'ext_doctest': True,
        'ext_intersphinx': True,
        'ext_todo': True,
        'ext_coverage': True,
        'ext_pngmath': True,
        'ext_mathjax': False,
        'ext_ifconfig': True,
        'ext_viewcode': False,
    })

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

    # slide_theme
    msg = """
Hieroglyph includes two themes:

* """ + bold("slides") + """
  The default theme, with different styling for first, second, and third
  level headings.

* """ + bold("single-level") + """
  All slides are styled the same, with the heading at the top.

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

    # XXX make a themes dict that has the keys/descriptions
    sphinx_quickstart.do_prompt(
        d, 'slide_theme', 'Slide Theme', 'slides',
        sphinx_quickstart.choice('slides', 'single-level',),
    )

    # Ask original questions
    print("")
    sphinx_ask_user(d)
Пример #5
0
def prompt_address(fields):
    """ 
    Prompts for a multi-line address. If the user enters a blank line, we stop.
    If the user enters a blank line on the first entry, we set the address to None.
    Otherwise, we build the address up up line by line.
    """
    i = 1
    fields['address'] = ''
    while True:
        address_line = 'address{0}'.format(i)
        do_prompt(fields, address_line, 'Enter address line {0}'.format(i), validator=ok)
        if fields[address_line].strip() is '':
            if i == 1:
                fields['address'] = None
            else:
                fields['address'] = "'''" + py_sanitize(fields['address']) + "'''"
            break
        else:
            if i > 1:
                fields['address'] += '\n'
            fields['address'] += fields[address_line].strip()
            i = i + 1
Пример #6
0
def test_quickstart_inputstrip():
    d = {}
    answers = {
        'Q1': 'Y',
        'Q2': ' Yes ',
        'Q3': 'N',
        'Q4': 'N ',
    }
    qs.term_input = mock_input(answers)
    qs.do_prompt(d, 'k1', 'Q1')
    assert d['k1'] == 'Y'
    qs.do_prompt(d, 'k2', 'Q2')
    assert d['k2'] == 'Yes'
    qs.do_prompt(d, 'k3', 'Q3')
    assert d['k3'] == 'N'
    qs.do_prompt(d, 'k4', 'Q4')
    assert d['k4'] == 'N'
Пример #7
0
def test_quickstart_inputstrip():
    d = {}
    answers = {
        'Q1': 'Y\r',  # input() return with '\r' on Python-3.2.0 for Windows
        'Q2': ' Yes \r',
        'Q3': 'N',
        'Q4': 'N ',
    }
    qs.term_input = mock_raw_input(answers)
    qs.do_prompt(d, 'k1', 'Q1')
    assert d['k1'] == 'Y'
    qs.do_prompt(d, 'k2', 'Q2')
    assert d['k2'] == 'Yes'
    qs.do_prompt(d, 'k3', 'Q3')
    assert d['k3'] == 'N'
    qs.do_prompt(d, 'k4', 'Q4')
    assert d['k4'] == 'N'
Пример #8
0
def test_do_prompt():
    d = {}
    answers = {"Q2": "v2", "Q3": "v3", "Q4": "yes", "Q5": "no", "Q6": "foo"}
    qs.term_input = mock_raw_input(answers)
    try:
        qs.do_prompt(d, "k1", "Q1")
    except AssertionError:
        assert "k1" not in d
    else:
        assert False, "AssertionError not raised"
    qs.do_prompt(d, "k1", "Q1", default="v1")
    assert d["k1"] == "v1"
    qs.do_prompt(d, "k3", "Q3", default="v3_default")
    assert d["k3"] == "v3"
    qs.do_prompt(d, "k2", "Q2")
    assert d["k2"] == "v2"
    qs.do_prompt(d, "k4", "Q4", validator=qs.boolean)
    assert d["k4"] is True
    qs.do_prompt(d, "k5", "Q5", validator=qs.boolean)
    assert d["k5"] is False
    raises(AssertionError, qs.do_prompt, d, "k6", "Q6", validator=qs.boolean)
Пример #9
0
def test_do_prompt():
    d = {}
    answers = {
        'Q2': 'v2',
        'Q3': 'v3',
        'Q4': 'yes',
        'Q5': 'no',
        'Q6': 'foo',
    }
    qs.term_input = mock_input(answers)
    try:
        qs.do_prompt(d, 'k1', 'Q1')
    except AssertionError:
        assert 'k1' not in d
    else:
        assert False, 'AssertionError not raised'
    qs.do_prompt(d, 'k1', 'Q1', default='v1')
    assert d['k1'] == 'v1'
    qs.do_prompt(d, 'k3', 'Q3', default='v3_default')
    assert d['k3'] == 'v3'
    qs.do_prompt(d, 'k2', 'Q2')
    assert d['k2'] == 'v2'
    qs.do_prompt(d, 'k4', 'Q4', validator=qs.boolean)
    assert d['k4'] is True
    qs.do_prompt(d, 'k5', 'Q5', validator=qs.boolean)
    assert d['k5'] is False
    raises(AssertionError, qs.do_prompt, d, 'k6', 'Q6', validator=qs.boolean)
Пример #10
0
def test_do_prompt():
    d = {}
    answers = {
        'Q2': 'v2',
        'Q3': 'v3',
        'Q4': 'yes',
        'Q5': 'no',
        'Q6': 'foo',
    }
    qs.term_input = mock_input(answers)
    try:
        qs.do_prompt(d, 'k1', 'Q1')
    except AssertionError:
        assert 'k1' not in d
    else:
        assert False, 'AssertionError not raised'
    qs.do_prompt(d, 'k1', 'Q1', default='v1')
    assert d['k1'] == 'v1'
    qs.do_prompt(d, 'k3', 'Q3', default='v3_default')
    assert d['k3'] == 'v3'
    qs.do_prompt(d, 'k2', 'Q2')
    assert d['k2'] == 'v2'
    qs.do_prompt(d, 'k4', 'Q4', validator=qs.boolean)
    assert d['k4'] is True
    qs.do_prompt(d, 'k5', 'Q5', validator=qs.boolean)
    assert d['k5'] is False
    raises(AssertionError, qs.do_prompt, d, 'k6', 'Q6', validator=qs.boolean)
Пример #11
0
def qsp_do_prompt(d, key, text, default=None, validator=nonempty):
    default = hook_d.get(key, default)
    if isinstance(default, bool):
        default = 'y' if hook_d[key] else 'n'
    do_prompt(d, key, text, default, validator)
Пример #12
0
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('Welcome to the ABlog %s quick start utility.') % __version__)
    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('Selected root path: %s' % d['path']))
    else:
        print('Enter the root path for your blog project.')
        do_prompt(d, 'path', 'Root path for your project', '.', 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('')
        do_prompt(d, 'path',
            '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.'))
        do_prompt(d, 'project', '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.'))
        do_prompt(d, 'author', '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('Error: the master file %s has already been found in the '
                   'selected root path.' % (d['master'] + d['suffix']))))
        print('ablog-start will not overwrite the existing file.')
        print('')
        do_prompt(d, 'master', 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.'))
        do_prompt(d, 'blog_baseurl', 'Base URL for your project',
            None, lambda x: True)

    print('')
Пример #13
0
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('Welcome to the ABlog %s quick start utility.') % __version__)
    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('Selected root path: %s' % d['path']))
    else:
        print('Enter the root path for your blog project.')
        if SPHINX_LT_17:
            do_prompt(d, 'path', 'Root path for your project', '.', is_path)
        else:
            d['path'] = do_prompt('Root path for your project', '.', 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('')
        if SPHINX_LT_17:
            do_prompt(d, 'path',
                      'Please enter a new root path (or just Enter to exit)',
                      '', is_path)
        else:
            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.'))
        if SPHINX_LT_17:
            do_prompt(d, 'project', 'Project name')
        else:
            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.'))
        if SPHINX_LT_17:
            do_prompt(d, 'author', 'Author name(s)')
        else:
            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('Error: the master file %s has already been found in the '
                  'selected root path.' % (d['master'] + d['suffix']))))
        print('ablog-start will not overwrite the existing file.')
        print('')
        if SPHINX_LT_17:
            do_prompt(
                d, 'master',
                w('Please enter a new file name, or rename the '
                  'existing file and press Enter'), d['master'])
        else:
            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.'))
        if SPHINX_LT_17:
            do_prompt(d, 'blog_baseurl', 'Base URL for your project', None,
                      lambda x: True)
        else:
            d['blog_baseurl'] = do_prompt('Base URL for your project', None,
                                          lambda x: True)

    print('')
Пример #14
0
def ask_user(d):
    """Wrap sphinx_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'),
        'ext_autodoc': False,
        'ext_doctest': True,
        'ext_intersphinx': True,
        'ext_todo': True,
        'ext_coverage': True,
        'ext_pngmath': True,
        'ext_mathjax': False,
        'ext_ifconfig': True,
        'ext_viewcode': False,
    })

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

    # slide_theme
    msg = """
Hieroglyph includes two themes:

* """ + bold("slides") + """
  The default theme, with different styling for first, second, and third
  level headings.

* """ + bold("single-level") + """
  All slides are styled the same, with the heading at the top.

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

    # XXX make a themes dict that has the keys/descriptions
    sphinx_quickstart.do_prompt(
        d,
        'slide_theme',
        'Slide Theme',
        'single-level',
        sphinx_quickstart.choice(
            'slides',
            'single-level',
        ),
    )

    # Ask original questions
    print("")
    sphinx_ask_user(d)
Пример #15
0
def get_input(fields, argv):
    print bold('Welcome to the sffms quickstart utility!')
    print '''
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).'''
    
    fields['path'] = get_path_from_cmdline(argv)
    if fields['path'] is None:
        print '''
Enter the directory in which to create your manuscript. The default
is this directory.'''
        do_prompt(fields, 'path', 'Path to your manuscript', '.', is_path)
    get_clear_path(fields)
        
    print '''
You can use this script to set up a novel or a short story.
For novels, sffms-quickstart creates a master story file and 
three chapter files, while for short stories, sffms-quickstart 
generates a single master story file. Short stories are also 
typeset a little differently from novels.'''
    do_prompt(fields, 'novel', 'Are you creating a novel? (y/N)', 'n', boolean)

    print ''
    do_prompt(fields, 'title', 'Enter your manuscript\'s title')
    fields['reST_title'] = generate_reST_title(fields['title'])
    # We sanitize the title after creating the 'reST_title' because we 
    # don't actually want to escape those characters in reST -- just in Python.
    fields['title'] = py_sanitize(fields['title'])
    
    print '''
Your title appears in a running header at the top of the page.
If you have a long title, consider supplying a shorter version
for inclusion in the running header. For example, for the story
'The Adventures of Sherlock Holmes: A Scandal in Bohemia,' the
short version could be 'A Scandal in Bohemia.' '''
    do_prompt(fields, 'runningtitle', 'Enter your manuscript\'s short title (optional)', validator=optional)
    
    print ''
    do_prompt(fields, 'author', 'Enter your full name', validator=required_string)
    
    print '''
Your full name (or surname, if specified) appears in the 
running header. Consider supplying your surname here.'''
    do_prompt(fields, 'surname', 'Enter your surname (optional)', validator=optional)
    
    print '''
You may enter a free-form multi-line address, including a postal 
address, telephone number, email address, or whatever contact info 
you wish to include. The address is displayed on the title page. 
When you are done entering the address, enter an empty (blank) line.'''
    prompt_address(fields)

    print '''
Your story source is contained in a master file. This file
either contains the entire story, or a table of contents
that points to separate chapter files.'''
    do_prompt(fields, 'master_doc', 'Name of your master source file (without suffix)', 'manuscript', validator=py_sanitize)
            
    fields['now'] = time.asctime()
    fields['copyright'] = time.strftime('%Y') + ', ' + fields['author']