From 0c4220d84808097795e7db4781be100504ce1353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Tue, 26 Dec 2023 18:47:53 -0500 Subject: [PATCH] =?UTF-8?q?Mots=20crois=C3=A9s=20fonctionnel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 0 crossword_generator.py | 5 ++--- file_ops.py | 13 ++++++++----- grid_generator.py | 4 +++- 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 __init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/crossword_generator.py b/crossword_generator.py index 693ab1d..f36bdc6 100755 --- a/crossword_generator.py +++ b/crossword_generator.py @@ -10,9 +10,8 @@ paper, if you're one of those people. import argparse # Custom imports -import file_ops -import grid_generator -from grid_generator import GridGenerator +import crossword_generator.file_ops as file_ops +from crossword_generator.grid_generator import GridGenerator def parse_cmdline_args(): diff --git a/file_ops.py b/file_ops.py index 895e898..dc50f8b 100644 --- a/file_ops.py +++ b/file_ops.py @@ -1,4 +1,5 @@ import os +import pathlib import pprint import shutil import subprocess @@ -23,7 +24,7 @@ def read_word_list(filename, min_length=2, min_different_letters=2): return words -def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=True, words=[]): +def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=True, words=None): """ This function receives the generated grid and writes it to the file (or to the screen, if that's what we want). The grid is expected to be a list of lists, as used by the remaining functions. @@ -32,6 +33,8 @@ def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=T is printed as such. """ # Print grid to the file and compile + if words is None: + words = [] with open(out_file, "w") as texfile: # Write preamble texfile.write("\documentclass[a4paper]{article}" + "\n") @@ -123,13 +126,13 @@ def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=T print("\n=== Compiling the generated latex file! ===") with tempfile.TemporaryDirectory() as tmpdir: # Save current directory - original_dir = os.getcwd() + original_dir = pathlib.Path(os.getcwd()) # Copy the latex source to the temporary directory shutil.copy(out_file, tmpdir) # Copy logo to the temporary directory - shutil.copy("logo.png", tmpdir) + shutil.copy("../crossword_generator/logo.png", tmpdir) # Move to the temp directory os.chdir(tmpdir) @@ -138,10 +141,10 @@ def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=T os.rename(out_file, "out.tex") # Compile - proc = subprocess.call(['pdflatex', "out.tex"]) + subprocess.call(['pdflatex', "out.tex"]) # Copy PDF back to the original directory - shutil.copy("out.pdf", original_dir+"/"+out_pdf) + shutil.copy("out.pdf", str(original_dir / out_pdf)) # Move back to the original directory os.chdir(original_dir) diff --git a/grid_generator.py b/grid_generator.py index 8ddb42d..e5b3231 100644 --- a/grid_generator.py +++ b/grid_generator.py @@ -1,8 +1,10 @@ -import basic_ops +import crossword_generator.basic_ops as basic_ops class GridGenerator: def __init__(self, word_list, dimensions, n_loops, timeout, target_occupancy): + self.words_in_grid = None + self.grid = None self.word_list = word_list self.dimensions = dimensions self.n_loops = n_loops