Commit ceef0000 authored by lfilippo's avatar lfilippo

Add timestamp to list o' files

parent 440a9f00
#!/usr/bin/env python
import re, os, sys, subprocess
import time
from subprocess import Popen, PIPE, STDOUT
from collections import defaultdict
......@@ -289,6 +290,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
......@@ -297,13 +299,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 with data for each file
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
......@@ -344,12 +349,14 @@ def create_tex(dirname, original_files=[], template_dir="", verbose=False):
return texstr, allfiles
def main(dirname, ip, identifier, original_files=[], lecture_title='', template_dir='', verbose=True):
def main(dirname, ip, identifier, original_files=[], lecture_title='', template_dir='', verbose=True,
header = [ "fname", "ftype", "timestamp", "md5" ]):
"""
Keyword Arguments:
dirname -- root directory
identifier -- Student name, nethz account
original_files -- list of md5 hashes of original files
header -- list of columns to display (in that order): possible: fname, ftype, timestamp, md5
"""
# grab files in root directory
cwd = os.getcwd()
......@@ -372,49 +379,78 @@ 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}` \\'
# Create a header for type of file (given category identifier)
def get_category_string(category, header):
cat = {
"unmodified" : "Unmodified",
"modified" : "Modified",
"duplicate" : "Modified (Duplicates)",
"ignored" : "Ignored",
}
ncols = len(header);
# Escape nightmare
return r'\hline\multicolumn{{{}}}{{|l|}}{{\textbf{{{}}}}}\\\hline'.format(ncols, cat[category])
def get_formatted_string(item, head):
"""
Given column name, return appropriated formatted text.
"""
if head == 'fname':
return r'\verb`{' + item['fname'] + r'}`'
elif head == "ftype":
return short_names[item['ftype']]
elif head == "timestamp":
return str(item['timestamp'])
elif head == "md5":
return r'\verb`{' + item['md5s'] + r'}`'
# Given item, returns row of table representing item
def get_formatted_item_string(item, header):
template_str = ''
for i, head in enumerate(header):
template_str += get_formatted_string(item, head)
if i+1 == len(header):
template_str += "\\\\"
else:
template_str += "&"
return template_str
ncols = len(header);
out.append(r'\begin{tabular}{' + '|l'*ncols + '|}')
# modified
out.append(get_category_string("modified", header))
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, header))
# duplicate
out.append(
r'\hline\multicolumn{3}{|l|}{\textbf{Modified (duplicates)}}\\\hline')
out.append(get_category_string("duplicate", header))
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, header))
# not modified
out.append(r'\hline\multicolumn{3}{|l|}{\textbf{Unmodified}}\\\hline')
out.append(get_category_string("unmodified", header))
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, header))
# ignored
out.append(r'\hline\multicolumn{3}{|l|}{\textbf{Ignored}}\\\hline')
out.append(get_category_string("ignored", header))
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, header))
out.append(r'\hline')
out.append(r'\end{tabular}')
out.append(r'\end{table}')
......
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