added num columns option
This commit is contained in:
@@ -13,6 +13,7 @@ from app.pdf import make_pdf
|
||||
@click.option("--silent", default=False, is_flag=True)
|
||||
@click.option("--include-answers", default=True, is_flag=True)
|
||||
@click.option("--output-filepath")
|
||||
@click.option("--num-columns", default=4)
|
||||
def main(
|
||||
bits: int,
|
||||
num_problems: int,
|
||||
@@ -20,6 +21,7 @@ def main(
|
||||
silent: bool = False,
|
||||
include_answers: bool = True,
|
||||
output_filepath: str = None,
|
||||
num_columns: int = 4,
|
||||
) -> None:
|
||||
|
||||
validate_args(pdf, silent, output_filepath)
|
||||
@@ -32,6 +34,7 @@ def main(
|
||||
answers=answers,
|
||||
output_path=output_filepath or "problems.pdf",
|
||||
include_answers=include_answers,
|
||||
num_columns=num_columns,
|
||||
)
|
||||
|
||||
if not silent:
|
||||
|
||||
12
app/pdf.py
12
app/pdf.py
@@ -6,7 +6,11 @@ POSTSCRIPT_FILEPATH = "tempfile.ps"
|
||||
|
||||
|
||||
def make_pdf(
|
||||
problems: str, answers: str, output_path: str, include_answers: bool
|
||||
problems: str,
|
||||
answers: str,
|
||||
output_path: str,
|
||||
include_answers: bool,
|
||||
num_columns: int,
|
||||
) -> None:
|
||||
if include_answers:
|
||||
pdf_jobs = (("problems", problems), ("answers", answers))
|
||||
@@ -18,7 +22,7 @@ def make_pdf(
|
||||
output_path = make_answers_path(output_path)
|
||||
with tempfile.NamedTemporaryFile(mode="w") as txt_file:
|
||||
write_to_txtfile(txt_file, text)
|
||||
make_postscript_file(txt_file)
|
||||
make_postscript_file(txt_file, num_columns)
|
||||
make_pdf_file(output_path)
|
||||
os.unlink(POSTSCRIPT_FILEPATH)
|
||||
|
||||
@@ -39,6 +43,6 @@ def make_pdf_file(output_path):
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
|
||||
def make_postscript_file(txt_file):
|
||||
command = f"enscript --columns=4 --no-header --output={POSTSCRIPT_FILEPATH} {txt_file.name}"
|
||||
def make_postscript_file(txt_file, num_columns):
|
||||
command = f"enscript --columns={num_columns} --no-header --output={POSTSCRIPT_FILEPATH} {txt_file.name}"
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
Reference in New Issue
Block a user