Commit 6a45642b authored by Amrita Deb's avatar Amrita Deb
Browse files

Merge branch 'rohlfing-docstring-argument-handling' into 'master'

Automated documentation build

See merge request !39
parents 1661db24 9f907fd7
Pipeline #457905 passed with stages
in 7 minutes and 25 seconds
#!/usr/bin/env python
"""Prepares batch upload to Moodle's assignment module.
PDFs in folder 'in' are moved to a certain folder structure to be recognized
by moodle and finally zipped to 'outzip'.
Attention: Zip-archive 'outzip' will be overwritten in the following!
"""
__author__ = "Amrita Deb (deb@itc.rwth-aachen.de), " +\
"Christian Rohlfing (rohlfing@ient.rwth-aachen.de)"
import os
import time
import time # keep track of time
import shutil # copyfile, make_archive
import argparse # argument parsing
import sys
......@@ -132,46 +144,43 @@ def sanity_check(matnums_csv, matnums_folder):
return notfoundcsv, notfoundpdf
def main(args):
"""Main routine
"""
# Parse input arguments
parser = argparse.ArgumentParser(description='''
prepares batch upload to Moodle via assignment module.
PDFs in folder 'in' are moved to folder 'tmp' with a certain folder
structure and finally zipped to 'out'.
Attention: zip-archive 'out' will be overwritten in the following!
def _make_parser():
csv_parser = moodle.get_moodle_csv_parser()
parser = argparse.ArgumentParser(
parents=[csv_parser], prog='preparemoodle.py',
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
''')
parser.add_argument(
"-i", "--infolder", default="./pdfs_encrypted",
help="Input folder with PDFs. Default: ./pdfs_encrypted")
parser.add_argument(
"-c", "--csv", default="./Bewertungen.csv",
help="Moodle grading sheet. Default: ./Bewertungen.csv")
parser.add_argument(
"--csvdelim", default=",", help="CSV delimiter. Default: ','")
"infolder", help="Input folder with PDFs.")
parser.add_argument(
"--csvquote", default='"', help="CSV quote char." + """Default: '"'""")
"csv", help="Moodle grading sheet.")
parser.add_argument(
"--csvenc", default="utf-8", help="CSV encoding scheme. " +
"Typical encodings:'utf-8', 'utf-8-sig', or 'cp1252' (Windows). " +
"Default: 'utf-8'")
parser.add_argument(
"-o", "--outzip", default="./moodle_feedbacks.zip",
help="Zip archive. Default: ./moodle_feedbacks.zip")
"outzip", help="Zip archive with feedback files.")
parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run.")
parser.add_argument(
"-t", "--tmp", default="./tmp", help="Temporary folder. Default:./tmp")
"-t", "--tmp", default="./tmp", help="Temporary folder.")
parser.add_argument(
"--nowarn", action='store_true', help="Disables warnings")
"--nowarn", action='store_true', help="Disables warnings.")
parser.add_argument(
"--moodlefilesize", default="250",
help="Moodle upload file size in MiB. Default: 250")
"--moodleuploadlimit", default="250",
help="Moodle upload limit in MiB.")
return parser
# Create argument parser with default values
_parser = _make_parser()
args = parser.parse_args(args)
def main(args):
"""Main routine
"""
# Parse input arguments
args = _parser.parse_args(args)
infolder = args.infolder
sheet_csv = args.csv
outzip = args.outzip
......@@ -181,7 +190,7 @@ def main(args):
csv_delim = args.csvdelim
csv_quote = args.csvquote
csv_enc = args.csvenc
size_limit = int(args.moodlefilesize) # Moodle upload size limit in MiB
size_limit = int(args.moodleuploadlimit) # Moodle upload size limit in MiB
# Print status
starttime = time.time()
......@@ -226,9 +235,9 @@ Processing {} students'''.format(num_students))
matnums_csv = []
moodleids = []
if no_warn:
print("Start processing", sep=' ', end='', flush=True)
print("Start copying", sep=' ', end='', flush=True)
else:
print("Start processing")
print("Start copying")
for cnt, info in enumerate(infos):
# Copy PDF files
# Find all PDFs starting with matriculation number, e.g.
......@@ -303,8 +312,7 @@ Processing {} students'''.format(num_students))
# Print status
endtime = time.time()
print("""Done.
Time taken: {:.2f}""".format(endtime-starttime))
print("Time taken: {:.2f}".format(endtime-starttime))
# Main routine
......
#!/usr/bin/env python
"""Extract student's submission files from Moodle assignment
Transfer PDF files from ZIP file containing all submissions of a Moodle
assignment into output folder with file names following exam scan
naming convention.
Attention: Contents in output folder will be overwritten in the following!
"""
__author__ = "Amrita Deb (deb@itc.rwth-aachen.de), " +\
"Christian Rohlfing (rohlfing@ient.rwth-aachen.de)"
import sys # get arguments from command line
import os # path listing/manipulation/...
import time # keep track of time
......@@ -7,61 +22,58 @@ import shutil # unzipping and copying files
from utils import moodle as moodle
def main(args):
"""Transfer PDF files from submisions zip file (or already extracted folder)
containing all submissions into user provided folder following exam scan
naming convention
def _make_parser():
csv_parser = moodle.get_moodle_csv_parser()
1) Files are extracted from zip file location eg: ./all_submissions.zip
In case folder is given, extraction is skipped.
2) Scan through extracted folder for PDF files.
Only 1 PDF file/student is accepted.
3) Matriculation number and last name are fetched from grading worksheet
4) PDFs from extracted folder are renamed according to convention and
placed in user provided outfolder
"""
parser = argparse.ArgumentParser(
parents=[csv_parser],
description=__doc__, prog='preparepdf.py',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Argument handling
parser = argparse.ArgumentParser(description='''
Zip file 'inzip', containing all submissions of an assignment,
is extracted, renamed according to convention 'filenameformat'
and placed in folder 'outfolder'.
''')
parser.add_argument(
"-i", "--inzip", default="submissions.zip",
help="Input zip file or already extracted folder. " +
"Default: ./submissions.zip")
"inzip", help="Input ZIP file or extracted folder.")
parser.add_argument(
"csv", help="Moodle grading sheet.")
parser.add_argument(
"-o", "--outfolder", default="./pdfs",
help="Output folder with PDFs. Default: ./pdfs")
"outfolder", help="Output folder with PDFs.")
parser.add_argument(
"--filenameformat", default="{matnum}_{fullname[0]}",
"-f", "--filenameformat", default="{matnum}_{fullname[0]}",
help="File name format. Available keywords: " +
"{matnum}, {fullname}, {lastname}, {firstname}. " +
"Default: '{matnum}_{fullname[0]}'")
parser.add_argument(
"--copyall", action='store_true',
"-c", "--copyall", action='store_true',
help="If set, copies all files (including multiple and non-PDF files)")
parser.add_argument(
"--appendoriginal", action='store_true',
"-a", "--appendoriginal", action='store_true',
help="If set, appends original file name to new location's file name")
parser.add_argument(
"-c", "--csv", default="./Bewertungen.csv",
help="Moodle grading sheet. Default: ./Bewertungen.csv")
parser.add_argument(
"--csvdelim", default=",", help="CSV delimiter. Default: ','")
parser.add_argument(
"--csvquote", default='"', help="CSV quote char." + """Default: '"'""")
parser.add_argument(
"--csvenc", default="utf-8", help="CSV encoding scheme. " +
"Typical encodings:'utf-8', 'utf-8-sig', or 'cp1252' (Windows). " +
"Default: 'utf-8'")
parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run.")
parser.add_argument(
"-t", "--tmp", default="./tmp", help="Temporary folder. Default:./tmp")
"-t", "--tmp", default="./tmp", help="Temporary folder.")
return parser
args = parser.parse_args(args)
# Create argument parser with default values
_parser = _make_parser()
def main(args):
"""Main routine
1) Files are extracted from zip file location eg: ./all_submissions.zip
In case folder is given, extraction is skipped.
2) Scan through extracted folder for PDF files.
Only 1 PDF file/student is accepted.
3) Matriculation number and last name are fetched from grading worksheet
4) PDFs from extracted folder are renamed according to convention and
placed in user provided outfolder
"""
# Argument handling
args = _parser.parse_args(args)
inzip = args.inzip
outfolder = args.outfolder
sheet_csv = args.csv
......
#!/usr/bin/env python
"""Rename scanned PDFs assuming scan order equal to alphabetical order of
students in Moodle grading sheet.
Renames scans accordingly to info in Moodle grading sheet, such that the
file name starts with the matriculation number. This only works if exams were
scanned in alphabetical order.
Optionally, each scanned PDF is searched for barcodes/QRs containing the
matriculation number to double check.
Attention: Contents in output folder will be overwritten in the following!
"""
__author__ = "Amrita Deb (deb@itc.rwth-aachen.de), " +\
"Christian Rohlfing (rohlfing@ient.rwth-aachen.de)"
import os
import time
import shutil # copyfile, make_archive
......@@ -11,49 +27,44 @@ import utils.matnum as matnum_utils
import utils.qr as qr_utils
def main(args):
"""Main routine
"""
def _make_parser():
csv_parser = moodle.get_moodle_csv_parser()
parser = argparse.ArgumentParser(
parents=[csv_parser],
description=__doc__, prog='renamescans.py',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Parse input arguments
parser = argparse.ArgumentParser(description='''
renames scans accordingly to info in Moodle grading sheet, such that
the file name starts with the matriculation number.
This only works if exams were scanned in alphabetical order.
Optionally, each scanned PDF is searched for barcodes/QRs containing
the matriculation number to double check.
Attention: Contents in output folder are overwritten!
''')
parser.add_argument(
"-i", "--infolder", default="./pdfs_scan",
help="Input folder with PDFs. Default: ./pdfs_scan")
"infolder", help="Input folder with PDFs.")
parser.add_argument(
"-o", "--outfolder", default="./pdfs",
help="Output folder with renamed scans. Default: ./pdfs")
"csv", help="Moodle grading sheet.")
parser.add_argument(
"outfolder", help="Output folder with renamed scans.")
parser.add_argument(
"--filenameformat", default="{matnum}_{fullname[0]}",
help="File name format. Available keywords: " +
"{matnum}, {fullname}, {lastname}, {firstname}. " +
"Default: '{matnum}_{fullname[0]}'")
parser.add_argument(
"-c", "--csv", default="./Bewertungen.csv",
help="Moodle grading sheet file. Default: ./Bewertungen.csv")
parser.add_argument(
"--csvdelim", default=",", help="CSV delimiter. Default: ','")
parser.add_argument(
"--csvquote", default='"', help="CSV quote char." + """Default: '"'""")
parser.add_argument(
"--csvenc", default="utf-8", help="CSV encoding scheme. " +
"Typical encodings:'utf-8', 'utf-8-sig', or 'cp1252' (Windows). " +
"Default: 'utf-8'")
parser.add_argument(
"-q", "--checkqr", action='store_true',
help="Flag for additional QR code match.")
parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run.")
args = parser.parse_args(args)
return parser
# Create argument parser with default values
_parser = _make_parser()
def main(args):
"""Main routine
"""
# Parse input arguments
args = _parser.parse_args(args)
infolder = args.infolder
sheet_csv = args.csv
outfolder = args.outfolder
......@@ -151,8 +162,7 @@ def main(args):
# Print time
endtime = time.time()
print("""Done.
Time taken: {:.2f}""".format(endtime-starttime))
print("Time taken: {:.2f}".format(endtime-starttime))
# Main routine
......
......@@ -3,11 +3,18 @@
"""Prepare supplement material
This script copies and renames supplementary material (such as exam sheet or
sample solution) to have the prefix ("[matnum]_[lastname]").
sample solution) with file names following the exam scan naming convention.
This information is either taken from the filenames of exam scan PDFs or from
the Moodle grading CSV file.
Attention: Contents in output folder will be overwritten in the following!
"""
__author__ = "Amrita Deb (deb@itc.rwth-aachen.de), " +\
"Christian Rohlfing (rohlfing@ient.rwth-aachen.de)"
import sys # get arguments from command line
import os # path listing/manipulation/...
import time # keep track of time
......@@ -71,44 +78,44 @@ def copy_supplements(supp_dir, supp_files, prefixes, output_dir, dry=False):
return copied_files
def main(args):
"""Main function
"""
def _make_parser():
csv_parser = moodle.get_moodle_csv_parser()
parser = argparse.ArgumentParser(
parents=[csv_parser],
description=__doc__, prog='supplements.py',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# Argument handling
parser = argparse.ArgumentParser(description='''
This script copies supplementary material (such as exam sheet or sample
solution) to have the prefix (e.g. "[matnum]_[lastname]").
This information is either taken from the filenames of exam scan PDFs or
from the Moodle grading CSV file.
''')
parser.add_argument(
"-i", "--infolder", default="./supplements",
help="Folder with supplements. Default: ./supplements")
"infolder", help="Folder with supplements.")
parser.add_argument(
"-p", "--prefix", default="./pdfs",
help="Provides information to construct prefixes. Either PDF folder " +
"with scanned PDFs or Moodle grading CSV file. Default: ./pdfs")
"prefix", help="Provides information to construct prefixes. Either " +
"folder with scanned PDFs or Moodle grading CSV file.")
parser.add_argument(
"-o", "--outfolder", default="./supplements_out",
help="Output folder. Default: ./supplements_out")
"outfolder",
help="Output folder with supplements per student.")
parser.add_argument(
"--filenameformat", default="{matnum}_{fullname[0]}",
help="File name format. Available keywords: " +
"{{matnum}}, {{fullname}}, {{lastname}}, {{firstname}}. " +
"Default: '{{matnum}}_{{fullname[0]}}'")
parser.add_argument(
"--csvdelim", default=",", help="CSV delimiter. Default: ','")
parser.add_argument(
"--csvquote", default='"', help="CSV quote char." + """Default: '"'""")
parser.add_argument(
"--csvenc", default="utf-8", help="CSV encoding scheme. " +
"Typical encodings:'utf-8', 'utf-8-sig', or 'cp1252' (Windows). " +
"Default: 'utf-8'")
parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run")
args = parser.parse_args(args)
return parser
# Create argument parser with default values
_parser = _make_parser()
def main(args):
"""Main routine
"""
# Argument handling
args = _parser.parse_args(args)
supp_dir = args.infolder
prefixinfo = args.prefix
prefixformat = args.filenameformat
......
Identifier,"Full name","Registration number",Status,Grade,"Grade can be changed","Last modified (grade)","Feedback comments"
"Participant 1519332","d'Lastname, FirstnameL",123012,,,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",
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