summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-04-01 21:07:31 +0000
committerKarl Berry <karl@freefriends.org>2019-04-01 21:07:31 +0000
commitca790e6da556783aa072a2b1d21eee01b100ec32 (patch)
tree226da3ee026929e682fb4f71fa403a42487ae758 /Master/texmf-dist/scripts
parentb9279e1b4ddf93b0d93a9f62ba3335fc2386cebb (diff)
webquiz (1apr19)
git-svn-id: svn://tug.org/texlive/trunk@50694 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts')
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/CHANGES.rst4
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/webquiz177
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/webquiz.bat26
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/webquiz.py177
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/webquiz_layout.py4
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/webquiz_makequiz.py8
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/webquiz_templates.py43
-rwxr-xr-xMaster/texmf-dist/scripts/webquiz/webquiz_util.py37
8 files changed, 302 insertions, 174 deletions
diff --git a/Master/texmf-dist/scripts/webquiz/CHANGES.rst b/Master/texmf-dist/scripts/webquiz/CHANGES.rst
index e29b7e5cfb2..4de4c5641c5 100755
--- a/Master/texmf-dist/scripts/webquiz/CHANGES.rst
+++ b/Master/texmf-dist/scripts/webquiz/CHANGES.rst
@@ -2,6 +2,10 @@
WebQuiz Changes
===============
+Version 5.2:
+------------
+ - compatibility with both MikTeX and TeXLive under windows
+
Version 5.1:
------------
- code reorganised n zip file for TeXLive inclusion
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz b/Master/texmf-dist/scripts/webquiz/webquiz
index 283f21d1321..de1e052fb7c 100755
--- a/Master/texmf-dist/scripts/webquiz/webquiz
+++ b/Master/texmf-dist/scripts/webquiz/webquiz
@@ -42,7 +42,7 @@ except subprocess.CalledProcessError:
try:
metadata = webquiz_util.MetaData(ini_file, debugging=False)
except (FileNotFoundError, subprocess.CalledProcessError):
- print('webquiz installation error: unable to find webquiz.ini -> {}'.format(ini_file))
+ print(webquiz_templates.missing_webquiz_ini.format(ini_file))
sys.exit(1)
# ---------------------------------------------------------------------------------------
@@ -71,7 +71,8 @@ def preprocess_with_pst2pdf(options, quiz_file):
# 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)
+ # pst2pdf is missing a #!-header so we need shell=True
+ options.run(cmd, shell=True)
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)
@@ -226,12 +227,16 @@ class WebQuizSettings:
# define user and system rc file and load the ones that exist
- self.system_rcfile = os.path.join(webquiz_util.kpsewhich('-var TEXMFLOCAL'),
- 'tex',
- 'latex',
- 'webquiz',
- 'webquizrc'
- )
+ TEXMFLOCAL=''
+ try:
+ TEXMFLOCAL = webquiz_util.kpsewhich('-var-value TEXMFLOCAL')
+ except subprocess.CalledProcessError:
+ pass
+
+ if TEXMFLOCAL == '':
+ TEXMFLOCAL = webquiz_util.kpsewhich('-var-value TEXMFMAIN')
+
+ self.system_rcfile = os.path.join(TEXMFLOCAL, 'tex', 'latex', 'webquiz', 'webquizrc')
self.read_webquizrc(self.system_rcfile)
# the user rc file defaults to:
@@ -378,9 +383,8 @@ class WebQuizSettings:
Print the non-default settings for webquiz from the webquizrc
'''
if not hasattr(self, 'rcfile'):
- print(
- 'Please initialise WebQuiz using the command: webquiz --initialise\n'
- )
+ print(webquiz_templates.initialise_settings)
+ sys.exit(1)
if setting not in ['all', 'verbose', 'help']:
setting = setting.replace('-', '_')
@@ -440,7 +444,7 @@ class WebQuizSettings:
default_root = '/Library/WebServer/Documents/WebQuiz'
platform = 'Mac OSX'
elif sys.platform.startswith('win'):
- default_root = ' c:\inetpub\wwwroot\WebQuiz'
+ default_root = 'c:\inetpub\wwwroot\WebQuiz'
platform = 'Windows'
else:
default_root = '/var/www/html/WebQuiz'
@@ -496,7 +500,7 @@ class WebQuizSettings:
# if texdoc failed then try using TEXMFMAIN
if webquiz_doc=='':
try:
- webquiz_doc = os.path.join(webquiz_util.kpsewhich('-var TEXMFMAIN'), 'doc','latex', 'webquiz')
+ webquiz_doc = os.path.join(webquiz_util.kpsewhich('-var-value TEXMFMAIN'), 'doc','latex', 'webquiz')
except subprocess.CalledProcessError:
pass
@@ -648,7 +652,7 @@ class WebQuizSettings:
Undocumented feature - useful for debugging initialisation routine
'''
webquiz_top = os.path.abspath(webquiz_util.webquiz_file('..'))
- texmf = webquiz_util.kpsewhich('-var TEXMFMAIN')
+ texmf = webquiz_util.kpsewhich('-var-value TEXMFMAIN')
for (src, target) in [('scripts', 'scripts'),
('latex', 'tex/latex'),
('doc', 'doc/latex')]:
@@ -665,8 +669,17 @@ class WebQuizSettings:
try:
# add a link to webquiz.py
- texbin = os.path.dirname(webquiz_util.shell_command('which pdflatex').split()[-1])
- os.symlink(os.path.join(texmf,'scripts','webquiz','webquiz.py'), os.path.join(texbin, 'webquiz'))
+ texbin = os.path.dirname(shutil.which('pdflatex'))
+ if sys.platform.startswith('win'):
+ shutil.copyfile(
+ os.path.join(texmf,'scripts','webquiz','webquiz.bat'),
+ os.path.join(texbin, 'webquiz.bat')
+ )
+ else:
+ os.symlink(
+ os.path.join(texmf,'scripts','webquiz','webquiz.py'),
+ os.path.join(texbin, 'webquiz')
+ )
subprocess.call('mktexlsr', shell=True)
except (FileExistsError,FileNotFoundError):
@@ -677,8 +690,7 @@ class WebQuizSettings:
sys.exit(1)
except subprocess.CalledProcessError as err:
- print('There was a problem running mktexlsr')
- sys.exit(1)
+ self.webquiz_error('There was a problem running mktexlsr', err)
def tex_uninstall(self):
r'''
@@ -692,7 +704,7 @@ class WebQuizSettings:
Undocumented feature - useful for debugging initialisation routine
'''
webquiz_top = os.path.abspath(webquiz_util.webquiz_file('..'))
- texmf = webquiz_util.kpsewhich('-var TEXMFMAIN')
+ texmf = webquiz_util.kpsewhich('-var-value TEXMFMAIN')
for target in ['scripts', 'tex/latex', 'doc/latex']:
try:
shutil.rmtree(os.path.join(texmf, target, 'webquiz'))
@@ -706,8 +718,11 @@ class WebQuizSettings:
try:
# remove link from texbin to webquiz.py
- texbin = os.path.dirname(webquiz_util.shell_command('which pdflatex').split()[-1])
- os.remove(os.path.join(texbin, 'webquiz'))
+ texbin = os.path.dirname(shutil.which('pdflatex'))
+ if sys.platform.startswith('win'):
+ os.remove(os.path.join(texbin, 'webquiz.bat'))
+ else:
+ os.remove(os.path.join(texbin, 'webquiz'))
except (FileExistsError,FileNotFoundError):
pass
@@ -729,12 +744,16 @@ class WebQuizSettings:
sys.exit(1)
# remove link to webquiz.py
- texbin = os.path.dirname(webquiz_util.shell_command('which pdflatex').split()[-1])
- webquiz = os.path.join(texbin,'webquiz')
+ texbin = os.path.dirname(shutil.which('pdflatex'))
try:
- target = os.readlink(webquiz)
- if target==os.path.join(texmf,'scripts','webquiz','webquiz.py'):
+ if sys.platform.startswith('win'):
+ webquiz = os.path.join(texbin, 'webquiz.bat')
os.remove(webquiz)
+ else:
+ webquiz = os.path.join(texbin,'webquiz')
+ target = os.readlink(webquiz)
+ if target==os.path.join(texmf,'scripts','webquiz','webquiz.py'):
+ os.remove(webquiz)
except (FileExistsError,FileNotFoundError):
pass
@@ -852,6 +871,7 @@ if __name__ == '__main__':
settings_parser.add_argument(
'-i',
'--initialise',
+ '--initialize',
action='store_true',
default=False,
help='Install web components of webquiz')
@@ -1001,41 +1021,50 @@ if __name__ == '__main__':
# - we need to use shell=True because otherwise pst2pdf gives an error
# options.talk() is a shorthand for letting the user know what is happening
if options.quiet == 0:
- options.run = lambda cmd: subprocess.call(cmd, shell=True)
+ options.run = webquiz_util.run
options.talk = lambda msg: print(msg)
elif options.quiet == 1:
- options.run = lambda cmd: subprocess.call(cmd, shell=True, stdout=open(os.devnull, 'wb'))
+ options.run = webquiz_util.quiet_run
options.talk = lambda msg: print(msg)
else:
- options.run = lambda cmd: subprocess.call(cmd, shell=True, stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'))
+ options.run = webquiz_util.silent_run
options.talk = lambda msg: None
# run through the list of quizzes and make them
for quiz_file in options.quiz_file:
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 not '.' in quiz_file:
- quiz_file += '.tex'
+ 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 not os.path.isfile(quiz_file):
- print('WebQuiz error: cannot read file {}'.format(quiz_file))
+ if ext not in ['.tex', '.xml']:
+ webquiz_util.webquiz_error(True, 'unrecognised file extension {}'.format(ext))
- else:
+ 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 if pst2pdf is used
- quiz_name = quiz_file
- if options.quiet < 2:
- print('WebQuiz generating web page for {}'.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))
- # If the pst2podf option is used then we need to preprocess
+ 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
# options.pst2pdf = True if pst2pdf is given as an option to
# the webquiz documentclass
with codecs.open(quiz_file, 'r', encoding='utf8') as q_file:
doc = q_file.read()
- options.pst2pdf = False
try:
brac = doc.index(r'\documentclass[') + 15 # start of class options
if 'pst2pdf' in [
@@ -1049,46 +1078,46 @@ if __name__ == '__main__':
except ValueError:
pass
- # the file exists and is readable so make the quiz
- webquiz_makequiz.MakeWebQuiz(quiz_name, quiz_file, options, settings, metadata)
-
- quiz_name = quiz_name[:quiz_name.index('.')] # remove the extension
-
- # move the css file into the directory for the quiz
- css_file = os.path.join(quiz_name, quiz_name + '.css')
- if os.path.isfile(quiz_name + '.css'):
- if os.path.isfile(css_file):
- os.remove(css_file)
- shutil.move(quiz_name + '.css', css_file)
-
- # now clean up unless debugging
- if not options.debugging:
- for ext in ['4ct', '4tc', 'dvi', 'idv', 'lg', 'log',
- 'ps', 'pdf', 'tmp', 'xml', 'xref'
+ # the file exists and is readable so make the quiz
+ webquiz_makequiz.MakeWebQuiz(quiz_name, quiz_file, options, settings, metadata)
+
+ quiz_name, ext = os.path.splitext(quiz_name) # extract filename and extension
+
+ # move the css file into the directory for the quiz
+ css_file = os.path.join(quiz_name, quiz_name + '.css')
+ if os.path.isfile(quiz_name + '.css'):
+ if os.path.isfile(css_file):
+ os.remove(css_file)
+ shutil.move(quiz_name + '.css', css_file)
+
+ # now clean up unless debugging
+ if not options.debugging:
+ for ext in ['4ct', '4tc', 'dvi', 'idv', 'lg', 'log',
+ 'ps', 'pdf', 'tmp', 'xml', 'xref'
+ ]:
+ if os.path.isfile(quiz_name + '.' + ext):
+ os.remove(quiz_name + '.' + ext)
+
+ # files created when using pst2pdf
+ if options.pst2pdf:
+ for file in glob.glob(quiz_name + '-pdf.*'):
+ os.remove(file)
+ for file in glob.glob(quiz_name + '-pdf-fixed.*'):
+ os.remove(file)
+ for extention in ['.preamble', '.plog', '-tmp.tex',
+ '-pst.tex', '-fig.tex'
]:
- if os.path.isfile(quiz_name + '.' + ext):
- os.remove(quiz_name + '.' + ext)
-
- # files created when using pst2pdf
- if options.pst2pdf:
- for file in glob.glob(quiz_name + '-pdf.*'):
- os.remove(file)
- for file in glob.glob(quiz_name + '-pdf-fixed.*'):
- os.remove(file)
- for extention in ['.preamble', '.plog', '-tmp.tex',
- '-pst.tex', '-fig.tex'
- ]:
- if os.path.isfile(quiz_name + extention):
- os.remove(quiz_name + extention)
- if os.path.isdir(os.path.join(quiz_name, quiz_name)):
- shutil.rmtree(os.path.join(quiz_name, quiz_name))
-
- if settings.initialise_warning != '':
+ if os.path.isfile(quiz_name + extention):
+ os.remove(quiz_name + extention)
+ if os.path.isdir(os.path.join(quiz_name, quiz_name)):
+ shutil.rmtree(os.path.join(quiz_name, quiz_name))
+
+ if settings.initialise_warning != '' and not settings.have_initialised:
print(webquiz_templates.text_initialise_warning)
except Exception as err:
- # there is a small chance that there is an error before we the
+ # there is a small chance that there is an error before the
# settings.debugging flag has been set
webquiz_util.webquiz_error(settings.debugging if 'settings' in globals() else True,
'unknown problem.\n\nIf you think this is a bug please report it by creating an issue at\n {}\n'
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz.bat b/Master/texmf-dist/scripts/webquiz/webquiz.bat
index c92a60d3a29..89c05730fa4 100755
--- a/Master/texmf-dist/scripts/webquiz/webquiz.bat
+++ b/Master/texmf-dist/scripts/webquiz/webquiz.bat
@@ -1,14 +1,30 @@
@echo off
+rem WebQuiz batch file to find and launch python executable
+
+rem Set TEXMF to root TeX directory and look for webquiz.py in scripts/webquiz
setlocal enableextensions
-rem assuming the main script is in the same directory
-if not exist "%~dpn0.py" (
- echo %~nx0: main script "%~dpn0.py" not found>&2
+for /F "tokens=*" %%i in ('kpsewhich -var-value TEXMFMAIN') do (SET TEXMF=%%i)
+
+rem First look for webquiz.py in the current directory
+set WebQuiz="webquiz.py"
+if not exist %WebQuiz% (
+ if exist "%TEXMF%/scripts/webquiz/webquiz.py" (
+ set WebQuiz="%TEXMF%/scripts/webquiz/webquiz.py"
+ )
+)
+rem
+rem exit with an error if webquiz.py has not been found
+if not exist %WebQuiz% (
+ echo WebQuiz executable not found. Please check that WebQuiz is properly installed>&2
exit /b 1
)
-rem check if interpreter is on the PATH
+
+rem check for the python interpreter in the PATH
for %%I in (python.exe) do set "PYTHONEXE=%%~$PATH:I"
if not defined PYTHONEXE (
echo %~nx0: Python interpreter not installed or not on the PATH>&2
exit /b 1
)
-"%PYTHONEXE%" "%~dpn0.py" %*
+
+rem launch webquiz
+"%PYTHONEXE%" %WebQuiz% %*
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz.py b/Master/texmf-dist/scripts/webquiz/webquiz.py
index 283f21d1321..de1e052fb7c 100755
--- a/Master/texmf-dist/scripts/webquiz/webquiz.py
+++ b/Master/texmf-dist/scripts/webquiz/webquiz.py
@@ -42,7 +42,7 @@ except subprocess.CalledProcessError:
try:
metadata = webquiz_util.MetaData(ini_file, debugging=False)
except (FileNotFoundError, subprocess.CalledProcessError):
- print('webquiz installation error: unable to find webquiz.ini -> {}'.format(ini_file))
+ print(webquiz_templates.missing_webquiz_ini.format(ini_file))
sys.exit(1)
# ---------------------------------------------------------------------------------------
@@ -71,7 +71,8 @@ def preprocess_with_pst2pdf(options, quiz_file):
# 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)
+ # pst2pdf is missing a #!-header so we need shell=True
+ options.run(cmd, shell=True)
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)
@@ -226,12 +227,16 @@ class WebQuizSettings:
# define user and system rc file and load the ones that exist
- self.system_rcfile = os.path.join(webquiz_util.kpsewhich('-var TEXMFLOCAL'),
- 'tex',
- 'latex',
- 'webquiz',
- 'webquizrc'
- )
+ TEXMFLOCAL=''
+ try:
+ TEXMFLOCAL = webquiz_util.kpsewhich('-var-value TEXMFLOCAL')
+ except subprocess.CalledProcessError:
+ pass
+
+ if TEXMFLOCAL == '':
+ TEXMFLOCAL = webquiz_util.kpsewhich('-var-value TEXMFMAIN')
+
+ self.system_rcfile = os.path.join(TEXMFLOCAL, 'tex', 'latex', 'webquiz', 'webquizrc')
self.read_webquizrc(self.system_rcfile)
# the user rc file defaults to:
@@ -378,9 +383,8 @@ class WebQuizSettings:
Print the non-default settings for webquiz from the webquizrc
'''
if not hasattr(self, 'rcfile'):
- print(
- 'Please initialise WebQuiz using the command: webquiz --initialise\n'
- )
+ print(webquiz_templates.initialise_settings)
+ sys.exit(1)
if setting not in ['all', 'verbose', 'help']:
setting = setting.replace('-', '_')
@@ -440,7 +444,7 @@ class WebQuizSettings:
default_root = '/Library/WebServer/Documents/WebQuiz'
platform = 'Mac OSX'
elif sys.platform.startswith('win'):
- default_root = ' c:\inetpub\wwwroot\WebQuiz'
+ default_root = 'c:\inetpub\wwwroot\WebQuiz'
platform = 'Windows'
else:
default_root = '/var/www/html/WebQuiz'
@@ -496,7 +500,7 @@ class WebQuizSettings:
# if texdoc failed then try using TEXMFMAIN
if webquiz_doc=='':
try:
- webquiz_doc = os.path.join(webquiz_util.kpsewhich('-var TEXMFMAIN'), 'doc','latex', 'webquiz')
+ webquiz_doc = os.path.join(webquiz_util.kpsewhich('-var-value TEXMFMAIN'), 'doc','latex', 'webquiz')
except subprocess.CalledProcessError:
pass
@@ -648,7 +652,7 @@ class WebQuizSettings:
Undocumented feature - useful for debugging initialisation routine
'''
webquiz_top = os.path.abspath(webquiz_util.webquiz_file('..'))
- texmf = webquiz_util.kpsewhich('-var TEXMFMAIN')
+ texmf = webquiz_util.kpsewhich('-var-value TEXMFMAIN')
for (src, target) in [('scripts', 'scripts'),
('latex', 'tex/latex'),
('doc', 'doc/latex')]:
@@ -665,8 +669,17 @@ class WebQuizSettings:
try:
# add a link to webquiz.py
- texbin = os.path.dirname(webquiz_util.shell_command('which pdflatex').split()[-1])
- os.symlink(os.path.join(texmf,'scripts','webquiz','webquiz.py'), os.path.join(texbin, 'webquiz'))
+ texbin = os.path.dirname(shutil.which('pdflatex'))
+ if sys.platform.startswith('win'):
+ shutil.copyfile(
+ os.path.join(texmf,'scripts','webquiz','webquiz.bat'),
+ os.path.join(texbin, 'webquiz.bat')
+ )
+ else:
+ os.symlink(
+ os.path.join(texmf,'scripts','webquiz','webquiz.py'),
+ os.path.join(texbin, 'webquiz')
+ )
subprocess.call('mktexlsr', shell=True)
except (FileExistsError,FileNotFoundError):
@@ -677,8 +690,7 @@ class WebQuizSettings:
sys.exit(1)
except subprocess.CalledProcessError as err:
- print('There was a problem running mktexlsr')
- sys.exit(1)
+ self.webquiz_error('There was a problem running mktexlsr', err)
def tex_uninstall(self):
r'''
@@ -692,7 +704,7 @@ class WebQuizSettings:
Undocumented feature - useful for debugging initialisation routine
'''
webquiz_top = os.path.abspath(webquiz_util.webquiz_file('..'))
- texmf = webquiz_util.kpsewhich('-var TEXMFMAIN')
+ texmf = webquiz_util.kpsewhich('-var-value TEXMFMAIN')
for target in ['scripts', 'tex/latex', 'doc/latex']:
try:
shutil.rmtree(os.path.join(texmf, target, 'webquiz'))
@@ -706,8 +718,11 @@ class WebQuizSettings:
try:
# remove link from texbin to webquiz.py
- texbin = os.path.dirname(webquiz_util.shell_command('which pdflatex').split()[-1])
- os.remove(os.path.join(texbin, 'webquiz'))
+ texbin = os.path.dirname(shutil.which('pdflatex'))
+ if sys.platform.startswith('win'):
+ os.remove(os.path.join(texbin, 'webquiz.bat'))
+ else:
+ os.remove(os.path.join(texbin, 'webquiz'))
except (FileExistsError,FileNotFoundError):
pass
@@ -729,12 +744,16 @@ class WebQuizSettings:
sys.exit(1)
# remove link to webquiz.py
- texbin = os.path.dirname(webquiz_util.shell_command('which pdflatex').split()[-1])
- webquiz = os.path.join(texbin,'webquiz')
+ texbin = os.path.dirname(shutil.which('pdflatex'))
try:
- target = os.readlink(webquiz)
- if target==os.path.join(texmf,'scripts','webquiz','webquiz.py'):
+ if sys.platform.startswith('win'):
+ webquiz = os.path.join(texbin, 'webquiz.bat')
os.remove(webquiz)
+ else:
+ webquiz = os.path.join(texbin,'webquiz')
+ target = os.readlink(webquiz)
+ if target==os.path.join(texmf,'scripts','webquiz','webquiz.py'):
+ os.remove(webquiz)
except (FileExistsError,FileNotFoundError):
pass
@@ -852,6 +871,7 @@ if __name__ == '__main__':
settings_parser.add_argument(
'-i',
'--initialise',
+ '--initialize',
action='store_true',
default=False,
help='Install web components of webquiz')
@@ -1001,41 +1021,50 @@ if __name__ == '__main__':
# - we need to use shell=True because otherwise pst2pdf gives an error
# options.talk() is a shorthand for letting the user know what is happening
if options.quiet == 0:
- options.run = lambda cmd: subprocess.call(cmd, shell=True)
+ options.run = webquiz_util.run
options.talk = lambda msg: print(msg)
elif options.quiet == 1:
- options.run = lambda cmd: subprocess.call(cmd, shell=True, stdout=open(os.devnull, 'wb'))
+ options.run = webquiz_util.quiet_run
options.talk = lambda msg: print(msg)
else:
- options.run = lambda cmd: subprocess.call(cmd, shell=True, stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'))
+ options.run = webquiz_util.silent_run
options.talk = lambda msg: None
# run through the list of quizzes and make them
for quiz_file in options.quiz_file:
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 not '.' in quiz_file:
- quiz_file += '.tex'
+ 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 not os.path.isfile(quiz_file):
- print('WebQuiz error: cannot read file {}'.format(quiz_file))
+ if ext not in ['.tex', '.xml']:
+ webquiz_util.webquiz_error(True, 'unrecognised file extension {}'.format(ext))
- else:
+ 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 if pst2pdf is used
- quiz_name = quiz_file
- if options.quiet < 2:
- print('WebQuiz generating web page for {}'.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))
- # If the pst2podf option is used then we need to preprocess
+ 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
# options.pst2pdf = True if pst2pdf is given as an option to
# the webquiz documentclass
with codecs.open(quiz_file, 'r', encoding='utf8') as q_file:
doc = q_file.read()
- options.pst2pdf = False
try:
brac = doc.index(r'\documentclass[') + 15 # start of class options
if 'pst2pdf' in [
@@ -1049,46 +1078,46 @@ if __name__ == '__main__':
except ValueError:
pass
- # the file exists and is readable so make the quiz
- webquiz_makequiz.MakeWebQuiz(quiz_name, quiz_file, options, settings, metadata)
-
- quiz_name = quiz_name[:quiz_name.index('.')] # remove the extension
-
- # move the css file into the directory for the quiz
- css_file = os.path.join(quiz_name, quiz_name + '.css')
- if os.path.isfile(quiz_name + '.css'):
- if os.path.isfile(css_file):
- os.remove(css_file)
- shutil.move(quiz_name + '.css', css_file)
-
- # now clean up unless debugging
- if not options.debugging:
- for ext in ['4ct', '4tc', 'dvi', 'idv', 'lg', 'log',
- 'ps', 'pdf', 'tmp', 'xml', 'xref'
+ # the file exists and is readable so make the quiz
+ webquiz_makequiz.MakeWebQuiz(quiz_name, quiz_file, options, settings, metadata)
+
+ quiz_name, ext = os.path.splitext(quiz_name) # extract filename and extension
+
+ # move the css file into the directory for the quiz
+ css_file = os.path.join(quiz_name, quiz_name + '.css')
+ if os.path.isfile(quiz_name + '.css'):
+ if os.path.isfile(css_file):
+ os.remove(css_file)
+ shutil.move(quiz_name + '.css', css_file)
+
+ # now clean up unless debugging
+ if not options.debugging:
+ for ext in ['4ct', '4tc', 'dvi', 'idv', 'lg', 'log',
+ 'ps', 'pdf', 'tmp', 'xml', 'xref'
+ ]:
+ if os.path.isfile(quiz_name + '.' + ext):
+ os.remove(quiz_name + '.' + ext)
+
+ # files created when using pst2pdf
+ if options.pst2pdf:
+ for file in glob.glob(quiz_name + '-pdf.*'):
+ os.remove(file)
+ for file in glob.glob(quiz_name + '-pdf-fixed.*'):
+ os.remove(file)
+ for extention in ['.preamble', '.plog', '-tmp.tex',
+ '-pst.tex', '-fig.tex'
]:
- if os.path.isfile(quiz_name + '.' + ext):
- os.remove(quiz_name + '.' + ext)
-
- # files created when using pst2pdf
- if options.pst2pdf:
- for file in glob.glob(quiz_name + '-pdf.*'):
- os.remove(file)
- for file in glob.glob(quiz_name + '-pdf-fixed.*'):
- os.remove(file)
- for extention in ['.preamble', '.plog', '-tmp.tex',
- '-pst.tex', '-fig.tex'
- ]:
- if os.path.isfile(quiz_name + extention):
- os.remove(quiz_name + extention)
- if os.path.isdir(os.path.join(quiz_name, quiz_name)):
- shutil.rmtree(os.path.join(quiz_name, quiz_name))
-
- if settings.initialise_warning != '':
+ if os.path.isfile(quiz_name + extention):
+ os.remove(quiz_name + extention)
+ if os.path.isdir(os.path.join(quiz_name, quiz_name)):
+ shutil.rmtree(os.path.join(quiz_name, quiz_name))
+
+ if settings.initialise_warning != '' and not settings.have_initialised:
print(webquiz_templates.text_initialise_warning)
except Exception as err:
- # there is a small chance that there is an error before we the
+ # there is a small chance that there is an error before the
# settings.debugging flag has been set
webquiz_util.webquiz_error(settings.debugging if 'settings' in globals() else True,
'unknown problem.\n\nIf you think this is a bug please report it by creating an issue at\n {}\n'
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz_layout.py b/Master/texmf-dist/scripts/webquiz/webquiz_layout.py
index 89b5f3d94e4..19130b7afe6 100755
--- a/Master/texmf-dist/scripts/webquiz/webquiz_layout.py
+++ b/Master/texmf-dist/scripts/webquiz/webquiz_layout.py
@@ -36,8 +36,8 @@ from webquiz_templates import no_script
# quiz.unit_code = unit code from \UnitCode
# quiz.unit_name = unit name from \UnitName
# quiz.unit_url = unit url from \UnitURL
-# quiz.webquiz_init = javascript for initialising quiz page.
-# This MUST appear tow<M-C-D-A>rds the end of HTML body
+# quiz.webquiz_init = javascript for initialising quiz page
+# MUST appear towards the end of HTML body
def write_web_page(quiz):
return quiz_page.format(
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz_makequiz.py b/Master/texmf-dist/scripts/webquiz/webquiz_makequiz.py
index cca12a664f5..5f9e66f61bb 100755
--- a/Master/texmf-dist/scripts/webquiz/webquiz_makequiz.py
+++ b/Master/texmf-dist/scripts/webquiz/webquiz_makequiz.py
@@ -49,14 +49,14 @@ class MakeWebQuiz(object):
self.options = options
self.settings = settings
self.metadata = metadata
- self.quiz_name = quiz_name.split('.')[0]
- self.quiz_file, extension = quiz_file.split('.')
+ self.quiz_file, extension = os.path.splitext(quiz_file)
+ self.quiz_name = os.path.basename(self.quiz_file)
self.webquiz_url = settings['webquiz_url']
- if self.webquiz_url[-1] == '/':
+ if self.webquiz_url[-1] == '/':
self.webquiz_url = self.webquiz_url[:len(self.webquiz_url)-1]
# run htlatex only if quiz_file has a .tex extension
- if extension == 'tex':
+ if extension == '.tex':
self.htlatex_quiz_file()
self.read_xml_file()
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz_templates.py b/Master/texmf-dist/scripts/webquiz/webquiz_templates.py
index a3c8f849945..ea86df20391 100755
--- a/Master/texmf-dist/scripts/webquiz/webquiz_templates.py
+++ b/Master/texmf-dist/scripts/webquiz/webquiz_templates.py
@@ -195,12 +195,6 @@ multiple_feedback_correct = r'''
</div>'''
multiple_feedback_answer = ' <li><em>{correct_answer}</em> {reason}</li>'
-initialise_invite = r'''WebQuiz needs to be initialised. In order to display quiz web pages
-WebQuiz needs to copy some css and javascript files into a directory
-that is accessible from your webserver.
-
-Do you want to initialise WebQuiz now [Y/n]? '''
-
# no script error when javascript is not enabled
no_script = r'''<noscript>
<div class="warning">
@@ -211,9 +205,39 @@ no_script = r'''<noscript>
</noscript>'''
######################################################################
+# missing webquiz.ini file
+######################################################################
+
+missing_webquiz_ini = r'''
+webquiz installation error: unable to find webquiz.ini -> {}
+
+If you believe that WebQuiz has been installed correctly then please try
+rebuilding the TeX filename database. On TeXLive systems this can be done
+using the command mktexlsl, or using the TeXLive gui. On MiKTEX you can
+rebuild the database from the Tasks menu on the MiKTeX console. You may
+need to run this command using an administrator account or sudo, on unix
+systems.
+
+'''
+
+######################################################################
# the remaining templates prompt the user when initialising webquiz
######################################################################
+initialise_invite = r'''WebQuiz needs to be initialised.
+
+Before WebQuiz can display quiz web pages on your system it first needs to
+copy some css and javascript files into a directory that is accessible from
+your webserver.
+
+Do you want to initialise WebQuiz now [Y/n]? '''
+
+initialise_before_settings = r'''
+Before you can view the webquiz settings you need to initialise WebQuiz
+using the command:
+ webquiz --initialise
+'''
+
initialise_introduction = r'''
WebQuiz Initialisation
======================
@@ -290,13 +314,6 @@ If you want to change the default webquiz settings please use:
webquiz --edit-settings
'''
-webquiz_url_warning = r'''
-WebQuiz has not been initialised. To remove the warning message from
-the web page please use
- webquiz --initialise
-to install the WebQuiz javascript and css files.
-'''
-
text_initialise_warning = r'''
WebQuiz has not yet been initialised. To remove this warning please use
webquiz --initialise
diff --git a/Master/texmf-dist/scripts/webquiz/webquiz_util.py b/Master/texmf-dist/scripts/webquiz/webquiz_util.py
index 7a06108e1b0..ea2e6e7b179 100755
--- a/Master/texmf-dist/scripts/webquiz/webquiz_util.py
+++ b/Master/texmf-dist/scripts/webquiz/webquiz_util.py
@@ -33,9 +33,11 @@ def shell_command(cmd):
def kpsewhich(search):
r'''
- Short-cut to access kpsewhich output. usage: kpsewhich('-var-value=TEXMFLOCAL')
+ Short-cut to access kpsewhich output.
+
+ usage: kpsewhich('-var-value=TEXMFLOCAL')
'''
- return subprocess.check_output('kpsewhich ' + search, stderr=subprocess.STDOUT, shell=True).decode('ascii').strip()
+ return subprocess.check_output('kpsewhich ' + search, shell=True).decode('ascii').strip()
# ---------------------------------------------------------------------------------------
class MetaData(dict):
@@ -126,3 +128,34 @@ def copytree(src, dst, symlinks=False, ignore=None):
copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)
+
+###############################################################################
+## shortcuts for running commands
+environ = os.environ.copy()
+
+def run(cmd, shell=False):
+ r'''
+ Run commands with output to stdout and errors to stderr
+ '''
+ if shell:
+ subprocess.call(cmd, env=environ, shell=True)
+ else:
+ subprocess.call(cmd.split(), env=environ)
+
+def quiet_run(cmd, shell=False):
+ r'''
+ Run commands with ignoring and sending errors to stderr
+ '''
+ if shell:
+ subprocess.call(cmd, env=environ, stdout=open(os.devnull, 'wb'), shell=True)
+ else:
+ subprocess.call(cmd.split(), env=environ, stdout=open(os.devnull, 'wb'))
+
+def silent_run(cmd, shell=False):
+ r'''
+ Run commands ignoring all output and errors
+ '''
+ if shell:
+ subprocess.call(cmd, env=environ, stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'), shell=True)
+ else:
+ subprocess.call(cmd.split(), env=environ, stdout=open(os.devnull, 'wb'), stderr=open(os.devnull, 'wb'))