From d28d7728a703da687d251480e0a530218940a370 Mon Sep 17 00:00:00 2001 From: Mathis Vinay Date: Wed, 22 Mar 2023 16:28:21 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20typos=20corrections,=20quotes=20&?= =?UTF-8?q?=20other=20syntax=20problems?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + API/utils.py | 32 ++++++++++++++++---------------- Dockerfile | 2 +- app.py | 2 +- lotemplate/__init__.py | 2 +- lotemplate/classes.py | 4 ++-- lotemplate/utils.py | 2 +- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 042b100..f47acad 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ uploads/ .~lock.*# exports/ /config* +/output*.* diff --git a/API/utils.py b/API/utils.py index 6aecd64..4c727a5 100644 --- a/API/utils.py +++ b/API/utils.py @@ -35,7 +35,7 @@ def restart_soffice() -> None: :return: None """ - clean_tempfiles() + clean_temp_files() subprocess.call( f'soffice "--accept=socket,host={cnx.host},port={cnx.port};urp;StarOffice.ServiceManager" &', shell=True @@ -47,7 +47,7 @@ def restart_soffice() -> None: pass -def clean_tempfiles(): +def clean_temp_files(): """ Deletes all the temporary files created @@ -86,7 +86,7 @@ def delete_file(directory: str, name: str) -> None: def error_format(exception: Exception, message: str = None) -> dict: """ - put all informations about an error in a dictionary for better error handling when using the API. + put all information about an error in a dictionary for better error handling when using the API. You can also overwrite the provided error message :param exception: the exception to format @@ -107,7 +107,7 @@ def error_format(exception: Exception, message: str = None) -> dict: def error_sim(exception: str, code: str, message: str, variables=dict({})) -> dict: """ - Simulate an error catch, ans return a error-formatted dict in the same way as error_format does + Simulate an error catch, and return an error-formatted dict in the same way as error_format does :param exception: the exception name :param code: the exception id @@ -119,14 +119,14 @@ def error_sim(exception: str, code: str, message: str, variables=dict({})) -> di return {'error': exception, 'code': code, 'message': message, 'variables': variables} -def save_file(directory: str, f, name: str, error_catched=False) -> Union[tuple[dict, int], dict]: +def save_file(directory: str, f, name: str, error_caught=False) -> Union[tuple[dict, int], dict]: """ upload a template file, and scan it. :param f: the file to save :param directory: the directory of the file :param name: the name of the file - :param error_catched: specify if an error has been catched + :param error_caught: specify if an error has been caught :return: a json, with the filename under which it was saved (key 'file'), and the scanned variables present in the template (key 'variables') """ @@ -152,7 +152,7 @@ def save_file(directory: str, f, name: str, error_catched=False) -> Union[tuple[ except ot.errors.UnoException as e: delete_file(directory, name) restart_soffice() - if error_catched: + if error_caught: return ( error_format(e, "Internal server error on file opening. Please checks the README file, section " "'Unsolvable problems' for more informations."), @@ -166,14 +166,14 @@ def save_file(directory: str, f, name: str, error_catched=False) -> Union[tuple[ return {'file': name, 'message': "Successfully uploaded", 'variables': values} -def scan_file(directory: str, file: str, error_catched=False) -> Union[tuple[dict, int], dict]: +def scan_file(directory: str, file: str, error_caught=False) -> Union[tuple[dict, int], dict]: """ scans the specified file :param directory: the directory where the file is :param file: the file to scan - :param error_catched: specify if an error was already catched - :return: a json and optionaly an int which represent the status code to return + :param error_caught: specify if an error was already caught + :return: a json and optionally an int which represent the status code to return """ try: @@ -181,7 +181,7 @@ def scan_file(directory: str, file: str, error_catched=False) -> Union[tuple[dic variables = temp.variables except ot.errors.UnoException as e: restart_soffice() - if error_catched: + if error_caught: return ( error_format(e, "Internal server error on file opening. Please checks the README file, section " "'Unsolvable problems' for more informations."), @@ -192,15 +192,15 @@ def scan_file(directory: str, file: str, error_catched=False) -> Union[tuple[dic return {'file': file, 'message': "Successfully scanned", 'variables': variables} -def fill_file(directory: str, file: str, json, error_catched=False) -> Union[tuple[dict, int], dict, Response]: +def fill_file(directory: str, file: str, json, error_caught=False) -> Union[tuple[dict, int], dict, Response]: """ fill the specified file :param directory: the directory where the file is :param file: the file to fill :param json: the json to fill the document with - :param error_catched: specify if an error was already catched - :return: a json and optionaly an int which represent the status code to return + :param error_caught: specify if an error was already caught + :return: a json and optionally an int which represent the status code to return """ if type(json) != list or not json: @@ -239,7 +239,7 @@ def fill_file(directory: str, file: str, json, error_catched=False) -> Union[tup return send_file('exports/export.zip', 'export.zip') except ot.errors.UnoException as e: restart_soffice() - if error_catched: + if error_caught: return ( error_format(e, "Internal server error on file opening. Please checks the README file, section " "'Unsolvable problems' for more informations."), @@ -249,4 +249,4 @@ def fill_file(directory: str, file: str, json, error_catched=False) -> Union[tup return fill_file(directory, file, json, True) -clean_tempfiles() +clean_temp_files() diff --git a/Dockerfile b/Dockerfile index fce9b33..4e38187 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,6 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt,sharing=locked \ && useradd -d /app python COPY . /app WORKDIR /app -Run chown python /app -R \ +RUN chown python /app -R \ && pip install -r requirements.txt USER python diff --git a/app.py b/app.py index 8938d2b..8bcba8b 100644 --- a/app.py +++ b/app.py @@ -75,7 +75,7 @@ def directory_route(directory): os.rename(f"uploads/{directory}", f"uploads/{new_name}") return {'directory': new_name, 'old_directory': directory, - "message": f"directory {directory} sucessfully renamed in {new_name}"} + "message": f"directory {directory} successfully renamed in {new_name}"} @app.route("//", methods=['GET', 'PATCH', 'DELETE', 'POST']) diff --git a/lotemplate/__init__.py b/lotemplate/__init__.py index 92fff8f..dfcfdc7 100644 --- a/lotemplate/__init__.py +++ b/lotemplate/__init__.py @@ -5,7 +5,7 @@ LOTemplate Filler ~~~~~~~~~~~~~~~~~ -A module for manipulate and fill libreoffice writter-like documents with given variables +A module for manipulate and fill libreoffice writer-like documents with given variables Contains the two used classes, errors raised and some utils fonctions """ diff --git a/lotemplate/classes.py b/lotemplate/classes.py index a46c196..d2f2231 100644 --- a/lotemplate/classes.py +++ b/lotemplate/classes.py @@ -137,7 +137,7 @@ def __init__(self, file_path: str, cnx: Connexion, should_scan: bool): self.close() raise errors.UnoException( 'connection_closed', - f"The previously etablished connection with the soffice process on '{self.cnx.host}:{self.cnx.port}' " + f"The previously established connection with the soffice process on '{self.cnx.host}:{self.cnx.port}' " f"has been closed, or ran into an unknown error. Please restart the soffice process, and retry.", dict_of(cnx.host, cnx.port) ) from e @@ -445,7 +445,7 @@ def tables_fill(doc, text_prefix: str, table_prefix: str) -> None: except RuntimeException as e: raise errors.UnoException( 'connection_closed', - f"The previously etablished connection with the soffice process on " + f"The previously established connection with the soffice process on " f"'{self.cnx.host}:{self.cnx.port}' has been closed, or ran into an unknown error. " f"Please restart the soffice process, and retry.", dict_of(self.cnx.host, self.cnx.port) diff --git a/lotemplate/utils.py b/lotemplate/utils.py index 6786d0b..e7b64dc 100644 --- a/lotemplate/utils.py +++ b/lotemplate/utils.py @@ -77,7 +77,7 @@ def get_type(obj, **kwargs) -> str: def check_type(f): """ - A decorator that checks if the arguments are of the right type, following typeints of the function + A decorator that checks if the arguments are of the right type, following typehints of the function :param f: the function to wraps :return: the wrapper