From b737281a5dc4206f068ec575b10d218237d772c4 Mon Sep 17 00:00:00 2001 From: Benjamin Chrobot Date: Mon, 3 Feb 2020 08:32:29 -0500 Subject: [PATCH] refactor: create proper utils module --- app/utils/__init__.py | 4 ++++ app/utils/locks.py | 19 +++++++++++++++++++ app/{utils.py => utils/xls.py} | 19 +------------------ 3 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 app/utils/__init__.py create mode 100644 app/utils/locks.py rename app/{utils.py => utils/xls.py} (67%) diff --git a/app/utils/__init__.py b/app/utils/__init__.py new file mode 100644 index 00000000..97fa7996 --- /dev/null +++ b/app/utils/__init__.py @@ -0,0 +1,4 @@ +from .locks import lock_function +from .xls import XLSDictReader + +__all__ = ['lock_function', 'XLSDictReader'] diff --git a/app/utils/locks.py b/app/utils/locks.py new file mode 100644 index 00000000..1f83e1da --- /dev/null +++ b/app/utils/locks.py @@ -0,0 +1,19 @@ +"""Utilities for managing locks.""" + +from functools import wraps + + +def lock_function(lock): + """Lock a function but always release that lock.""" + def decorator(func): + """Lock a function but always release that lock.""" + @wraps(func) + def wrapper(*args, **kwargs): + """Lock a function but always release that lock.""" + try: + lock.acquire() + return func(*args, **kwargs) + finally: + lock.release() + return wrapper + return decorator diff --git a/app/utils.py b/app/utils/xls.py similarity index 67% rename from app/utils.py rename to app/utils/xls.py index 52914b3e..89704d66 100644 --- a/app/utils.py +++ b/app/utils/xls.py @@ -1,27 +1,10 @@ -"""Utilities for the entire app.""" +"""Excel utilities.""" from collections import OrderedDict -from functools import wraps import xlrd -def lock_function(lock): - """Lock a function but always release that lock.""" - def decorator(func): - """Lock a function but always release that lock.""" - @wraps(func) - def wrapper(*args, **kwargs): - """Lock a function but always release that lock.""" - try: - lock.acquire() - return func(*args, **kwargs) - finally: - lock.release() - return wrapper - return decorator - - class XLSDictReader: # pylint: disable=too-few-public-methods """ A csv.DictReader-like class from xls(x) files.