Commit 102fbf2a authored by Christian Rohlfing's avatar Christian Rohlfing
Browse files

Adapted batch

parent 57b52b42
import os, sys,subprocess,time
import os
import time
import argparse
import shutil
import watermark
import encrypt
import preparemoodle
if __name__ == '__main__':
#Parameters definition
# Parameters definition
parser = argparse.ArgumentParser(description='''
Watermark and encrypts exams and prepares everything for moodle upload.
Watermark and encrypts exams and prepares everything for moodle upload.
Attention: contents of folder 'out' will be deleted in the beginning!
Options:
......@@ -15,66 +20,58 @@ Options:
-o, --out output folder containing passwords.csv and moodle_feedbacks.zip. Default: ./out
-p, --password sets global password. Default: empty, such that each PDF gets a custom password generated with 'pwgen'
-e, --cores number of cores for watermarking. Default: 1
-d, --dpi dpi parameter for conversion from pdf to images. Default: 250
-d, --dpi dpi parameter for pdf to image conversion. Default: 250
-q, --quality quality parameter for jpeg. Default: 25
-t, --tmp tmp folder. Default: ./tmp
''')
parser.add_argument("-i", "--infolder", default="./pdfs",
parser.add_argument("-i", "--infolder", default="./pdfs",
help="Input folder with PDFs. Default: ./pdfs")
parser.add_argument("-c", "--csv", default="Bewertungen.csv",
parser.add_argument("-c", "--csv", default="Bewertungen.csv",
help="Moodle grading CSV file, needed to construct the folder names for moodle zip")
parser.add_argument("-o", "--outfolder", default="./out",
parser.add_argument("-o", "--outfolder", default="./out",
help="output folder containing passwords.csv and moodle_feedbacks.zip. Default: ./out")
parser.add_argument("-e", "--cores", default="2",
parser.add_argument("-e", "--cores", default="2",
help="Number of cores for parallel processing. Default: 2")
parser.add_argument("-p", "--password", default=" ",
parser.add_argument("-p", "--password", default="",
help="sets global password. Default: empty, such that each PDF gets a custom password generated with 'pwgen'")
parser.add_argument("-d", "--dpi", default="250",
parser.add_argument("-d", "--dpi", default="250",
help="dpi parameter for conversion from pdf to images. Default: 250")
parser.add_argument("-t", "--tmp", default="./tmp",
parser.add_argument("-t", "--tmp", default="./tmp",
help="tmp folder. Default: ./tmp/")
args = parser.parse_args()
infolder =args.infolder
infolder = args.infolder
csv = args.csv
outfolder = args.outfolder
cores = args.cores
dpi = args.dpi
tmp = args.tmp
starttime = time.time()
password = args.password
#Empty 'out' folder
for root, dirs, files in os.walk(outfolder):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d))
#Empty 'tmp' folder
for root, dirs, files in os.walk(tmp):
for f in files:
os.unlink(os.path.join(root, f))
for d in dirs:
shutil.rmtree(os.path.join(root, d))
starttime = time.time()
# Watermarking process
watermark_outfolder = tmp+'/pdfs_watermarked'
# Watermarking process
watermark_outfolder = os.path.join(tmp, 'pdfs_watermarked')
if not os.path.exists(watermark_outfolder):
os.makedirs(watermark_outfolder)
subprocess.call((sys.executable, 'watermark.py', '--in', infolder,'--out', watermark_outfolder, '--cores', cores))
encrypt_outfolder = tmp+'/pdfs_encrypted'
if not os.path.exists(encrypt_outfolder):
os.makedirs(encrypt_outfolder)
if args.password==" ":
subprocess.call((sys.executable, 'encrypt.py', '--in', watermark_outfolder, '--out',encrypt_outfolder,'--passwordout',outfolder))
else:
subprocess.call((sys.executable, 'encrypt.py', '--in', watermark_outfolder, '--out',encrypt_outfolder,'--passwordout',outfolder,'--password',args.password))
watermark.main(['--in', infolder, '--out', watermark_outfolder,
'--cores', cores])
enc_out = os.path.join(tmp, 'pdfs_encrypted')
if not os.path.exists(enc_out):
os.makedirs(enc_out)
passwordcsv = os.path.join(outfolder, 'passwords.csv')
encrypt.main(['--in', watermark_outfolder, '--out', enc_out,
'--passwordout', passwordcsv, '--password', password])
# ZIP Archive preparation process
moodle_out = os.path.join(outfolder, 'moodle_feedbacks.zip')
moodle_tmp = os.path.join(tmp, 'tmp')
if not os.path.exists(moodle_tmp):
os.makedirs(moodle_tmp)
preparemoodle.main(['--in', enc_out, '--csv', csv, '--tmp', moodle_tmp,
'--out', moodle_out])
#ZIP Archive preparation process
if not os.path.exists('./tmp/tmp'):
os.makedirs('./tmp/tmp')
subprocess.call((sys.executable, 'preparemoodle.py','--in',encrypt_outfolder,'--csv',csv,'--batch','1', '--tmp', './tmp/tmp', '--out',outfolder+'/moodle_feedbacks.zip'))
endtime = time.time()
print(f'\nTotal time taken: {endtime-starttime:.2f}s\n')
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