Aufgrund einer Wartung wird GitLab am 19.10. zwischen 8:00 und 9:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 19.10. between 8:00 and 9:00 am.

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
Batch
*****
.. toctree::
:maxdepth: 3
.. autoprogram:: batch:_parser
:prog: batch.py
API
===
.. automodule:: batch
:members:
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../../'))
# -- Project information -----------------------------------------------------
project = 'Exam Scan'
copyright = '2021, Amrita Deb, Christian Rohlfing'
author = 'Amrita Deb, Christian Rohlfing'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.napoleon',
]
extensions += ['sphinxcontrib.autoprogram']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_template.rst"]
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
Encrypt
*******
.. toctree::
:maxdepth: 3
.. autoprogram:: encrypt:_parser
:prog: encrypt.py
API
===
.. automodule:: encrypt
:members:
#!/usr/bin/env python
import os
def generateFiles(file_infos, template_path, out_dir):
""" insert figures into latex template
"""
with open(template_path, "r") as template_handle:
template_string = template_handle.read()
for file_info in file_infos:
file = file_info['file']
title = file_info['title']
line = '*'*len(title)
header = "{title}\n{line}".format(title=title, line=line)
s = template_string.replace("<file>", file)
s = s.replace("<header>", header)
out_file = "{file}.rst".format(file=file)
out_path = os.path.join(out_dir, out_file)
if os.path.exists(out_path):
print("Overwriting {file}."
.format(file=out_file))
with open(out_path, 'w') as out_handle:
out_handle.write(s)
print("Done.")
if __name__ == '__main__':
""" Main routine
"""
file_infos = [
{'file': 'watermark', 'title': 'Watermark'},
{'file': 'batch', 'title': 'Batch'},
{'file': 'encrypt', 'title': 'Encrypt'},
{'file': 'preparemoodle', 'title': 'Prepare Moodle'},
{'file': 'preparepdf', 'title': 'Prepare PDFs'},
{'file': 'renamescans', 'title': 'Rename Scans'},
{'file': 'supplements', 'title': 'Supplements'},
]
generateFiles(
file_infos=file_infos, template_path='./docs/source/_template.rst',
out_dir='./docs/source/')
Welcome to Exam Scan's documentation!
=====================================
.. toctree::
:maxdepth: 1
:caption: Contents:
encrypt
preparemoodle
preparepdf
renamescans
supplements
watermark
batch
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Prepare Moodle
**************
.. toctree::
:maxdepth: 3
.. autoprogram:: preparemoodle:_parser
:prog: preparemoodle.py
API
===
.. automodule:: preparemoodle
:members:
Prepare PDFs
************
.. toctree::
:maxdepth: 3
.. autoprogram:: preparepdf:_parser
:prog: preparepdf.py
API
===
.. automodule:: preparepdf
:members:
Rename Scans
************
.. toctree::
:maxdepth: 3
.. autoprogram:: renamescans:_parser
:prog: renamescans.py
API
===
.. automodule:: renamescans
:members:
sphinx>=3.5.4
sphinxcontrib-autoprogram>=0.1.7
\ No newline at end of file
Supplements
***********
.. toctree::
:maxdepth: 3
.. autoprogram:: supplements:_parser
:prog: supplements.py
API
===
.. automodule:: supplements
:members:
Watermark
*********
.. toctree::
:maxdepth: 3
.. autoprogram:: watermark:_parser
:prog: watermark.py
API
===
.. automodule:: watermark
:members:
......@@ -2,12 +2,16 @@
"""Creates encrypted copies of PDFs
This scripts creates encrypted copies of (watermarked) PDFs well as a CSV file
storing passwords for each file.
PDFs in input folder are encrypted and stored in output folder well as a CSV
file mapping passwords to each PDF.
Author: Amrita Deb <Deb@itc.rwth-aachen.de>
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 pikepdf
import os
import csv
......@@ -34,40 +38,48 @@ def encrypt(pdf_file, enc_file, password):
pdf.close()
def _make_parser():
parser = argparse.ArgumentParser(
description=__doc__, prog='encrypt.py',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
"infolder", help="Input folder of PDFs to be encrypted.")
parser.add_argument(
"outfolder", help="Output folder of encrypted PDFs.")
parser.add_argument(
"-p", "--password", default="",
help="Common password for all encrypted PDFs. " +
"Default='' results in generation of random passwords.")
parser.add_argument(
"--passwordout", default="",
help="Output path for CSV file. " +
"Default='' will be changed to [outfolder]/passwords.csv.")
return parser
# Create argument parser with default values
_parser = _make_parser()
def main(args):
"""Main function
1) Lists all PDFs to be encrypted from input folder
2) Encrypt pdf witn randomly generated 8 character long password
2) Encrypt pdf with randomly generated 8 character long password
3) Prepare a csv file that contains matriculation number and password
"""
# Argument handling
parser = argparse.ArgumentParser(description='''
PDFs in input folder are encrypted and stored in output folder.
Alongside with a CSV file mapping passwords to each PDF.
''')
parser.add_argument("-i", "--infolder", default="./pdfs_watermarked",
help="Input PDF folder. Default: ./pdfs_watermarked")
parser.add_argument("-o", "--outfolder", default="./pdfs_encrypted",
help="Output folder storing encrypted PDFs. " +
"Default: ./pdfs_encrypted")
parser.add_argument("-p", "--password", default="",
help="Common password for all encrypted PDFs. " +
"Default: '' " +
"results in generation of random passwords.")
parser.add_argument("-w", "--passwordout", default="",
help="Output path for CSV file. " +
"Default: '' will be changed to " +
"[outfolder]/passwords.csv.")
args = parser.parse_args(args)
args = _parser.parse_args(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:
......@@ -78,13 +90,18 @@ def main(args):
pdf_folder = os.listdir(infolder)
pdf_files = [_ for _ in pdf_folder
if _.lower().endswith(".pdf")]
print("""
if len(pdf_files) > 0:
print("""
Available PDFs to be encrypted:
- {}
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
# Encrypt all PDFs in input folder
csv_lines = []
enc_files = []
......
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