def __init__(self, path, section='DEFAULT'): log.debug('initing global_settings by from %s, section:%s' % (path, section)) self.inifile = None for virtpath in contrib.get_virtual_paths().values(): if virtpath in path: self.inifile = os.path.join(virtpath, settings.GLOBAL_CONTEXT_FILE_NAME) self.section = section
def get_type(path): """ >>> get_type('C:\\\\none') 'none' >>> get_type(os.path.dirname(__file__)) 'folder' >>> get_type(__file__) 'test' >>> name = os.path.join(os.path.dirname(__file__), settings.TEST_CONTEXT_FILE_NAME) >>> f = open(name, 'w') >>> f.close() >>> get_type(os.path.dirname(__file__)) 'suite' >>> os.remove(name) """ if os.path.exists(path): if os.path.isdir(path): if os.path.exists(os.path.join(path, settings.TEST_CONTEXT_FILE_NAME)): return "suite" if path.rstrip("/").rstrip("\\") in contrib.get_virtual_paths().values(): return "virtual" return "folder" if ".ini" in path: return "configfile" if settings.SPEC_URL_FILE_NAME in path: return "specification" return "test" return "none"
def get_dir_index(document_root, path, fullpath): files = [] dirs = [] def get_descriptor(title): fullpath = os.path.join(path, title) return { 'title': title, 'type': tools.get_type(contrib.get_full_path(document_root, fullpath)) } if not document_root: pagetype = 'front-page' for key in contrib.get_virtual_paths(): dir_descriptor = get_descriptor(key) dirs.append(dir_descriptor) else: pagetype = tools.get_type(fullpath) for f in sorted(os.listdir(fullpath)): if not f.startswith('.'): if os.path.isfile(os.path.join(fullpath, f)): files.append(get_descriptor(f)) else: f += '/' dirs.append(get_descriptor(f)) try: if tools.get_type(fullpath) == 'virtual': contexts = context.global_settings(fullpath).sections() else: contexts = context.get(fullpath).sections() log.debug(contexts) except Exception, e: log.error(e) contexts = []