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 #!/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 os
import time import time # keep track of time
import shutil # copyfile, make_archive import shutil # copyfile, make_archive
import argparse # argument parsing import argparse # argument parsing
import sys import sys
...@@ -132,46 +144,43 @@ def sanity_check(matnums_csv, matnums_folder): ...@@ -132,46 +144,43 @@ def sanity_check(matnums_csv, matnums_folder):
return notfoundcsv, notfoundpdf return notfoundcsv, notfoundpdf
def main(args): def _make_parser():
"""Main routine csv_parser = moodle.get_moodle_csv_parser()
""" parser = argparse.ArgumentParser(
parents=[csv_parser], prog='preparemoodle.py',
# Parse input arguments description=__doc__,
parser = argparse.ArgumentParser(description=''' formatter_class=argparse.ArgumentDefaultsHelpFormatter)
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!
''')
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( parser.add_argument(
"--csvdelim", default=",", help="CSV delimiter. Default: ','") "infolder", help="Input folder with PDFs.")
parser.add_argument( parser.add_argument(
"--csvquote", default='"', help="CSV quote char." + """Default: '"'""") "csv", help="Moodle grading sheet.")
parser.add_argument( parser.add_argument(
"--csvenc", default="utf-8", help="CSV encoding scheme. " + "outzip", help="Zip archive with feedback files.")
"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")
parser.add_argument( parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run.") "-d", "--dry", action='store_true', help="Flag for dry run.")
parser.add_argument( parser.add_argument(
"-t", "--tmp", default="./tmp", help="Temporary folder. Default:./tmp") "-t", "--tmp", default="./tmp", help="Temporary folder.")
parser.add_argument( parser.add_argument(
"--nowarn", action='store_true', help="Disables warnings") "--nowarn", action='store_true', help="Disables warnings.")
parser.add_argument( parser.add_argument(
"--moodlefilesize", default="250", "--moodleuploadlimit", default="250",
help="Moodle upload file size in MiB. 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 infolder = args.infolder
sheet_csv = args.csv sheet_csv = args.csv
outzip = args.outzip outzip = args.outzip
...@@ -181,7 +190,7 @@ def main(args): ...@@ -181,7 +190,7 @@ def main(args):
csv_delim = args.csvdelim csv_delim = args.csvdelim
csv_quote = args.csvquote csv_quote = args.csvquote
csv_enc = args.csvenc 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 # Print status
starttime = time.time() starttime = time.time()
...@@ -226,9 +235,9 @@ Processing {} students'''.format(num_students)) ...@@ -226,9 +235,9 @@ Processing {} students'''.format(num_students))
matnums_csv = [] matnums_csv = []
moodleids = [] moodleids = []
if no_warn: if no_warn:
print("Start processing", sep=' ', end='', flush=True) print("Start copying", sep=' ', end='', flush=True)
else: else:
print("Start processing") print("Start copying")
for cnt, info in enumerate(infos): for cnt, info in enumerate(infos):
# Copy PDF files # Copy PDF files
# Find all PDFs starting with matriculation number, e.g. # Find all PDFs starting with matriculation number, e.g.
...@@ -303,8 +312,7 @@ Processing {} students'''.format(num_students)) ...@@ -303,8 +312,7 @@ Processing {} students'''.format(num_students))
# Print status # Print status
endtime = time.time() endtime = time.time()
print("""Done. print("Time taken: {:.2f}".format(endtime-starttime))
Time taken: {:.2f}""".format(endtime-starttime))
# Main routine # 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 sys # get arguments from command line
import os # path listing/manipulation/... import os # path listing/manipulation/...
import time # keep track of time import time # keep track of time
...@@ -7,61 +22,58 @@ import shutil # unzipping and copying files ...@@ -7,61 +22,58 @@ import shutil # unzipping and copying files
from utils import moodle as moodle from utils import moodle as moodle
def main(args): def _make_parser():
"""Transfer PDF files from submisions zip file (or already extracted folder) csv_parser = moodle.get_moodle_csv_parser()
containing all submissions into user provided folder following exam scan
naming convention
1) Files are extracted from zip file location eg: ./all_submissions.zip parser = argparse.ArgumentParser(
In case folder is given, extraction is skipped. parents=[csv_parser],
2) Scan through extracted folder for PDF files. description=__doc__, prog='preparepdf.py',
Only 1 PDF file/student is accepted. formatter_class=argparse.ArgumentDefaultsHelpFormatter)
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
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( parser.add_argument(
"-i", "--inzip", default="submissions.zip", "inzip", help="Input ZIP file or extracted folder.")
help="Input zip file or already extracted folder. " + parser.add_argument(
"Default: ./submissions.zip") "csv", help="Moodle grading sheet.")
parser.add_argument( parser.add_argument(
"-o", "--outfolder", default="./pdfs", "outfolder", help="Output folder with PDFs.")
help="Output folder with PDFs. Default: ./pdfs")
parser.add_argument( parser.add_argument(
"--filenameformat", default="{matnum}_{fullname[0]}", "-f", "--filenameformat", default="{matnum}_{fullname[0]}",
help="File name format. Available keywords: " + help="File name format. Available keywords: " +
"{matnum}, {fullname}, {lastname}, {firstname}. " + "{matnum}, {fullname}, {lastname}, {firstname}. " +
"Default: '{matnum}_{fullname[0]}'") "Default: '{matnum}_{fullname[0]}'")
parser.add_argument( parser.add_argument(
"--copyall", action='store_true', "-c", "--copyall", action='store_true',
help="If set, copies all files (including multiple and non-PDF files)") help="If set, copies all files (including multiple and non-PDF files)")
parser.add_argument( 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") 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( parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run.") "-d", "--dry", action='store_true', help="Flag for dry run.")
parser.add_argument( 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 inzip = args.inzip
outfolder = args.outfolder outfolder = args.outfolder
sheet_csv = args.csv sheet_csv = args.csv
......
#!/usr/bin/env python #!/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 os
import time import time
import shutil # copyfile, make_archive import shutil # copyfile, make_archive
...@@ -11,49 +27,44 @@ import utils.matnum as matnum_utils ...@@ -11,49 +27,44 @@ import utils.matnum as matnum_utils
import utils.qr as qr_utils import utils.qr as qr_utils
def main(args): def _make_parser():
"""Main routine 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( parser.add_argument(
"-i", "--infolder", default="./pdfs_scan", "infolder", help="Input folder with PDFs.")
help="Input folder with PDFs. Default: ./pdfs_scan")
parser.add_argument( parser.add_argument(
"-o", "--outfolder", default="./pdfs", "csv", help="Moodle grading sheet.")
help="Output folder with renamed scans. Default: ./pdfs") parser.add_argument(
"outfolder", help="Output folder with renamed scans.")
parser.add_argument( parser.add_argument(
"--filenameformat", default="{matnum}_{fullname[0]}", "--filenameformat", default="{matnum}_{fullname[0]}",
help="File name format. Available keywords: " + help="File name format. Available keywords: " +
"{matnum}, {fullname}, {lastname}, {firstname}. " + "{matnum}, {fullname}, {lastname}, {firstname}. " +
"Default: '{matnum}_{fullname[0]}'") "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( parser.add_argument(
"-q", "--checkqr", action='store_true', "-q", "--checkqr", action='store_true',
help="Flag for additional QR code match.") help="Flag for additional QR code match.")
parser.add_argument( parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run.") "-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 infolder = args.infolder
sheet_csv = args.csv sheet_csv = args.csv
outfolder = args.outfolder outfolder = args.outfolder
...@@ -151,8 +162,7 @@ def main(args): ...@@ -151,8 +162,7 @@ def main(args):
# Print time # Print time
endtime = time.time() endtime = time.time()
print("""Done. print("Time taken: {:.2f}".format(endtime-starttime))
Time taken: {:.2f}""".format(endtime-starttime))
# Main routine # Main routine
......
...@@ -3,11 +3,18 @@ ...@@ -3,11 +3,18 @@
"""Prepare supplement material """Prepare supplement material
This script copies and renames supplementary material (such as exam sheet or 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 This information is either taken from the filenames of exam scan PDFs or from
the Moodle grading CSV file. 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 sys # get arguments from command line
import os # path listing/manipulation/... import os # path listing/manipulation/...
import time # keep track of time import time # keep track of time
...@@ -71,44 +78,44 @@ def copy_supplements(supp_dir, supp_files, prefixes, output_dir, dry=False): ...@@ -71,44 +78,44 @@ def copy_supplements(supp_dir, supp_files, prefixes, output_dir, dry=False):
return copied_files return copied_files
def main(args): def _make_parser():
"""Main function 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( parser.add_argument(
"-i", "--infolder", default="./supplements", "infolder", help="Folder with supplements.")
help="Folder with supplements. Default: ./supplements")
parser.add_argument( parser.add_argument(
"-p", "--prefix", default="./pdfs", "prefix", help="Provides information to construct prefixes. Either " +
help="Provides information to construct prefixes. Either PDF folder " + "folder with scanned PDFs or Moodle grading CSV file.")
"with scanned PDFs or Moodle grading CSV file. Default: ./pdfs")
parser.add_argument( parser.add_argument(
"-o", "--outfolder", default="./supplements_out", "outfolder",
help="Output folder. Default: ./supplements_out") help="Output folder with supplements per student.")
parser.add_argument( parser.add_argument(
"--filenameformat", default="{matnum}_{fullname[0]}", "--filenameformat", default="{matnum}_{fullname[0]}",
help="File name format. Available keywords: " + help="File name format. Available keywords: " +
"{{matnum}}, {{fullname}}, {{lastname}}, {{firstname}}. " + "{{matnum}}, {{fullname}}, {{lastname}}, {{firstname}}. " +
"Default: '{{matnum}}_{{fullname[0]}}'") "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( parser.add_argument(
"-d", "--dry", action='store_true', help="Flag for dry run") "-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 supp_dir = args.infolder
prefixinfo = args.prefix prefixinfo = args.prefix
prefixformat = args.filenameformat 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