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 = []
def live_settings_json(request, content=None): settings_fullpath = get_virtual_paths_path() if not content: content = open(settings_fullpath, 'r').read() descriptor = { 'directory': '/settings', 'content': content, 'contexts': [], 'relative_file_path': 'settings', 'is_stubbed': False, 'favicon' : 'dir-index-test.gif', 'filetype': tools.get_type(settings_fullpath), } return descriptor
def breadcrumbs(path): """ >>> breadcrumbs('') '' >>> breadcrumbs('/') '' >>> breadcrumbs('/path1/') '<a href="/">•</a> <a>path1</a> <a href="//"><img height="11" src="/static/img/up.png" /></a>' """ path = path.replace('\\','/') document_root = contrib.get_document_root(path) fullpath = contrib.get_full_path(document_root, path) type = dir_index_tools.get_type(fullpath) if document_root and document_root != '/': html = '<a href="/">•</a> ' root = '/' lastpath = root i = 0 crumbs = path.rstrip('/').split('/') for p in crumbs: i += 1 if p: lastpath += p lastpath += '/' if i < len(crumbs): html += '<a href="%s">%s</a> ‣ ' % ( lastpath, p ) else: html += '<a>%s</a> ' % ( p ) if type != 'test': html += '<a href="%s%s"><img height="11" src="/static/img/up.png" /></a>' % (root, above(path)) else: html = '' return mark_safe(html)
def get_descriptor(title): fullpath = os.path.join(path, title) return { 'title': title, 'type': tools.get_type(contrib.get_full_path(document_root, fullpath)) }
try: contexts = context.get( fullpath ).sections() except Exception, e: log.exception(e) contexts = [] content = open(fullpath, 'rb').read() return { 'directory': path, 'content': content, 'contexts': contexts, 'relative_file_path': path, 'is_stubbed': stubbed, 'favicon' : 'dir-index-test.gif', 'filetype': tools.get_type(fullpath), 'spec' : get_spec(path, fullpath), } def get_spec(target, path): spec_url = spec.get_url(path) log.info('spec url: %s' % spec_url) if spec_url: return spec_url else: return '%s?editor' % settings.SPEC_URL_FILE_NAME def get_file_content(fullpath): log.debug('get content of %s' % fullpath) statobj = os.stat(fullpath) mimetype, encoding = mimetypes.guess_type(fullpath)