Commit ccefd8e3 authored by Deb's avatar Deb
Browse files

Iss6 + Iss8

parent 67f26a2e
Pipeline #456347 failed with stage
in 1 minute and 1 second
......@@ -122,12 +122,25 @@ Folder `supplements_out` contains copies of the sample solutions for each studen
We assume that the folder `./pdfs` holds the scans of the exams and .
The filename of each PDF should start with the matriculation number of the student, e.g. `./pdfs/123456_Lastname.pdf`.
Arguments:
1. infolder (MANDATORY): Folder from which the pdfs to be watermarked will be taken from
1. outfolder (MANDATORY): Folder where the watermarked pdfs will be stored
1. fontsize (OPTIONAL) : Font size of watermark text in points. Denoted by `--fontsize`. Default is 75
1. cores (OPTIONAL) : Number of cores for parallel processing. Denoted by `--cores`. Default is 1
1. tmp (OPTIONAL) : Temporary folder where intermediate files will be stored and later deleted. Denoted by `--tmp`. Default is './tmp'
1. dpi (OPTIONAL) : Dots per inch resolution parameter for the PDF. Denoted by `--dpi`. Default is 150.
1. quality (OPTIONAL) : Compression quality of the image of each page of the PDF. Denoted by `--quality`. Default is 75
```bash
python watermark.py --in ./pdfs --out ./pdfs_watermarked --cores 2
```
Folder `pdfs_watermarked` contains watermarked PDFs, with each page watermarked with the matriculation number of the student.
**TIP:** Play around with `dpi` and `quality` parameters according to your requirements. Higher values for these two will result in high resolution PDFs of bigger size(ideal for when the number of files is low). Lower values will result in PDFs having lower filesize and low resolution (ideal when the number of files is high)
#### Watermark Sample solution copies
We assume that the folder `./supplements_out` holds the copies for every students
......
......@@ -64,7 +64,10 @@ def main(args):
args = parser.parse_args(args)
infolder = args.infolder
outfolder = args.outfolder
if not os.path.exists(outfolder):
os.makedirs(outfolder)
if args.passwordout == "":
password_file = os.path.join(outfolder, 'passwords.csv')
else:
......@@ -103,8 +106,6 @@ Exiting now.""")
else:
password = args.password
if not os.path.exists(outfolder):
os.makedirs(outfolder)
# Encrypt
in_file = os.path.join(infolder, pdf_file)
enc_file = os.path.splitext(pdf_file)[0] + '_aes.pdf'
......
......@@ -9,6 +9,23 @@ import sys
import utils.moodle as moodle
import utils.matnum as matnum_utils
import zipfile
def bytesto(bytes, to, bsize=1024):
"""convert bytes to megabytes, etc.
sample code:
print('mb= ' + str(bytesto(314575262000000, 'm')))
sample output:
mb= 300002347.946
"""
a = {'k' : 1, 'm': 2, 'g' : 3, 't' : 4, 'p' : 5, 'e' : 6 }
r = float(bytes)
for i in range(a[to]):
r = r / bsize
return(round(r,2))
def sanity_check(matnums_csv, matnums_folder):
"""Check two cases for sanity:
......@@ -149,7 +166,7 @@ Processing {} students'''.format(num_students))
# Prepare submission folder
folder = moodle.submission_folder_name(info)
longfolder = os.path.join(tmp_folder, folder)
# Create folder
if not dry:
os.mkdir(longfolder)
......@@ -185,10 +202,27 @@ Processing {} students'''.format(num_students))
# Zip
if not dry:
# Zip
print("Zipping")
shutil.make_archive(os.path.splitext(outzip)[0], 'zip', tmp_folder)
print('Zip archive is stored at {}'.format(outzip))
foldersize = 0
count = 1
z = zipfile.ZipFile(os.path.splitext(outzip)[0]+str(count)+".zip", "w")
for dirpath, dirnames, filenames in os.walk(tmp_folder):
for file in filenames:
file_path = os.path.join(dirpath, file)
if not os.path.islink(file_path):
foldersize += os.path.getsize(file_path)
if bytesto(foldersize,'m') < 250:
z.write(file_path,os.path.join(os.path.relpath(file_path, tmp_folder),file))
os.remove(file_path)
else:
print("Preparing zip file "+str(count))
z.close()
print('Zip archive is stored at {}'.format(os.path.splitext(outzip)[0]+str(count)+".zip"))
count+=1
foldersize = 0
z = zipfile.ZipFile(os.path.splitext(outzip)[0]+str(count)+".zip", "w")
z.write(file_path,os.path.join(os.path.relpath(file_path, tmp_folder),file))
os.remove(file_path)
# Delete temporary folder
shutil.rmtree(tmp_folder)
......
ID,"Vollständiger Name",Matrikelnummer,Status,Bewertung,"Status des Bewertungsworkflows","Bewertung kann geändert werden","Zuletzt geändert (Abgabe)","Zuletzt geändert (Bewertung)","Feedback als Kommentar"
Teilnehmer/in107,"Four, Student",123456,"Zur Bewertung abgegeben - Unbewertet",,Unbewertet,Ja,"Montag, 18. Mai 2020, 10:11",-,
Teilnehmer/in106,"One, Student",123457,"Keine Abgabe - Unbewertet",,Unbewertet,Ja,-,"Samstag, 16. Mai 2020, 12:15",-,
Teilnehmer/in105,"Three, Student",125412,"Keine Abgabe - Unbewertet",,Unbewertet,Ja,-,"Samstag, 16. Mai 2020, 12:15",-,
\ No newline at end of file
Identifier,"Full name","Registration number",Status,Grade,"Grade can be changed","Last modified (grade)","Feedback comments"
"Participant 1519324","Lastname, First",321121,,,Yes,"Monday, 15 March 2021, 5:42 PM",
"Participant 1519323","Yet another last name, First Name",321122,,,Yes,"Monday, 15 March 2021, 5:42 PM",
"Participant 1519322","Last, First",321123,,,Yes,"Monday, 15 March 2021, 5:42 PM",
"Participant 1519321","d'Lastname, Firstname",321124,,,Yes,"Monday, 15 March 2021, 5:42 PM",
"Participant 1519331","LastnameK, FirstnameK",123011,,,Yes,"Monday, 15 March 2021, 5:42 PM",
"Participant 1519330","LastnameJ, FirstnameJ",123010,,,Yes,"Monday, 15 March 2021, 5:42 PM",
"Participant 1519322","LastnameB, FirstnameB",123002,,,Yes,"Monday, 15 March 2021, 5:42 PM",
"Participant 1519321","LastnameA, FirstnameA",123001,,,Yes,"Monday, 15 March 2021, 5:42 PM",
......@@ -18,22 +18,42 @@ class MainTest(unittest.TestCase):
# Clean up
shutil.rmtree(self.test_dir)
def test_encrypt_scan_single(self):
import encrypt
expected_files = ["123001_LastnameA_aes.pdf",
'passwords.csv']
# Prepare parameter
in_dir = './tests/assets/pdfs'
out_dir = os.path.join(self.test_dir, 'out')
os.mkdir(out_dir)
# Encrypt files
encrypt.main([in_dir,out_dir])
created_files = os.listdir(out_dir)
created_files.sort()
self.assertEqual(expected_files, created_files)
def test_encrypt_scans(self):
import encrypt
expected_files = ['123456_Nachname_aes.pdf',
'456789_Lastname_aes.pdf',
'567891_Student_aes.pdf',
expected_files = ["123001_LastnameA_aes.pdf",
"123002_LastnameB_aes.pdf",
"123010_LastnameJ_aes.pdf",
"123011_LastnameK_aes.pdf",
'passwords.csv']
# Prepare parameter
in_dir = './pdfs'
in_dir = './tests/assets/pdfs'
out_dir = os.path.join(self.test_dir, 'out')
os.mkdir(out_dir)
# Encrypt files
encrypt.main(["-i", in_dir, "-o", out_dir])
encrypt.main([in_dir,out_dir])
created_files = os.listdir(out_dir)
created_files.sort()
......@@ -46,13 +66,13 @@ class MainTest(unittest.TestCase):
'passwords.csv']
# Prepare parameter
in_dir = './supplements'
in_dir = './tests/assets/supplements'
out_dir = os.path.join(self.test_dir, 'out')
os.mkdir(out_dir)
# Encrypt files
encrypt.main(["-i", in_dir, "-o", out_dir])
encrypt.main([in_dir, out_dir])
created_files = os.listdir(out_dir)
created_files.sort()
......
......@@ -14,15 +14,15 @@ class MainTest(unittest.TestCase):
def test_extract_grading_info(self):
from utils import moodle as moodle_utils
csv_file = "./Bewertungen.csv"
csv_file = "./tests/assets/Grades.csv"
gis = moodle_utils.extract_info(sheet_csv=csv_file)
self.assertEqual(gis[2]['lastname'], "Three")
self.assertEqual(gis[2]['lastname'], "LastnameA")
num_students = moodle_utils.get_student_number(sheet_csv=csv_file)
self.assertEqual(num_students, 3)
csv_file = "./Grades.csv"
csv_file = "./tests/assets/Grades.csv"
gis = moodle_utils.extract_info(sheet_csv=csv_file)
# Check that "d'Lastname" gets whitened to "dLastname"
self.assertEqual(gis[3]['lastname'], "dLastname")
self.assertEqual(gis[3]['lastname'], "LastnameA")
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