Esempio n. 1
0
def format_output(rstfile, htmlfile, newfile, mld, rstdata, settings, state):
    """build page html out of various parameters and a template file
    """
    if state.newfile:
        all_source, all_html = [], []
    else:
        all_source = rhfn.list_files(state.sitename, state.current, rstfile,
                                     'src')
        all_html = rhfn.list_files(state.sitename, state.current, htmlfile,
                                   'dest')
    with TEMPLATE.open() as f_in:
        # eigengebakken language support
        output = []
        for line in f_in:
            while '_(' in line:
                start, rest = line.split('_(', 1)
                keyword, end = rest.split(')', 1)
                line = rhfn.get_text(keyword, state.get_lang()).join(
                    (start, end))
            output.append(line)
        output = ''.join(output)
    conflist = rhfn.list_confs(settings)
    format_stuff = ''
    if state.conf.get('highlight', False):
        format_stuff = ''.join(codemirror_stuff)
        if state.loaded:
            format_stuff += ''.join(
                scriptspec.format(x) for x in scriptdict[state.loaded])
    return output.format(all_source, all_html, newfile, mld, rstdata,
                         state.conf['wid'], state.conf['hig'], conflist,
                         state.loaded, format_stuff)
Esempio n. 2
0
def test_saveall(state):
    """testing saveall"""
    print(test_saveall.__doc__ + '...', end=' ')
    state.oldtext = 'hallo vriendjes'
    state.loaded = rhfn.HTML
    data = state.saveall('jansen.rst', '', 'hallo vriendjes')
    assert_equal(data[0], "Not executed: text area doesn't contain restructured text")
    state.loaded = rhfn.RST
    # first-time only: check if deletions have been propagated
    for name in ('tobedeleted', 'python'):
        assert name in rhfn.list_files(state.sitename, state.current, ext='src', deleted=True)
        assert name not in rhfn.list_files(state.sitename, state.current, ext='dest', deleted=True)
    data = state.saveall('jansen.rst', '', 'hallo vriendjes')
    assert_equal(data, ('Rst converted to html and saved as jansen.html',
                        'jansen.rst', 'jansen.html', ''))
    for name in ('tobedeleted', 'python'):
        assert name not in rhfn.list_files(state.sitename, state.current, ext='src', deleted=True)
        assert name in rhfn.list_files(state.sitename, state.current, ext='dest', deleted=True)
    data = state.saveall('jansen.rst', 'pietersen.rst', 'hallo vriendjes')
    assert_equal(data, ('Rst converted to html and saved as pietersen.html',
                        'pietersen.rst', 'pietersen.html', ''))
    state.oldtext = 'something else'
    data = state.saveall('jansen.rst', '', 'hallo vriendjes')
    assert_equal(data, ('Rst converted to html and saved as jansen.html',
                        'jansen.rst', 'jansen.html', ''))
    data = state.saveall('jansen.rst', 'pietersen.rst', 'hallo vriendjes')
    assert_equal(data, ('Source file already exists', 'pietersen.rst',
                        'pietersen.html', ''))
    print('ok')
    return state
Esempio n. 3
0
def format_output(rstfile, htmlfile, newfile, mld, rstdata, settings, state):
    """build page html out of various parameters and a template file
    """
    if state.newfile:
        all_source, all_html = [], []
    else:
        all_source = rhfn.list_files(state.sitename, state.current, rstfile, 'src')
        all_html = rhfn.list_files(state.sitename, state.current, htmlfile, 'dest')
    lines = load_template("rst2html.html").split('\n')
    output = apply_lang(lines, state)
    conflist = rhfn.list_confs(settings)
    format_stuff = ''
    if state.conf.get('highlight', False):
        format_stuff = ''.join(codemirror_stuff)
        if state.loaded:
            format_stuff += ''.join(scriptspec.format(x) for x in scriptdict[state.loaded])
    return output.format(all_source, all_html, newfile, mld, rstdata, state.conf['wid'],
                         state.conf['hig'], conflist, state.loaded, format_stuff)
Esempio n. 4
0
def test_copytoroot(state):
    """testing copytoroot"""
    print(test_copytoroot.__doc__ + '...', end=' ')
    state.loaded = rhfn.RST
    data = state.copytoroot('jansen.html', converted_txt)
    assert_equal(data, 'Please load HTML first')
    state.loaded = rhfn.HTML
    # also check if deletions have been propagated
    for name in ('tobedeleted', 'python'):
        assert name in rhfn.list_files(state.sitename, state.current, ext='dest', deleted=True)
    data = state.copytoroot('jansen.html', converted_txt)
    assert_equal(data, 'Copied to siteroot/jansen.html')
    for name in ('tobedeleted', 'python'):
        assert name not in rhfn.list_files(state.sitename, state.current, ext='dest', deleted=True)
        assert name not in rhfn.list_files(state.sitename, state.current, ext='src')
        assert name not in rhfn.list_files(state.sitename, state.current, ext='dest')
        # also check existence in mirror directory
        assert name not in rhfn.list_files(state.sitename, state.current, ext='mirror')
    print('ok')
    return state
Esempio n. 5
0
def test_rename_delete_docs(sitename, current):
    """renaming and deleting documents"""
    print(test_rename_delete_docs.__doc__ + '...', end=' ')
    # create new source document and add contents
    naam_o, naam_r = 'to_rename', 'renamed'
    data_r = 'now creating {}'.format(naam_o)
    data_rh = '<p>{}</p>'.format(data_r)
    msg = rhfn.save_src_data(sitename, '', naam_o, data_r, True)
    assert_equal(msg, '')
    assert naam_o in rhfn.list_files(sitename, '', ext='src')
    # rename by marking old name as deleted and saving contents under new name
    msg = rhfn.save_src_data(sitename, '', naam_r, data_r, True)
    assert_equal(msg, '')
    msg = rhfn.mark_deleted(sitename, '', naam_o)
    assert_equal(msg, '')
    assert naam_o not in rhfn.list_files(sitename, '', ext='src')
    assert naam_o in rhfn.list_files(sitename, '', ext='src', deleted=True)
    assert naam_r in rhfn.list_files(sitename, '', ext='src')
    # create and delete document
    naam_d = 'to_delete'
    data_d = 'now creating {}'.format(naam_d)
    data_dh = '<p>{}</p>'.format(data_d)
    msg = rhfn.save_src_data(sitename, '', naam_d, data_d, True)
    assert_equal(msg, '')
    assert naam_d in rhfn.list_files(sitename, '', ext='src')
    msg = rhfn.mark_deleted(sitename, '', naam_d)
    assert_equal(msg, '')
    assert naam_d not in rhfn.list_files(sitename, '', ext='src')
    assert naam_d in rhfn.list_files(sitename, '', ext='src', deleted=True)
    # move rename/delete to target and check
    assert naam_o not in rhfn.list_files(sitename, '', ext='dest')
    assert naam_r not in rhfn.list_files(sitename, '', ext='dest')
    assert naam_d not in rhfn.list_files(sitename, '', ext='dest')
    msg = rhfn.save_html_data(sitename, '', naam_r, data_rh)
    assert_equal(msg, '')
    assert naam_o not in rhfn.list_files(sitename, '', ext='dest')
    assert naam_o in rhfn.list_files(sitename, '', ext='dest', deleted=True)
    assert naam_o not in rhfn.list_files(sitename, '', ext='src', deleted=True)
    assert naam_r in rhfn.list_files(sitename, '', ext='dest')
    assert naam_d not in rhfn.list_files(sitename, '', ext='dest')
    assert naam_d in rhfn.list_files(sitename, '', ext='dest', deleted=True)
    assert naam_d not in rhfn.list_files(sitename, '', ext='src', deleted=True)
    # move rename/delete to mirror and check
    assert naam_o not in rhfn.list_files(sitename, '', ext='mirror')
    assert naam_r not in rhfn.list_files(sitename, '', ext='mirror')
    assert naam_d not in rhfn.list_files(sitename, '', ext='mirror')
    msg = rhfn.save_to_mirror(sitename, '', naam_r, confdata_extra)
    assert_equal(msg, '')
    assert naam_o not in rhfn.list_files(sitename, '', ext='mirror')
    assert naam_r in rhfn.list_files(sitename, '', ext='mirror')
    assert naam_r not in rhfn.list_files(sitename, '', ext='dest', deleted=True)
    assert naam_d not in rhfn.list_files(sitename, '', ext='mirror')
    assert naam_d not in rhfn.list_files(sitename, '', ext='dest', deleted=True)
    print('ok')
Esempio n. 6
0
def test_list_files(sitename):
    """listing dirs and files"""
    print(test_list_files.__doc__ + '...', end=' ')
    naam = 'jansen'
    msg = rhfn.save_src_data(sitename, '', naam,
                             'now creating {}'.format(naam), True)
    assert_equal(msg, '')
    naam = 'hendriksen'
    msg = rhfn.save_src_data(sitename, 'guichelheil', naam,
                             'now creating {}'.format(naam), True)
    assert_equal(msg, '')

    naam = 'jansen'
    msg = rhfn.save_html_data(sitename, '', naam,
                              '<p>now creating {}</p>'.format(naam))
    assert_equal(msg, '')
    naam = 'hendriksen'
    msg = rhfn.save_html_data(sitename, 'guichelheil', naam,
                              '<p>now creating {}</p>'.format(naam))
    assert_equal(msg, '')
    expected = ['guichelheil/']
    assert_equal(rhfn.list_subdirs(sitename), expected)
    assert_equal(rhfn.list_subdirs(sitename, 'src'), expected)
    assert_equal(rhfn.list_subdirs(sitename, 'dest'), expected)
    assert_equal(rhfn.list_subdirs(sitename, 'other'), expected)

    # nonexistent site
    data = rhfn.list_subdirs('oink')
    assert_equal(data, [])
    # nonexistent subdir
    data = rhfn.list_files(sitename, 'blub', '', '', 'en')
    assert_equal(data, '<option>..</option>')  # 'Directory `blub` not found'

    expected_0 = '<option>guichelheil/</option>'
    expected_1 = expected_0 + '<option>jansen.rst</option>'
    expected_2 = expected_0 + '<option selected="selected">jansen.rst</option>'
    expected_3 = expected_0 + '<option>jansen.html</option>'
    expected_4 = expected_0 + '<option selected="selected">jansen.html</option>'
    assert_equal(rhfn.list_files(sitename), expected_1)
    assert_equal(rhfn.list_files(sitename, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, ext='src', deleted=True), [])
    assert_equal(rhfn.list_files(sitename, ext='dest'), expected_3)
    assert_equal(rhfn.list_files(sitename, ext='dest', deleted=True), [])
    naam = ''
    assert_equal(rhfn.list_files(sitename, naam=naam), expected_1)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='dest'), expected_3)
    naam = 'nonexist'
    assert_equal(rhfn.list_files(sitename, naam=naam), expected_1)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='dest'), expected_3)
    naam = 'jansen.rst'
    assert_equal(rhfn.list_files(sitename, naam=naam), expected_2)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='src'), expected_2)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='dest'), expected_3)
    naam = 'jansen.html'
    assert_equal(rhfn.list_files(sitename, naam=naam), expected_1)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, naam=naam, ext='dest'), expected_4)
    current = ''
    assert_equal(rhfn.list_files(sitename, current), expected_1)
    assert_equal(rhfn.list_files(sitename, current, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, current, ext='dest'), expected_3)
    current = 'guichelheil'
    expected_0 = '<option>..</option>'
    expected_1 = expected_0 + '<option>hendriksen.rst</option>'
    expected_2 = expected_0 + '<option selected="selected">hendriksen.rst</option>'
    expected_3 = expected_0 + '<option>hendriksen.html</option>'
    expected_4 = expected_0 + '<option selected="selected">hendriksen.html</option>'
    assert_equal(rhfn.list_files(sitename, current), expected_1)
    assert_equal(rhfn.list_files(sitename, current, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, current, ext='src', deleted=True), [])
    assert_equal(rhfn.list_files(sitename, current, ext='dest'), expected_3)
    assert_equal(rhfn.list_files(sitename, current, ext='dest', deleted=True), [])
    naam = ''
    assert_equal(rhfn.list_files(sitename, current, naam), expected_1)
    assert_equal(rhfn.list_files(sitename, current, naam, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, current, naam, ext='dest'), expected_3)
    naam = 'jansen'
    assert_equal(rhfn.list_files(sitename, current, naam), expected_1)
    assert_equal(rhfn.list_files(sitename, current, naam, ext='src'), expected_1)
    assert_equal(rhfn.list_files(sitename, current, naam, ext='dest'), expected_3)
    naam = 'hendriksen.rst'
    assert_equal(rhfn.list_files(sitename, current, naam), expected_2)
    assert_equal(rhfn.list_files(sitename, current, naam, 'src'), expected_2)
    assert_equal(rhfn.list_files(sitename, current, naam, 'dest'), expected_3)
    naam = 'hendriksen.html'
    assert_equal(rhfn.list_files(sitename, current, naam), expected_1)
    assert_equal(rhfn.list_files(sitename, current, naam, 'src'), expected_1)
    assert_equal(rhfn.list_files(sitename, current, naam, 'dest'), expected_4)

    msg = rhfn.make_new_dir(sitename, 'moerasspiraea')
    assert_equal(msg, '')
    msg = rhfn.make_new_dir(sitename, 'moerasspiraea')
    assert_equal(msg, 'dir_name_taken')
    print('ok')
    return current