diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-27 18:25:04 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-27 18:25:04 -0400 |
commit | 7c8abd0076f780a382857b38f33f5cc2c52d6bd1 (patch) | |
tree | 102d882fcc40894c467a462ff017572c0adc7616 /alembic/util.py | |
parent | d4fea1d2e9c19a9b8da4a415c6d303b58e7360c9 (diff) | |
download | alembic-7c8abd0076f780a382857b38f33f5cc2c52d6bd1.tar.gz |
beginning to build the revision system
Diffstat (limited to 'alembic/util.py')
-rw-r--r-- | alembic/util.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/alembic/util.py b/alembic/util.py index 88085ee..df5bfd8 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -3,6 +3,7 @@ import sys import os import textwrap from sqlalchemy import util +import imp NO_VALUE = util.symbol("NO_VALUE") @@ -40,3 +41,25 @@ def msg(msg, newline=True): for line in lines[0:-1]: sys.stdout.write(" " +line + "\n") sys.stdout.write(" " + lines[-1] + ("\n" if newline else "")) + +def load_python_file(dir_, filename): + """Load a file from the given path as a Python module.""" + + module_id = re.sub(r'\W', "_", filename) + path = os.path.join(dir_, filename) + module = imp.load_source(module_id, path, open(path, 'rb')) + del sys.modules[module_id] + return module + +class memoized_property(object): + """A read-only @property that is only evaluated once.""" + def __init__(self, fget, doc=None): + self.fget = fget + self.__doc__ = doc or fget.__doc__ + self.__name__ = fget.__name__ + + def __get__(self, obj, cls): + if obj is None: + return None + obj.__dict__[self.__name__] = result = self.fget(obj) + return result |