##// END OF EJS Templates
added helper for filesize
added helper for filesize

File last commit:

r93:aec4c007 default
r97:be0096a0 default
Show More
app_globals.py
92 lines | 2.8 KiB | text/x-python | PythonLexer
Marcin Kuzminski
initial commit.
r0 """The application's Globals object"""
Marcin Kuzminski
major app speedup moved the wsgi creation to app globals, in order to make it run only once....
r10 #uncomment the following if you want to serve a single repo
#from mercurial.hgweb.hgweb_mod import hgweb
from mercurial.hgweb.hgwebdir_mod import hgwebdir
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 from mercurial import templater
Marcin Kuzminski
major app speedup moved the wsgi creation to app globals, in order to make it run only once....
r10 from mercurial.hgweb.request import wsgiapplication
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 from mercurial import ui, config
import os
changed for pylons 0.1 / 1.0...
r43 from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
Marcin Kuzminski
initial commit.
r0 class Globals(object):
"""Globals acts as a container for objects available throughout the
life of the application
"""
changed for pylons 0.1 / 1.0...
r43 def __init__(self, config):
Marcin Kuzminski
initial commit.
r0 """One instance of Globals is created during application
initialization and is available during requests via the
'app_globals' variable
"""
changed for pylons 0.1 / 1.0...
r43 self.cache = CacheManager(**parse_cache_config_options(config))
added empty controllers for branches tags files graph, routing and test for them
r93 self.baseui = self.make_ui('hgwebdir.config')
Marcin Kuzminski
major app speedup moved the wsgi creation to app globals, in order to make it run only once....
r10
added empty controllers for branches tags files graph, routing and test for them
r93 def make_ui(self, path='hgwebdir.config'):
"""
A funcion that will read python rc files and make an ui from read options
@param path: path to mercurial config file
"""
#propagated from mercurial documentation
sections = [
'alias',
'auth',
'decode/encode',
'defaults',
'diff',
'email',
'extensions',
'format',
'merge-patterns',
'merge-tools',
'hooks',
'http_proxy',
'smtp',
'patch',
'paths',
'profiling',
'server',
'trusted',
'ui',
'web',
]
repos = path
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 baseui = ui.ui()
cfg = config.config()
cfg.read(repos)
added empty controllers for branches tags files graph, routing and test for them
r93 self.paths = cfg.items('paths')
self.base_path = self.paths[0][1].replace('*', '')
self.check_repo_dir(self.paths)
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20 self.set_statics(cfg)
added empty controllers for branches tags files graph, routing and test for them
r93
for section in sections:
for k, v in cfg.items(section):
baseui.setconfig(section, k, v)
Marcin Kuzminski
Tempalting change, bugfix for serving raw files, and diffs. Now raw files are not parsed thruough mako, and diffs are mako safe (not parsed also)
r31
added empty controllers for branches tags files graph, routing and test for them
r93 return baseui
Marcin Kuzminski
Added custom templates, did over check of code to make it work....
r20
def set_statics(self, cfg):
'''
set's the statics for use in mako templates
@param cfg:
'''
self.statics = cfg.get('web', 'staticurl', '/static')
if not self.statics.endswith('/'):
self.statics += '/'
def check_repo_dir(self, paths):
repos_path = paths[0][1].split('/')
if repos_path[-1] in ['*', '**']:
repos_path = repos_path[:-1]
if repos_path[0] != '/':
repos_path[0] = '/'
if not os.path.isdir(os.path.join(*repos_path)):
raise Exception('Not a valid repository in %s' % paths[0][1])