From acd71ca35023f7c8dd6ead1e30c53a974080bf93 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Tue, 7 Jun 2011 23:39:41 -0400 Subject: Refactoring path tricks into a function --- lib/d2/config/__init__.py | 6 +++--- lib/d2/util.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 lib/d2/util.py diff --git a/lib/d2/config/__init__.py b/lib/d2/config/__init__.py index 6fa1815..98fecfb 100644 --- a/lib/d2/config/__init__.py +++ b/lib/d2/config/__init__.py @@ -5,7 +5,7 @@ import logging import logging.handlers from collections import namedtuple from dodai import Configure -from d2.db import Base +from d2 import db, util try: from collections import OrderedDict except ImportError: @@ -30,7 +30,7 @@ class LdapConnector(object): def _set_certfile(self, sections): if 'certfile' in sections['ldap']: - certfile = os.path.expanduser(sections['ldap']['certfile']) + certfile = util.expand_path(sections['ldap']['certfile']) if os.path.exists(certfile): ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, certfile) @@ -103,7 +103,7 @@ class Config(object): # Set the schema on the db objects if any exist if ('schema' in self.sections['db'] and self.sections['db']['schema']): - for name, obj in Base.metadata.tables.items(): + for name, obj in db.Base.metadata.tables.items(): setattr(obj, 'schema', self.sections['db']['schema']) return self._db_ diff --git a/lib/d2/util.py b/lib/d2/util.py new file mode 100644 index 0000000..139ddc4 --- /dev/null +++ b/lib/d2/util.py @@ -0,0 +1,8 @@ +import os + + +def expand_path(path): + """Expand the user and shell variables in a path + """ + path = os.path.expanduser(path) + return os.path.expandvars(path) -- cgit v1.2.3