annotate pylons_app/lib/app_globals.py @ 56:bf1b64046c79

Added last change translation to 'time ago', added generation of enabled zip archives
author Marcin Kuzminski <marcin@python-blog.com>
date Fri, 09 Apr 2010 00:30:42 +0200
parents e00dccb6f211
children 928416088790
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 31
diff changeset
9 from beaker.cache import CacheManager
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 31
diff changeset
10 from beaker.util import parse_cache_config_options
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 31
diff changeset
11
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
12 class Globals(object):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
13
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14 """Globals acts as a container for objects available throughout the
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
15 life of the application
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17 """
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
18
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 31
diff changeset
19 def __init__(self, config):
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20 """One instance of Globals is created during application
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 initialization and is available during requests via the
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
22 'app_globals' variable
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
23
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
24 """
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
25 #two ways of building the merc app i don't know
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
26 #the fastest one but belive the wsgiapp is better
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
27 #self.hgapp = self.make_web_app()
43
2e1247e62c5b changed for pylons 0.1 / 1.0
marcink
parents: 31
diff changeset
28 self.cache = CacheManager(**parse_cache_config_options(config))
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
29 self.hgapp = wsgiapplication(self.make_web_app)
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
30
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
31 def make_web_app(self):
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
32 repos = "hgwebdir.config"
20
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
33 baseui = ui.ui()
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
34 cfg = config.config()
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
35 cfg.read(repos)
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
36 paths = cfg.items('paths')
55
e00dccb6f211 Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
37 self.paths = paths
20
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
38 self.check_repo_dir(paths)
55
e00dccb6f211 Implemented index page using vcs
Marcin Kuzminski <marcin@python-blog.com>
parents: 43
diff changeset
39
20
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
40 self.set_statics(cfg)
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
41
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
42 for k, v in cfg.items('web'):
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
43 baseui.setconfig('web', k, v)
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
44 #magic trick to make our custom template dir working
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
45 templater.path.append(cfg.get('web', 'templates', None))
56
bf1b64046c79 Added last change translation to 'time ago', added generation of enabled zip archives
Marcin Kuzminski <marcin@python-blog.com>
parents: 55
diff changeset
46 self.baseui = baseui
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
47 #baseui.setconfig('web', 'description', '')
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
48 #baseui.setconfig('web', 'name', '')
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
49 #baseui.setconfig('web', 'contact', '')
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
50 #baseui.setconfig('web', 'allow_archive', '')
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
51 #baseui.setconfig('web', 'style', 'monoblue_plain')
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
52 #baseui.setconfig('web', 'baseurl', '')
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
53 #baseui.setconfig('web', 'staticurl', '')
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
54
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
55 hgwebapp = hgwebdir(paths, baseui=baseui)
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
56 return hgwebapp
20
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
57
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
58
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
59 def set_statics(self, cfg):
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
60 '''
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
61 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
62 @param cfg:
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
63 '''
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
64 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
65 if not self.statics.endswith('/'):
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
66 self.statics += '/'
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
67
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
68
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
69 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
70 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
71 if repos_path[-1] in ['*', '**']:
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
72 repos_path = repos_path[:-1]
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
73 if repos_path[0] != '/':
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
74 repos_path[0] = '/'
bbaab7501c1a Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents: 10
diff changeset
75 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
76 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
77