Commit 916658be authored by Filippo Leonardi's avatar Filippo Leonardi

Merge branch 'F_branch' into 'master'

# Conflicts:
#   header.txt
#   latex_creator.py
parents 792b1661 46fc9206
......@@ -63,11 +63,24 @@
% Define appearance of C++ code
\lstdefinestyle{CPP}{
language=C++,
mathescape=false,
%mathescape=true,
alsoletter={\\,/,*},
morekeywords={\\brief,\\return,\\param, Dune, Eigen, MatrixXd, VectorXd, assert, Zero},
frame=lb,
xleftmargin=4.2pt,
numbers=left,
keywordstyle=\color{blue}\bfseries,
stringstyle=\color{red}\textit,
commentstyle=\color{green}\ttfamily,
morecomment=[l][\color{magenta}]{\#}
keywords={if, while, for, else, switch, std, cout}
morekeywords={\\brief,\\return,\\param, Dune, Eigen, MatrixXd, VectorXd, assert, Zero, define, \\\#},
literate={\\f}{}0,
basicstyle={\ttfamily \small },
tabsize=4,
breaklines=true,
numberstyle=\color{gray},
prebreak=\mbox{\tiny$\searrow$},
postbreak=\mbox{{\color{gray}$\cdots$}},
}
\lstdefinestyle{MATLAB}{
......@@ -97,7 +110,6 @@
xleftmargin=4.2pt,
}
\lstset{literate={\\f}{}0}
\newcommand{\f}{} % Escape C++ doxygen LaTeX commands of the form \f$ fancy math \f$
......
#!/usr/bin/env python
import re, os, sys, subprocess
<<<<<<< latex_creator.py
import re, os, sys, subprocess, time
from subprocess import Popen, PIPE, STDOUT
from collections import defaultdict
......@@ -272,6 +273,7 @@ def create_tex(dirname, original_files=[], template_dir="", verbose=False):
# print('symlink detected')
pass
# Informations about file named fname
ftype = get_ftype(fname)
md5s = md5sum(fname)
is_duplicate = md5s in hashsums
......@@ -280,13 +282,16 @@ def create_tex(dirname, original_files=[], template_dir="", verbose=False):
is_modified = md5s not in original_files
is_invalid = [lf(fname) for lf in invalid_filenames]
omitted_flag = True in is_invalid
timestamp = time.ctime(os.path.getmtime(fname))
# Dictionary of statistics
files_filtered.append({'fname': fname,
'template-dir': template_dir,
'ftype': ftype,
'md5s': md5s,
'is_modified': is_modified,
'is_duplicate': is_duplicate,
'timestamp' : timestamp,
'omitted': omitted_flag})
allfiles += files_filtered
# create tex
......@@ -314,7 +319,8 @@ def create_tex(dirname, original_files=[], template_dir="", verbose=False):
if not section_tex_str == '':
if section_label == '_____etc':
texstr += '\n \\clearpage \\section{Etc} \n'
# Etc. is bugging me
texstr += '\n \\clearpage \\section{Modified files} \n'
else:
texstr += '\n \\clearpage \\section{' + section_label.replace(
"_", "-") + '} \n'
......@@ -355,49 +361,57 @@ def main(dirname, ip, identifier, original_files=[], lecture_title='', template_
my_header = my_header.replace('LECTURETITLE', lecture_title)
out = [r'\begin{table}[h!] \centering']
out.append(r'\renewcommand{\arraystretch}{1.2}')
out.append(r'\begin{tabular}{|l|l|l|}')
out.append(r'\hline\multicolumn{3}{|l|}{\textbf{Modified}}\\\hline')
template_str = r'\verb`{:s}`& {:s} & \verb`{:s}` \\'
ncols = 4;
# Create a header for type of file
def get_category_string(category):
# Escape nightmare
return r'\hline\multicolumn{{{}}}{{|l|}}{{\textbf{{{}}}}}\\\hline'.format(ncols, category)
# Given item, returns row of table representing item
template_str = r'\verb`{:s}`& {:s} & {:s} & \verb`{:s}` \\'
def get_formatted_item_string(item):
return template_str.format(item['fname'],
short_names[item['ftype']],
item['timestamp'],
item['md5s'])
out.append(r'\begin{tabular}{' + '|l'*ncols + '|}')
# modified
out.append(get_category_string("Modified"))
modified_files = filter(
lambda x: (x['is_modified'] is True and x['is_duplicate'] is False
and x['omitted'] is False and not x['ftype'] == 'symbolic link'),
files)
for item in modified_files:
out.append(
template_str.format(item['fname'], short_names[item['ftype']],
item['md5s']))
out.append(get_formatted_item_string(item))
# duplicate
out.append(
r'\hline\multicolumn{3}{|l|}{\textbf{Modified (duplicates)}}\\\hline')
out.append(get_category_string("Modified (duplicates)"))
for item in filter(
lambda x: (x['is_modified'] is True and x['omitted'] is False
and x['is_duplicate'] is True and not x['ftype'] == 'symbolic link'),
files):
out.append(
template_str.format(item['fname'], short_names[item['ftype']],
item['md5s']))
out.append(get_formatted_item_string(item))
# not modified
out.append(r'\hline\multicolumn{3}{|l|}{\textbf{Unmodified}}\\\hline')
out.append(get_category_string("Unmodified"))
for item in filter(
lambda x: (x['is_modified'] is False and x['omitted'] is False
and not x['ftype'] == 'symbolic link'),
files):
out.append(
template_str.format(item['fname'], short_names[item['ftype']],
item['md5s']))
out.append(get_formatted_item_string(item))
# ignored
out.append(r'\hline\multicolumn{3}{|l|}{\textbf{Ignored}}\\\hline')
out.append(get_category_string("Ignored"))
for item in filter(
lambda x: (x['omitted'] is True and not x['ftype'] == 'symbolic link'),
files):
out.append(
template_str.format(item['fname'], short_names[item['ftype']],
item['md5s']))
out.append(get_formatted_item_string(item))
out.append(r'\hline')
out.append(r'\end{tabular}')
out.append(r'\end{table}')
......
......@@ -7,6 +7,9 @@ import latex_creator
exam_user_file='.exam-setup-user'
def read_info_file(infofile):
"""
Read end variables from results folder (username and realname)
"""
with open(infofile) as f:
for line in f.readlines():
match = re.search('export LOGINNAME="(.+?)"', line)
......@@ -20,6 +23,9 @@ def read_info_file(infofile):
def get_name_table():
"""
Computer ip - names table
"""
name_table = {}
for dirname in os.listdir(args.results):
......@@ -33,6 +39,9 @@ def get_name_table():
def get_file_hashes(hashfile):
"""
Read all hashes from the hash file
"""
with open(hashfile) as f:
hashes = [l[:32] for l in f.readlines()]
return hashes
......
#!/usr/bin/env python
import copy, sys
from PyPDF2 import PdfFileWriter, PdfFileReader
import glob, os
output = PdfFileWriter()
output_page_number = 0
alignment = 4 # to align on even pages
for filename in glob.glob("*.pdf"):
# This code is executed for every file in turn
print(filename)
input = PdfFileReader(open(filename, "rb"))
for p in [input.getPage(i) for i in range(0,input.getNumPages())]:
# This code is executed for every input page in turn
output.addPage(p)
output_page_number += 1
while output_page_number % alignment != 0:
output.addBlankPage()
output_page_number += 1
output_stream = open("file.pdf", "wb")
output.write(output_stream)
......@@ -41,6 +41,12 @@ if [[ ! $? -eq 0 ]]; then
echo "Cannot find parallel command. Make sure you have gnu parallel installed. Exiting."
exit 1
fi
if [[ ! -e ~/.fonts/Inconsolata.otf ]]; then
echo "Installing fonts..."
mkdir -p ~/.fonts/ && cp ./Inconsolata.otf ~/.fonts/
sudo mk
fi
if (( $+myoptions[--help] )) ; then
show_help $0
......@@ -135,6 +141,8 @@ if (( $+myoptions[-t] )) ; then
fi
fi
log="xelatex_compile_$(date +"%s").log"
# compile
if (( $+myoptions[-c] )) ; then
if [[ ! -e $HOME/.fonts/Inconsolata-Regular.ttf ]]; then
......@@ -142,6 +150,7 @@ if (( $+myoptions[-c] )) ; then
mkdir -p $HOME/.fonts && cp ${source_dir}/Inconsolata-{Bold,Regular}.ttf $HOME/.fonts/
fi
echo "\n>>> Compiling PDFs in $results ... \n"
touch $log
(
cd $results
# get all subfolders containing the EXAM_SETUP_USER file
......@@ -158,9 +167,9 @@ if (( $+myoptions[-c] )) ; then
(echo "*WARNING* $texfile does not exist." 1>&2)
fi
done)
echo $files | parallel --bar --will-cite xelatex '-interaction nonstopmode -halt-on-error' > /dev/null
echo $files | parallel --bar --will-cite xelatex '-interaction nonstopmode -halt-on-error' > /dev/null
# check if pdf was created
echo $files | parallel --bar --will-cite xelatex '-interaction nonstopmode -halt-on-error' >> $log
echo $files | parallel --bar --will-cite xelatex '-interaction nonstopmode -halt-on-error' >> $log
for ldir in ${(f)results_dir}; do
tail=${ldir:t}
texfile=${ldir}/${tail}.tex
......@@ -168,12 +177,14 @@ if (( $+myoptions[-c] )) ; then
if [[ ! -f "$pdfpath.pdf" ]]; then
(echo "*WARNING* no PDF created for $ldir" 1>&2)
fi
counter=$((counter+1))
done
)
echo "Compiling done, xelatex log written to \"$log\"."
fi
# concatenate PDFs
if (( $+myoptions[-s] )) ; then
(cd $results && pdfunite [0-9]*pdf results.pdf)
fi
fi
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment