Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
RWTHmoodle
exam-scan
Commits
b50f1b7a
Commit
b50f1b7a
authored
Apr 26, 2021
by
Christian Rohlfing
Browse files
Minor changes for dryout
parent
2bad1059
Changes
3
Hide whitespace changes
Inline
Side-by-side
preparemoodle.py
View file @
b50f1b7a
...
...
@@ -93,13 +93,12 @@ def main(args):
csv_enc
=
csv_enc
)
print
(
'''Preparing for moodle upload
Processing {} students
'''
.
format
(
num_students
))
Processing {} students'''
.
format
(
num_students
))
# Clean up and create temporary folder
dryout
=
""
dryout
=
[]
if
dry
:
print
(
"Dry run
\n
"
)
print
(
"Dry run"
)
else
:
# Remove zip file
if
os
.
path
.
exists
(
outzip
):
...
...
@@ -129,6 +128,10 @@ Processing {} students
num_found_pdfs
=
0
matnums_csv
=
[]
moodleids
=
[]
if
no_warn
:
print
(
"Start processing"
,
sep
=
' '
,
end
=
''
,
flush
=
True
)
else
:
print
(
"Start processing"
)
for
cnt
,
info
in
enumerate
(
infos
):
# Copy PDF files
# Find all PDFs starting with matriculation number, e.g.
...
...
@@ -161,20 +164,23 @@ Processing {} students
if
not
dry
:
shutil
.
copyfile
(
longpdffile
,
longpdffiledest
)
else
:
dryout
+=
"
\n
{}"
.
format
(
os
.
path
.
join
(
folder
,
pdffile
))
dryout
.
append
(
"- {old} -> {new}"
.
format
(
old
=
pdffile
,
new
=
os
.
path
.
join
(
folder
,
pdffile
)))
elif
not
no_warn
:
# No PDF found
print
(
"Warning: PDF for {matnum} (id={id}, name={name}) not found."
.
format
(
matnum
=
matnum
,
id
=
moodleid
,
name
=
info
[
'fullname'
]))
# Print for-loop progress
if
not
(
cnt
%
max
(
1
,
round
(
num_students
/
10
))):
if
no_warn
and
not
(
cnt
%
max
(
1
,
round
(
num_students
/
10
))):
print
(
"."
,
sep
=
' '
,
end
=
''
,
flush
=
True
)
# Print results
print
(
"done."
)
print
(
"Found {num_pdf} PDFs (CSV had {num_csv} entries)"
.
format
(
num_pdf
=
num_found_pdfs
,
num_csv
=
num_students
))
print
(
"done."
)
# Sanity check:
# Check for PDFs not reflected in CSV (student not registered in Moodle)
...
...
@@ -192,7 +198,8 @@ Processing {} students
# Print dry run results
else
:
print
(
"
\n
Dry run results:
\n
{}"
.
format
(
dryout
))
dryout
.
sort
()
print
(
"
\n
Dry run results:
\n
{}"
.
format
(
"
\n
"
.
join
(
dryout
)))
# Print status
endtime
=
time
.
time
()
...
...
preparepdf.py
View file @
b50f1b7a
...
...
@@ -183,8 +183,8 @@ Processing {} students
shutil
.
copyfile
(
file_full
,
dest_full
)
else
:
dryout
.
append
(
"- {} -> {}"
.
format
(
os
.
path
.
join
(
folder
,
file
),
dest
))
"- {
old
} -> {
new
}"
.
format
(
old
=
os
.
path
.
join
(
folder
,
file
),
new
=
dest
))
else
:
# Notify if folder was not found
infos_no_submission
.
append
(
info
)
...
...
supplements.py
View file @
b50f1b7a
...
...
@@ -51,7 +51,9 @@ def copy_supplements(supp_dir, supp_files, prefixes, output_dir, dry=False):
if
not
dry
:
shutil
.
copyfile
(
supp_filefull
,
new_filefull
)
else
:
dryout
.
append
(
new_file
)
dryout
.
append
(
"- {old} -> {new}"
.
format
(
old
=
supp_file
,
new
=
new_file
))
copied_files
.
append
(
new_file
)
# Print progress
...
...
@@ -95,6 +97,14 @@ def main(args):
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"
)
...
...
@@ -103,6 +113,9 @@ def main(args):
prefixinfo
=
args
.
prefix
prefixformat
=
args
.
filenameformat
output_dir
=
args
.
outfolder
csv_enc
=
args
.
csvenc
csv_delim
=
args
.
csvdelim
csv_quote
=
args
.
csvquote
dry
=
args
.
dry
# Decide whether PDF folder or CSV file was given
...
...
@@ -143,7 +156,8 @@ Files in output folder {} will be overwritten during this process.
prefixes
.
append
(
prefix
)
else
:
# Take prefixes from CSV file
prefixes
=
[]
infos
=
moodle
.
extract_info
(
csvfilename
)
infos
=
moodle
.
extract_info
(
sheet_csv
=
csvfilename
,
csv_delim
=
csv_delim
,
csv_quote
=
csv_quote
,
csv_enc
=
csv_enc
)
for
info
in
infos
:
prefix
=
prefixformat
.
format
(
matnum
=
info
[
'matnum'
],
fullname
=
info
[
'fullname'
],
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment