Switch to unified view

a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
...
...
31
from collections import defaultdict
31
from collections import defaultdict
32
32
33
import tg
33
import tg
34
import genshi.template
34
import genshi.template
35
import chardet
35
import chardet
36
import pkg_resources
36
from formencode.validators import FancyValidator
37
from formencode.validators import FancyValidator
37
from dateutil.parser import parse
38
from dateutil.parser import parse
38
from bson import ObjectId
39
from bson import ObjectId
40
from paste.deploy import appconfig
39
from pymongo.errors import InvalidId
41
from pymongo.errors import InvalidId
40
from contextlib import contextmanager
42
from contextlib import contextmanager
41
from pylons import tmpl_context as c, app_globals as g
43
from pylons import tmpl_context as c, app_globals as g
42
from pylons import response, request
44
from pylons import response, request
43
from tg.decorators import before_validate
45
from tg.decorators import before_validate
...
...
789
        del graph[root]
791
        del graph[root]
790
    if len(graph) > 0:
792
    if len(graph) > 0:
791
        # There is a loop in the input.
793
        # There is a loop in the input.
792
        return None
794
        return None
793
    return sorted
795
    return sorted
796
797
798
@contextmanager
799
def ming_config(**conf):
800
    """Temporarily swap in a new ming configuration, restoring the previous
801
    one when the contextmanager exits.
802
803
    :param \*\*conf: keyword arguments defining the new ming configuration
804
805
    """
806
    import ming
807
    from ming.session import Session
808
    datastores = Session._datastores
809
    try:
810
        ming.configure(**conf)
811
        yield
812
    finally:
813
        Session._datastores = datastores
814
        for name, session in Session._registry.iteritems():
815
            session.bind = datastores.get(name, None)
816
            session._name = name
817
818
819
@contextmanager
820
def ming_config_from_ini(ini_path):
821
    """Temporarily swap in a new ming configuration, restoring the previous
822
    one when the contextmanager exits.
823
824
    :param ini_path: Path to ini file containing the ming configuration
825
826
    """
827
    root = pkg_resources.get_distribution('allura').location
828
    conf = appconfig('config:%s' % os.path.join(root, ini_path))
829
    with ming_config(**conf):
830
        yield