Beispiel #1
0
def save_file(text, parameters, file_name, is_4a5=False):
    framed_text = varexercise.frame(
        text,
        **parameters
    )
    output_tex_files.append(file_name, is_4a5)
    if options.verbose > 0:
        message(_('I\'ve opened the file "%s".\n') % file_name)
    with open(file_name, 'w') as f:
        f.writelines(framed_text)
Beispiel #2
0
def main():
    """It is the main program."""
    if '-help' in sys.argv:
        print("Use --help, please.")
        return
    get_options()

    if options.help:
        if lang == 'hu':
            print(hu_help)
        else:
            print(__doc__)
        return

    message(_('''Have a good work. www.arek.uni-obuda.hu/harp/ec'''))

    make_testpapers()
Beispiel #3
0
def translate(file):
    """It makes the given translations.
    Returns with the names of the generated files.
    """

    change_format_4a5 = _('I changed the format '
                          'to %s because of the pagestyles 4a5!')
    new_files = []
    filename = file.name
    file0 = os.path.splitext(filename)[0]
    if page == '4a5':
        if make.format == 'pdflatex':
            make.format = "pdf"
            message(change_format_4a5 % "pdf")
        if make.format == 'dvi':
            make.format = "ps"
            message(change_format_4a5 % "ps")
    if make.format in ['dvi', 'ps', 'pdf']:
        os.system('latex %s' % filename)
        new_files.append("%s.dvi" % file0)
    if make.format in ['ps', 'pdf']:
        os.system('dvips %s.dvi -o' % file0)
        new_files.append("%s.ps" % file0)
    if make.format in ['pdflatex']:
        os.system('pdflatex %s' % filename)
        new_files.append("%s.pdf" % file0)
    if page == '4a5' and file.is_4a5:
        os.system('./4a5  %s.ps' % file0)
        new_files.append("%s_4a5.ps" % file0)
        os.system('rm  %s.ps' % file0)
        new_files.remove("%s.ps" % file0)
    if make.format == 'pdf':
        if page == '4a5' and file.is_4a5:
            os.system('ps2pdf %s_4a5.ps' % file0)
            new_files.append("%s_4a5.pdf" % file0)
        else:
            os.system('ps2pdf %s.ps' % file0)
            new_files.append("%s.pdf" % file0)
    return new_files
Beispiel #4
0
def make_testpapers(solution_file=True):

    books = BookShelf(files.input)

    codes = get_ordered_codes(exercise_numbers)
    number_of_variations = variations.num
    assert isinstance(number_of_variations, int) and number_of_variations >= 0

    global exercise_numbers
    try:
        variation = varexercise.Variations(
            exercise_numbers,
            files.input,
            number_of_variations
        )
    except CodeNotFoundError:
        message(_("Not all the exercise codes exists on the books "
                  "that was listed in the test paper."))
        return
    base_name, extension = os.path.splitext(files.output)

    pagesize, solution_pagesize, list_pagesize = get_pagesize(page)

    shared_parameters = dict(
        preamble_file="magyarpreambulum",
        rhead=header_footer.inst,
        lfoot=header_footer.course,
        rfoot=header_footer.date,
        definitions=books.definitions(codes)
    )

    solution_text = variation.one()
    text = solution_text if number_of_variations == 0 else variation.all()

    parameters = shared_parameters.copy()
    parameters.update(
        doc_type='testpaper',
        pagesize=pagesize,
        fontsize=fontsize,
        lhead=header_footer.title,
        cfoot=None,
    )
    file_name = "%s.tex" % base_name
    save_file(text, parameters, file_name, page == '4a5')

    if solution_file:

        parameters = shared_parameters.copy()
        parameters.update(
            doc_type='plain',
            pagesize=solution_pagesize,
            fontsize=fontsize,
            lhead=header_footer.title + " Megoldás",
            cfoot='\\thepage',
        )
        file_name = "%s_megold.tex" % base_name
        save_file(solution_text, parameters, file_name)

    if not number_of_variations == 0:
        text = variation.list()
        if not text:
            raise ValueError('no variations in TeX source.')
        else:
            parameters = shared_parameters.copy()
            parameters.update(
                doc_type='plain',
                fontsize=10,
                pagesize=list_pagesize,
                lhead=header_footer.title,
                cfoot='\\thepage',
            )
            file_name = "%s_list.tex" % base_name
            save_file(text, parameters, file_name)

    wrote_files_message = _('I wrote the files:\n %s\n')
    message(wrote_files_message % output_tex_files)

    other_output_files = OutputFiles()  # Non-tex files.
    if make.format == '0':
        make.format = 0
    if output_tex_files.list and make.format:
        message(_('I will translate the files. It will take a while.\n'))
        for file in output_tex_files.list:
            new_files = translate(file)
            other_output_files.extend(new_files)

    print('\n')
    message(wrote_files_message %
                ("%s%s" % (output_tex_files, other_output_files)))
Beispiel #5
0
def test_exercise_numbers():
    """ It writes the intervals and the not uniq numbers. """

    int_codelist = [x for x in books.codelist if isinstance(x, int)]

    message(_('1. The next files are in this group:'))
    for file in files.input:
        print("\t%s" % file)

    message(_('\n2. Intervals of exercise codes'
                  '(pl. 12..14 means: 12, 13, 14):'))
    integerlist.print_intervals(int_codelist)

    message(_('\n3. Not uniq exercise codes I found:'))
    num = integerlist.print_not_uniq(
        int_codelist,
        _('%d times is the code %d!'))
    if num == 0:
        message(_('None.'))

    # If there are bad arguments (which is not integer)
    # writes them.
    message(_('\n4. Bad arguments:'))
    bad_list = books.exercises_with_bad_arguments()
    if len(bad_list) > 0:
        for file_name, row, code in bad_list:
            raise BadCodeException(file_name, row, code)
    else:
        message(_('None.'))
    print()