From 453d0372d9604d44a1ff74d0bc78c672b68f63aa Mon Sep 17 00:00:00 2001 From: arthurcerveira Date: Tue, 17 Mar 2020 17:03:01 -0300 Subject: [PATCH] Remove f-strings to become python3.4 compatible --- README.md | 2 +- email_function_logger/function_logger.py | 24 ++++++++++++++---------- setup.py | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c02982c..4e79551 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Total execution time: 00:00:00 ## Supported versions -- Python 3.6 and above +- Python 3.4 and above ## Lincense diff --git a/email_function_logger/function_logger.py b/email_function_logger/function_logger.py index c740de2..3a7580a 100644 --- a/email_function_logger/function_logger.py +++ b/email_function_logger/function_logger.py @@ -3,7 +3,7 @@ import io from datetime import datetime -from contextlib import redirect_stdout, redirect_stderr +from contextlib import redirect_stdout from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText @@ -21,14 +21,15 @@ def log_function(*args, **kwargs): arguments = get_function_arguments(args, kwargs) # Add subject to email - subject = f"Function '{function.__name__}' execution log" + subject = "Function '{}' execution log".format(function.__name__) message['Subject'] = subject # Start email body text - text = f"Function {function.__name__}({arguments}) finished its execution.\n\n" + text = "Function {}({}) finished its execution.\n\n".format( + function.__name__, arguments) start_time = datetime.now() - text += f"Start time: {start_time:%b %d %H:%M:%S}\n" + text += "Start time: {0:%b %d %H:%M:%S}\n".format(start_time) f = io.StringIO() with redirect_stdout(f): @@ -36,16 +37,19 @@ def log_function(*args, **kwargs): text_output = f.getvalue() - text += f'Function text output:\n{text_output}' if text_output else 'No text output\n' - text += f'Function returned: {return_value}\n' if return_value else 'No returned value\n' + text += 'Function text output:\n{}'.format( + text_output) if text_output else 'No text output\n' + text += 'Function returned: {}\n'.format( + return_value) if return_value else 'No returned value\n' end_time = datetime.now() - text += f"End time: {end_time:%b %d %H:%M:%S}\n" + text += "End time: {0:%b %d %H:%M:%S}\n".format(end_time) total = (end_time - start_time).seconds hours, remainder = divmod(total, 3600) minutes, seconds = divmod(remainder, 60) - text += f'\nTotal execution time: {hours:02d}:{minutes:02d}:{seconds:02d}\n' + text += '\nTotal execution time: {0:02d}:{1:02d}:{2:02d}\n'.format( + hours, minutes, seconds) # Add body to email message.attach(MIMEText(text, 'plain')) @@ -59,7 +63,7 @@ def log_function(*args, **kwargs): def get_email_info(): for var in ENVIRON_VAR: - yield os.environ.get(var) if os.environ.get(var) else input(f'{var}: ') + yield os.environ.get(var) if os.environ.get(var) else input('{}: '.format(var)) def authenticate_email(email, password): @@ -80,7 +84,7 @@ def create_message(email, recipient): def get_function_arguments(args, kwargs): args_repr = [repr(a) for a in args] - kwargs_repr = [f"{k}={v!r}" for k, v in kwargs.items()] + kwargs_repr = ["{0}={1!r}".format(k, v) for k, v in kwargs.items()] arguments = ", ".join(args_repr + kwargs_repr) return arguments diff --git a/setup.py b/setup.py index dd8a43a..cc97ed1 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="email-function-logger", - version="0.3", + version="0.4", author="Arthur Cerveira", author_email="aacerveira@inf.ufpel.edu.br", description="A decorator to log information about a function and send it to your email", @@ -20,5 +20,5 @@ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], - python_requires='>=3.6', + python_requires='>=3.4', )