##// END OF EJS Templates
added empty controllers for branches tags files graph, routing and test for them
marcink -
r93:aec4c007 default
parent child Browse files
Show More
@@ -0,0 +1,16 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url
4 from pylons.controllers.util import abort, redirect
5
6 from pylons_app.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 class BranchesController(BaseController):
11
12 def index(self):
13 # Return a rendered template
14 #return render('/branches.mako')
15 # or, return a string
16 return 'Hello World'
@@ -0,0 +1,29 b''
1 import logging
2
3 from pylons import tmpl_context as c, app_globals as g, session, request, config, url
4 from pylons.controllers.util import abort, redirect
5
6 from pylons_app.lib.base import BaseController, render
7 from pylons_app.lib.utils import get_repo_slug
8 from pylons_app.model.hg_model import HgModel
9 from webhelpers.paginate import Page
10
11 log = logging.getLogger(__name__)
12
13 class ChangelogController(BaseController):
14 def __before__(self):
15 c.repos_prefix = config['repos_name']
16 c.staticurl = g.statics
17 c.repo_name = get_repo_slug(request)
18
19
20 def index(self):
21 hg_model = HgModel()
22 p = int(request.params.get('page', 1))
23 repo = hg_model.get_repo(c.repo_name)
24 c.repo_changesets = Page(repo, page=p, items_per_page=20)
25 c.shortlog_data = render('shortlog_data.html')
26 if request.params.get('partial'):
27 return c.shortlog_data
28 r = render('/shortlog.html')
29 return r
@@ -0,0 +1,16 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url
4 from pylons.controllers.util import abort, redirect
5
6 from pylons_app.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 class FileController(BaseController):
11
12 def index(self):
13 # Return a rendered template
14 #return render('/file.mako')
15 # or, return a string
16 return 'Hello World'
@@ -0,0 +1,16 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url
4 from pylons.controllers.util import abort, redirect
5
6 from pylons_app.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 class FilesController(BaseController):
11
12 def index(self):
13 # Return a rendered template
14 #return render('/files.mako')
15 # or, return a string
16 return 'Hello World'
@@ -0,0 +1,16 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url
4 from pylons.controllers.util import abort, redirect
5
6 from pylons_app.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 class GraphController(BaseController):
11
12 def index(self):
13 # Return a rendered template
14 #return render('/graph.mako')
15 # or, return a string
16 return 'Hello World'
@@ -0,0 +1,16 b''
1 import logging
2
3 from pylons import request, response, session, tmpl_context as c, url
4 from pylons.controllers.util import abort, redirect
5
6 from pylons_app.lib.base import BaseController, render
7
8 log = logging.getLogger(__name__)
9
10 class TagsController(BaseController):
11
12 def index(self):
13 # Return a rendered template
14 #return render('/tags.mako')
15 # or, return a string
16 return 'Hello World'
@@ -0,0 +1,7 b''
1 from pylons_app.tests import *
2
3 class TestBranchesController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url(controller='branches', action='index'))
7 # Test response...
@@ -0,0 +1,7 b''
1 from pylons_app.tests import *
2
3 class TestChangelogController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url(controller='changelog', action='index'))
7 # Test response...
@@ -0,0 +1,7 b''
1 from pylons_app.tests import *
2
3 class TestFileController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url(controller='file', action='index'))
7 # Test response...
@@ -0,0 +1,7 b''
1 from pylons_app.tests import *
2
3 class TestFilesController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url(controller='files', action='index'))
7 # Test response...
@@ -0,0 +1,7 b''
1 from pylons_app.tests import *
2
3 class TestGraphController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url(controller='graph', action='index'))
7 # Test response...
@@ -0,0 +1,7 b''
1 from pylons_app.tests import *
2
3 class TestTagsController(TestController):
4
5 def test_index(self):
6 response = self.app.get(url(controller='tags', action='index'))
7 # Test response...
@@ -47,7 +47,7 b' beaker.cache.data_dir=/tmp/cache/data'
47 47 beaker.cache.lock_dir=/tmp/cache/lock
48 48 beaker.cache.regions=short_term
49 49 beaker.cache.short_term.type=memory
50 beaker.cache.short_term.expire=3600
50 beaker.cache.short_term.expire=60
51 51
52 52 ################################################################################
53 53 ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ##
@@ -67,7 +67,7 b' logview.pylons.util = #eee'
67 67 ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ###
68 68 #########################################################
69 69 sqlalchemy.db1.url = sqlite:///%(here)s/hg_app.db
70 #sqlalchemy.db1.echo = True
70 #sqlalchemy.db1.echo = False
71 71 #sqlalchemy.db1.pool_recycle = 3600
72 72 sqlalchemy.convert_unicode = true
73 73
@@ -103,9 +103,10 b' qualname = pylons_app'
103 103
104 104
105 105 [logger_sqlalchemy]
106 level = DEBUG
106 level = INFO
107 107 handlers = console
108 108 qualname = sqlalchemy.engine
109 propagate = 0
109 110
110 111 ##############
111 112 ## HANDLERS ##
@@ -1,14 +1,20 b''
1 1 #!/usr/bin/python
2 2 # -*- coding: utf-8 -*-
3 import logging
3 from mako.template import Template
4 from mercurial.hg import repository
5 from mercurial.hgweb import hgweb
6 from mercurial.hgweb.request import wsgiapplication
7 from mercurial.localrepo import localrepository
8 from operator import itemgetter
4 9 from pylons import tmpl_context as c, app_globals as g, session, request, config
10 from pylons.controllers.util import abort
5 11 from pylons_app.lib import helpers as h
6 12 from pylons_app.lib.base import BaseController, render
7 from mako.template import Template
8 from pylons.controllers.util import abort
9 13 from pylons_app.lib.utils import get_repo_slug
10 from operator import itemgetter
11 14 from pylons_app.model.hg_model import HgModel
15 import logging
16 import os
17 from beaker.cache import cache_region
12 18 log = logging.getLogger(__name__)
13 19
14 20 class HgController(BaseController):
@@ -19,8 +25,14 b' class HgController(BaseController):'
19 25 c.repo_name = get_repo_slug(request)
20 26
21 27 def index(self):
28
29
22 30 hg_model = HgModel()
23 c.repos_list = list(hg_model.get_repos())
31 @cache_region('short_term', 'repo_list')
32 def _list():
33 return list(hg_model.get_repos())
34
35 c.repos_list = _list()
24 36 c.current_sort = request.GET.get('sort', 'name')
25 37
26 38 cs = c.current_sort
@@ -36,11 +48,19 b' class HgController(BaseController):'
36 48
37 49 return render('/index.html')
38 50
39 def view(self, *args, **kwargs):
40 #TODO: reimplement this not tu use hgwebdir
41
42 response = g.hgapp(request.environ, self.start_response)
51 def view(self, environ, start_response, path_info):
52 print path_info
43 53
54 def app_maker():
55
56 path = os.path.join(g.base_path, c.repo_name)
57 repo = repository(g.baseui, path)
58 hgwebapp = hgweb(repo, c.repo_name)
59 return hgwebapp
60
61 a = wsgiapplication(app_maker)
62 resp = a(environ, start_response)
63
44 64 http_accept = request.environ.get('HTTP_ACCEPT', False)
45 65 if not http_accept:
46 66 return abort(status_code=400, detail='no http accept in header')
@@ -48,18 +68,17 b' class HgController(BaseController):'
48 68 #for mercurial protocols and raw files we can't wrap into mako
49 69 if http_accept.find("mercurial") != -1 or \
50 70 request.environ['PATH_INFO'].find('raw-file') != -1:
51 return response
71 return resp
52 72 try:
53 tmpl = u''.join(response)
73 tmpl = u''.join(resp)
54 74 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
55 75 .config['pylons.app_globals'].mako_lookup)
56 76
57 77 except (RuntimeError, UnicodeDecodeError):
58 78 log.info('disabling unicode due to encoding error')
59 response = g.hgapp(request.environ, self.start_response)
60 tmpl = ''.join(response)
79 resp = g.hgapp(request.environ, self.start_response)
80 tmpl = ''.join(resp)
61 81 template = Template(tmpl, lookup=request.environ['pylons.pylons']\
62 82 .config['pylons.app_globals'].mako_lookup, disable_unicode=True)
63 83
64
65 84 return template.render(g=g, c=c, session=session, h=h)
@@ -19,14 +19,9 b' class ShortlogController(BaseController)'
19 19
20 20 def index(self):
21 21 hg_model = HgModel()
22 lim = 20
23 22 p = int(request.params.get('page', 1))
24 23 repo = hg_model.get_repo(c.repo_name)
25 cnt = repo.revisions[-1]
26 gen = repo.get_changesets(None)
27 repo_changesets = list(gen)
28
29 c.repo_changesets = Page(repo_changesets, page=p, item_count=cnt, items_per_page=lim)
24 c.repo_changesets = Page(repo, page=p, items_per_page=20)
30 25 c.shortlog_data = render('shortlog_data.html')
31 26 if request.params.get('partial'):
32 27 return c.shortlog_data
@@ -23,35 +23,53 b' class Globals(object):'
23 23
24 24 """
25 25 self.cache = CacheManager(**parse_cache_config_options(config))
26 self.hgapp = wsgiapplication(self.make_web_app)
26 self.baseui = self.make_ui('hgwebdir.config')
27
27 28
28 def make_web_app(self):
29 repos = "hgwebdir.config"
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
30 60 baseui = ui.ui()
31 61 cfg = config.config()
32 62 cfg.read(repos)
33 paths = cfg.items('paths')
34 self.paths = paths
35 self.check_repo_dir(paths)
36
63 self.paths = cfg.items('paths')
64 self.base_path = self.paths[0][1].replace('*', '')
65 self.check_repo_dir(self.paths)
37 66 self.set_statics(cfg)
38
39 for k, v in cfg.items('web'):
40 baseui.setconfig('web', k, v)
41 #magic trick to make our custom template dir working
42 templater.path.append(cfg.get('web', 'templates', None))
43 self.baseui = baseui
44 #baseui.setconfig('web', 'description', '')
45 #baseui.setconfig('web', 'name', '')
46 #baseui.setconfig('web', 'contact', '')
47 #baseui.setconfig('web', 'allow_archive', '')
48 #baseui.setconfig('web', 'style', 'monoblue_plain')
49 #baseui.setconfig('web', 'baseurl', '')
50 #baseui.setconfig('web', 'staticurl', '')
67
68 for section in sections:
69 for k, v in cfg.items(section):
70 baseui.setconfig(section, k, v)
51 71
52 hgwebapp = hgwebdir(paths, baseui=baseui)
53 return hgwebapp
54
72 return baseui
55 73
56 74 def set_statics(self, cfg):
57 75 '''
@@ -1,7 +1,8 b''
1 1
2 2 def get_repo_slug(request):
3 3 path_info = request.environ.get('PATH_INFO')
4 repo_name = path_info.split('/')[-2]
5 action = path_info.split('/')[-1]
6
4 uri_lst = path_info.split('/')
5 print uri_lst
6 print 'len', len(uri_lst)
7 repo_name = uri_lst[1]
7 8 return repo_name
@@ -15,6 +15,7 b' try:'
15 15 from vcs.backends.hg import get_repositories, MercurialRepository
16 16 except ImportError:
17 17 print 'You have to import vcs module'
18 raise
18 19
19 20 class HgModel(object):
20 21 """
@@ -49,7 +50,7 b' class HgModel(object):'
49 50 tmp_d['rev'] = tip.rev()
50 51 tmp_d['contact'] = mercurial_repo.contact
51 52 tmp_d['contact_sort'] = tmp_d['contact']
52 tmp_d['repo_archives'] = mercurial_repo._get_archives()
53 tmp_d['repo_archives'] = list(mercurial_repo._get_archives())
53 54
54 55 yield tmp_d
55 56
General Comments 0
You need to be logged in to leave comments. Login now