Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .locks import lock_function
from .xls import XLSDictReader

__all__ = ['lock_function', 'XLSDictReader']
19 changes: 19 additions & 0 deletions app/utils/locks.py
Original file line number Diff line number Diff line change
@@ -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
19 changes: 1 addition & 18 deletions app/utils.py → app/utils/xls.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down