Пример #1
0
def graceful_exit(sig, frame):
    ''' exit gracefully on SIGINT and SIGTERM'''
    if metadata:
        webquiz_util.webquiz_error(
            False, 'program terminated (signal {}\n  {})'.format(sig, frame))
    else:
        webquiz_util.webquiz_error(
            False, 'program terminated (signal {})'.format(sig))
Пример #2
0
def preprocess_with_pst2pdf(options, quiz_file):
    r'''
    Preprocess the latex file using pst2pdf. As we are preprocessing the file it
    is not enough to have latex pass us a flag that tells us to use pst2pdf.
    Instead, we have to extract the class file option from the tex file

    INPUT: quiz_file should be the name of the quiz file, WITHOUT the .tex extension
    '''
    options.talk('Preprocessing {} with pst2pdsf'.format(quiz_file))
    try:
        # pst2pdf converts pspicture environments to svg images and makes a
        # new latex file quiz_file+'-pdf' that includes these
        cmd = 'pst2pdf --svg --imgdir={q_file} {q_file}.tex'.format(q_file=quiz_file)
        options.run(cmd)
    except OSError as err:
        if err.errno == errno.ENOENT:
            webquiz_util.webquiz_error(options.debugging, 'pst2pdf not found. You need to install pst2pdf to use the pst2pdf option', err)
        else:
            webquiz_util.webquiz_error(options.debugging, 'error running pst2pdf on {}'.format(quiz_file), err)

    # match \includegraphics commands
    fix_svg = re.compile(r'(\\includegraphics\[scale=1\])\{('+quiz_file+r'-fig-[0-9]*)\}')
    # the svg images are in the quiz_file subdirectory but latex can't
    # find them so we update the tex file to look in the right place
    try:
        with codecs.open(quiz_file + '-pdf.tex', 'r', encoding='utf8') as pst_file:
            with codecs.open(quiz_file + '-pdf-fixed.tex', 'w', encoding='utf8') as pst_fixed:
                for line in pst_file:
                    pst_fixed.write(fix_svg.sub(r'\1{%s/\2.svg}' % quiz_file, line))
    except OSError as err:
        webquiz_util.webquiz_error(options.debugging,
            'there was an problem running pst2pdf for {}'.format(quiz_file),
            err
        )
Пример #3
0
 def webquiz_error(self, msg, err=None):
     r'''
         Customised error messages for the Module
     '''
     webquiz_util.webquiz_error(self.debugging, 'settings: ' + msg, err)
Пример #4
0
            if len(options.quiz_file) > 1 and options.quiet < 3:
                print('Making web page for {}'.format(quiz_file))

            quiz_name, ext = os.path.splitext(
                quiz_file)  # extract filename and extension
            # quiz_file is assumed to be a tex file if no extension is given
            if ext == '':
                ext = '.tex'
                quiz_file += ext

            # windows likes adding a prefix of '.\\'to filename and this causes havoc with latex
            if os.path.dirname(quiz_file) == '.':
                quiz_file = os.path.basename(quiz_file)

            if ext not in ['.tex', '.xml']:
                webquiz_util.webquiz_error(
                    True, 'unrecognised file extension {}'.format(ext))

            if not os.path.isfile(quiz_file):
                webquiz_util.webquiz + error(
                    True,
                    'WebQuiz error: cannot read file {}'.format(quiz_file))

            # the quiz name and the quiz_file will be different if pst2pdf is used
            quiz_name = quiz_file
            if options.quiet < 2:
                print('WebQuiz generating web page for {}'.format(quiz_file))

            options.pst2pdf = False
            if ext == ".tex":
                # If the pst2pdf option is used then we need to preprocess
                # the latex file BEFORE passing it to MakeWebQuiz. Set
Пример #5
0
 def webquiz_error(self, msg, err=None):
     r'''
         Customised error message for the xml module
     '''
     webquiz_util.webquiz_error(self.defaults.debugging, 'xml: ' + msg, err)
Пример #6
0
 def webquiz_error(self, msg, err=None):
     r'''
         Customised eror message for the makequiz module
     '''
     webquiz_util.webquiz_error(self.settings.debugging, 'makequiz: ' + msg,
                                err)