Exemple #1
0
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 = []
Exemple #2
0
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="/">&#8226;</a>&nbsp;&nbsp;<a>path1</a>&nbsp;&nbsp;<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="/">&#8226;</a>&nbsp;&nbsp;'
		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>&nbsp;&nbsp;&#8227;&nbsp;&nbsp;' % ( lastpath, p )
				else:
					html += '<a>%s</a>&nbsp;&nbsp;' % ( 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)
Exemple #4
0
	def get_descriptor(title):
		fullpath = os.path.join(path, title)
		return { 'title': title, 'type': tools.get_type(contrib.get_full_path(document_root, fullpath)) }
Exemple #5
0
	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)