diff --git a/pylons_app/lib/app_globals.py b/pylons_app/lib/app_globals.py --- a/pylons_app/lib/app_globals.py +++ b/pylons_app/lib/app_globals.py @@ -2,7 +2,10 @@ #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 +from mercurial import templater from mercurial.hgweb.request import wsgiapplication +from mercurial import ui, config +import os class Globals(object): """Globals acts as a container for objects available throughout the @@ -21,7 +24,40 @@ class Globals(object): #self.hgapp = self.make_web_app() self.hgapp = wsgiapplication(self.make_web_app) + def make_web_app(self): repos = "hgwebdir.config" - hgwebapp = hgwebdir(repos) + baseui = ui.ui() + cfg = config.config() + cfg.read(repos) + paths = cfg.items('paths') + self.check_repo_dir(paths) + self.set_statics(cfg) + + for k, v in cfg.items('web'): + baseui.setconfig('web', k, v) + #magic trick to make our custom template dir working + templater.path.append(cfg.get('web', 'templates', None)) + hgwebapp = hgwebdir(paths, baseui = baseui) return hgwebapp + + + 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]) +