comparison pylons_app/lib/app_globals.py @ 112:f7c403e89d5b

updated appglobals, to handle only the baseui config. removed hg app from it
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 28 Apr 2010 01:55:34 +0200
parents aec4c0071cb3
children b6e219f3a58d
comparison
equal deleted inserted replaced
111:70b1e5d1e20d 112:f7c403e89d5b
1 """The application's Globals object""" 1 """The application's Globals object"""
2 #uncomment the following if you want to serve a single repo 2 #uncomment the following if you want to serve a single repo
3 #from mercurial.hgweb.hgweb_mod import hgweb 3 #from mercurial.hgweb.hgweb_mod import hgweb
4 from mercurial.hgweb.hgwebdir_mod import hgwebdir
5 from mercurial import templater
6 from mercurial.hgweb.request import wsgiapplication
7 from mercurial import ui, config
8 import os 4 import os
9 from beaker.cache import CacheManager 5 from beaker.cache import CacheManager
10 from beaker.util import parse_cache_config_options 6 from beaker.util import parse_cache_config_options
7 from pylons_app.lib.utils import make_ui
11 8
12 class Globals(object): 9 class Globals(object):
13 10
14 """Globals acts as a container for objects available throughout the 11 """Globals acts as a container for objects available throughout the
15 life of the application 12 life of the application
21 initialization and is available during requests via the 18 initialization and is available during requests via the
22 'app_globals' variable 19 'app_globals' variable
23 20
24 """ 21 """
25 self.cache = CacheManager(**parse_cache_config_options(config)) 22 self.cache = CacheManager(**parse_cache_config_options(config))
26 self.baseui = self.make_ui('hgwebdir.config') 23 self.baseui = make_ui('hgwebdir.config')
27 24 self.paths = self.baseui.configitems('paths')
28
29 def make_ui(self, path='hgwebdir.config'):
30 """
31 A funcion that will read python rc files and make an ui from read options
32
33 @param path: path to mercurial config file
34 """
35 #propagated from mercurial documentation
36 sections = [
37 'alias',
38 'auth',
39 'decode/encode',
40 'defaults',
41 'diff',
42 'email',
43 'extensions',
44 'format',
45 'merge-patterns',
46 'merge-tools',
47 'hooks',
48 'http_proxy',
49 'smtp',
50 'patch',
51 'paths',
52 'profiling',
53 'server',
54 'trusted',
55 'ui',
56 'web',
57 ]
58
59 repos = path
60 baseui = ui.ui()
61 cfg = config.config()
62 cfg.read(repos)
63 self.paths = cfg.items('paths')
64 self.base_path = self.paths[0][1].replace('*', '') 25 self.base_path = self.paths[0][1].replace('*', '')
65 self.check_repo_dir(self.paths)
66 self.set_statics(cfg)
67
68 for section in sections:
69 for k, v in cfg.items(section):
70 baseui.setconfig(section, k, v)
71
72 return baseui
73
74 def set_statics(self, cfg):
75 '''
76 set's the statics for use in mako templates
77 @param cfg:
78 '''
79 self.statics = cfg.get('web', 'staticurl', '/static')
80 if not self.statics.endswith('/'):
81 self.statics += '/'
82
83
84 def check_repo_dir(self, paths):
85 repos_path = paths[0][1].split('/')
86 if repos_path[-1] in ['*', '**']:
87 repos_path = repos_path[:-1]
88 if repos_path[0] != '/':
89 repos_path[0] = '/'
90 if not os.path.isdir(os.path.join(*repos_path)):
91 raise Exception('Not a valid repository in %s' % paths[0][1])
92