Commit f603120f authored by Deb's avatar Deb
Browse files

empty input folder handling

parent cb873c5b
Pipeline #461047 passed with stages
in 4 minutes and 21 seconds
......@@ -158,6 +158,12 @@ For more info on the scripts and additional arguments refer to the [Documentatio
You can do all the above processes with one single scripts as follows:
Online Submissions:
```bash
python batch.py ./tests/assets/pdfs ./tests/assets/Grades.csv ./tests/assets/out --cores 2 --password ganzgeheim --suppinfolder ./tests/assets/supplements --supp --zip ./tests/assets/submissions.zip
```
Scanned Exams:
```bash
python batch.py ./tests/assets/pdfs ./tests/assets/Grades.csv ./tests/assets/out --cores 2 --password ganzgeheim --suppinfolder ./tests/assets/supplements --supp
```
......
......@@ -77,15 +77,12 @@ def main(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:
password_file = args.passwordout
# List all PDFs
# Check folder and list pdfs
starttime = time.time()
pdf_folder = os.listdir(infolder)
pdf_files = [_ for _ in pdf_folder
......@@ -102,6 +99,10 @@ Files in output folder {} will be overwritten during this process.
There are no PDFs in the given directory.
Exiting now.""")
return
if not os.path.exists(outfolder):
os.makedirs(outfolder)
# Encrypt all PDFs in input folder
csv_lines = []
enc_files = []
......
......@@ -112,21 +112,45 @@ Processing {} students
raise Exception(
"{zip} neither Zip file nor folder. Exiting."
.format(zip=inzip))
else:
inzip_folder = os.listdir(inzip)
inzip_files = [_ for _ in inzip_folder if _.lower().endswith(".zip")]
if len(inzip_files) > 0:
print("""
Available submission file(s) to be unzipped and renamed:
- {}
Files in output folder {} will be overwritten during this process.
""".format("\n- ".join(inzip_files), outfolder))
else:
print("""
There are no zip files in the given directory.
Exiting now.""")
return
# Folder was given instead of Zip file
extracted_folder = inzip
folder_instead_of_zip = True
else:
# Extract
print("Extracting files from {zip} ...".format(zip=inzip))
if not dry:
shutil.unpack_archive(inzip, extracted_folder) # unzip file
if os.path.isfile(inzip):
print("Extracting files from {zip} ...".format(zip=inzip))
if not dry:
shutil.unpack_archive(inzip, extracted_folder) # unzip file
else:
raise Exception("Dry run prevents me from unpacking the Zip file.")
else:
raise Exception("Dry run prevents me from unpacking the Zip file.")
print("""
There are no zip files in the given directory.
Exiting now.""")
return
# List all extracted folders
print('Extracted folde '+extracted_folder)
folders = os.listdir(extracted_folder)
folders.sort()
print(len(folders))
# There should never be more folders than entries in CSV file
if len(folders) > num_students:
......
......@@ -192,13 +192,29 @@ def main(args):
csv_enc = args.csvenc
size_limit = int(args.moodleuploadlimit) # Moodle upload size limit in MiB
starttime = time.time()
# Check folders
zip_dir, _ = os.path.split(outzip)
if zip_dir and not os.path.exists(zip_dir):
os.makedirs(zip_dir)
pdf_folder = os.listdir(infolder)
pdf_files = [
_ for _ in pdf_folder
if _.lower().endswith(".pdf") and matnum_utils.starts_with_matnum(_)]
if len(pdf_files) > 0:
print("""
Available PDFs to be zipped:
- {}
""".format("\n- ".join(pdf_files)))
else:
print("""
There are no PDFs in the given directory.
Exiting now.""")
return
# Print status
starttime = time.time()
num_students = moodle.get_student_number(sheet_csv=sheet_csv,
csv_enc=csv_enc)
......
......@@ -90,6 +90,20 @@ def main(args):
pdf_folder = os.listdir(infolder)
pdf_files = [_ for _ in pdf_folder
if _.lower().endswith(".pdf")]
if len(pdf_files) > 0:
print("""
Available scans to be renamed:
- {}
Files in output folder {} will be overwritten during this process.
""".format("\n- ".join(pdf_files), outfolder))
else:
print("""
There are no PDFs in the given directory.
Exiting now.""")
return
# Sort list alphabetically
# Most scanners are putting timestamps in the file names
# This information is more important than the OS time stamp
......
......@@ -125,6 +125,7 @@ def main(args):
csv_quote = args.csvquote
dry = args.dry
starttime = time.time()
# Check folders
if not os.path.exists(output_dir):
os.makedirs(output_dir)
......@@ -144,15 +145,21 @@ def main(args):
raise Exception("{} neither CSV file nor folder.".format(prefixinfo))
# Print status
starttime = time.time()
supp_folder = os.listdir(supp_dir)
supp_files = [_ for _ in supp_folder if _.lower().endswith(".pdf")]
print("""
if len(supp_files) > 0:
print("""
Available supplement PDFs to be copied:
- {}
Files in output folder {} will be overwritten during this process.
""".format("\n- ".join(supp_files), output_dir))
else:
print("""
There are no PDFs in the given directory.
Exiting now.""")
return
# Create prefixes
print(pdf_dir)
......
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