Mercurial > kallithea
annotate pylons_app/lib/app_globals.py @ 94:0bb9391bc287
webhelpers update
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 24 Apr 2010 16:52:34 +0200 |
parents | aec4c0071cb3 |
children | f7c403e89d5b |
rev | line source |
---|---|
0 | 1 """The application's Globals object""" |
10
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
0
diff
changeset
|
2 #uncomment the following if you want to serve a single repo |
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
0
diff
changeset
|
3 #from mercurial.hgweb.hgweb_mod import hgweb |
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
0
diff
changeset
|
4 from mercurial.hgweb.hgwebdir_mod import hgwebdir |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
5 from mercurial import templater |
10
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
0
diff
changeset
|
6 from mercurial.hgweb.request import wsgiapplication |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
7 from mercurial import ui, config |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
8 import os |
43 | 9 from beaker.cache import CacheManager |
10 from beaker.util import parse_cache_config_options | |
11 | |
0 | 12 class Globals(object): |
13 | |
14 """Globals acts as a container for objects available throughout the | |
15 life of the application | |
16 | |
17 """ | |
18 | |
43 | 19 def __init__(self, config): |
0 | 20 """One instance of Globals is created during application |
21 initialization and is available during requests via the | |
22 'app_globals' variable | |
23 | |
24 """ | |
43 | 25 self.cache = CacheManager(**parse_cache_config_options(config)) |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
26 self.baseui = self.make_ui('hgwebdir.config') |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
27 |
10
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
0
diff
changeset
|
28 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
29 def make_ui(self, path='hgwebdir.config'): |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
30 """ |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
31 A funcion that will read python rc files and make an ui from read options |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
32 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
33 @param path: path to mercurial config file |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
34 """ |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
35 #propagated from mercurial documentation |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
36 sections = [ |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
37 'alias', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
38 'auth', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
39 'decode/encode', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
40 'defaults', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
41 'diff', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
42 'email', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
43 'extensions', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
44 'format', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
45 'merge-patterns', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
46 'merge-tools', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
47 'hooks', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
48 'http_proxy', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
49 'smtp', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
50 'patch', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
51 'paths', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
52 'profiling', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
53 'server', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
54 'trusted', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
55 'ui', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
56 'web', |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
57 ] |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
58 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
59 repos = path |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
60 baseui = ui.ui() |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
61 cfg = config.config() |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
62 cfg.read(repos) |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
63 self.paths = cfg.items('paths') |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
64 self.base_path = self.paths[0][1].replace('*', '') |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
65 self.check_repo_dir(self.paths) |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
66 self.set_statics(cfg) |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
67 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
68 for section in sections: |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
69 for k, v in cfg.items(section): |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
70 baseui.setconfig(section, k, v) |
31
2963f2894a7a
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)
Marcin Kuzminski <marcin@python-blog.com>
parents:
20
diff
changeset
|
71 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
80
diff
changeset
|
72 return baseui |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
73 |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
74 def set_statics(self, cfg): |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
75 ''' |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
76 set's the statics for use in mako templates |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
77 @param cfg: |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
78 ''' |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
79 self.statics = cfg.get('web', 'staticurl', '/static') |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
80 if not self.statics.endswith('/'): |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
81 self.statics += '/' |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
82 |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
83 |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
84 def check_repo_dir(self, paths): |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
85 repos_path = paths[0][1].split('/') |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
86 if repos_path[-1] in ['*', '**']: |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
87 repos_path = repos_path[:-1] |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
88 if repos_path[0] != '/': |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
89 repos_path[0] = '/' |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
90 if not os.path.isdir(os.path.join(*repos_path)): |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
91 raise Exception('Not a valid repository in %s' % paths[0][1]) |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
10
diff
changeset
|
92 |