def projectNameFromPath(p): sConfPkg = os.environ.get("DAVOS_CONF_PACKAGE", "davos.config") pkg = importModule(sConfPkg) sPkgDirPath = os.path.dirname(pkg.__file__) sDirList = pathSplitDirs(p) for sFilename in os.listdir(sPkgDirPath): bIgnored = False for sPatrn in ("__*", ".*", "*.pyc"): if fnmatch(sFilename, sPatrn): bIgnored = True break if bIgnored: continue sModName = os.path.splitext(sFilename)[0] m = importModule(sConfPkg + "." + sModName) sProjDir = m.project.dir_name if sProjDir in sDirList: return sModName return ""
def getConfigModule(sProjectName): try: sConfPkg = os.environ.get("DAVOS_CONF_PACKAGE", "davos.config") sConfigModule = sConfPkg + "." + sProjectName modobj = importModule(sConfigModule) except ImportError: raise ImportError("No config module named '{}'".format(sConfigModule)) return modobj