# HG changeset patch # User Marcin Kuzminski # Date 1271802371 -7200 # Node ID aec4c0071cb367393d68e3d49f089b83a580ba84 # Parent 2968fb635787b38ce99712b09a57dbde8dd481a5 added empty controllers for branches tags files graph, routing and test for them diff -r 2968fb635787 -r aec4c0071cb3 development.ini --- a/development.ini Wed Apr 21 00:22:20 2010 +0200 +++ b/development.ini Wed Apr 21 00:26:11 2010 +0200 @@ -47,7 +47,7 @@ beaker.cache.lock_dir=/tmp/cache/lock beaker.cache.regions=short_term beaker.cache.short_term.type=memory -beaker.cache.short_term.expire=3600 +beaker.cache.short_term.expire=60 ################################################################################ ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## @@ -67,7 +67,7 @@ ### DB CONFIGS - EACH DB WILL HAVE IT'S OWN CONFIG ### ######################################################### sqlalchemy.db1.url = sqlite:///%(here)s/hg_app.db -#sqlalchemy.db1.echo = True +#sqlalchemy.db1.echo = False #sqlalchemy.db1.pool_recycle = 3600 sqlalchemy.convert_unicode = true @@ -103,9 +103,10 @@ [logger_sqlalchemy] -level = DEBUG +level = INFO handlers = console qualname = sqlalchemy.engine +propagate = 0 ############## ## HANDLERS ## diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/branches.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/branches.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,16 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect + +from pylons_app.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +class BranchesController(BaseController): + + def index(self): + # Return a rendered template + #return render('/branches.mako') + # or, return a string + return 'Hello World' diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/changelog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/changelog.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,29 @@ +import logging + +from pylons import tmpl_context as c, app_globals as g, session, request, config, url +from pylons.controllers.util import abort, redirect + +from pylons_app.lib.base import BaseController, render +from pylons_app.lib.utils import get_repo_slug +from pylons_app.model.hg_model import HgModel +from webhelpers.paginate import Page + +log = logging.getLogger(__name__) + +class ChangelogController(BaseController): + def __before__(self): + c.repos_prefix = config['repos_name'] + c.staticurl = g.statics + c.repo_name = get_repo_slug(request) + + + def index(self): + hg_model = HgModel() + p = int(request.params.get('page', 1)) + repo = hg_model.get_repo(c.repo_name) + c.repo_changesets = Page(repo, page=p, items_per_page=20) + c.shortlog_data = render('shortlog_data.html') + if request.params.get('partial'): + return c.shortlog_data + r = render('/shortlog.html') + return r diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/file.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/file.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,16 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect + +from pylons_app.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +class FileController(BaseController): + + def index(self): + # Return a rendered template + #return render('/file.mako') + # or, return a string + return 'Hello World' diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/files.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/files.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,16 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect + +from pylons_app.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +class FilesController(BaseController): + + def index(self): + # Return a rendered template + #return render('/files.mako') + # or, return a string + return 'Hello World' diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/graph.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/graph.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,16 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect + +from pylons_app.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +class GraphController(BaseController): + + def index(self): + # Return a rendered template + #return render('/graph.mako') + # or, return a string + return 'Hello World' diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/hg.py --- a/pylons_app/controllers/hg.py Wed Apr 21 00:22:20 2010 +0200 +++ b/pylons_app/controllers/hg.py Wed Apr 21 00:26:11 2010 +0200 @@ -1,14 +1,20 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -import logging +from mako.template import Template +from mercurial.hg import repository +from mercurial.hgweb import hgweb +from mercurial.hgweb.request import wsgiapplication +from mercurial.localrepo import localrepository +from operator import itemgetter from pylons import tmpl_context as c, app_globals as g, session, request, config +from pylons.controllers.util import abort from pylons_app.lib import helpers as h from pylons_app.lib.base import BaseController, render -from mako.template import Template -from pylons.controllers.util import abort from pylons_app.lib.utils import get_repo_slug -from operator import itemgetter from pylons_app.model.hg_model import HgModel +import logging +import os +from beaker.cache import cache_region log = logging.getLogger(__name__) class HgController(BaseController): @@ -19,8 +25,14 @@ c.repo_name = get_repo_slug(request) def index(self): + + hg_model = HgModel() - c.repos_list = list(hg_model.get_repos()) + @cache_region('short_term', 'repo_list') + def _list(): + return list(hg_model.get_repos()) + + c.repos_list = _list() c.current_sort = request.GET.get('sort', 'name') cs = c.current_sort @@ -36,11 +48,19 @@ return render('/index.html') - def view(self, *args, **kwargs): - #TODO: reimplement this not tu use hgwebdir - - response = g.hgapp(request.environ, self.start_response) + def view(self, environ, start_response, path_info): + print path_info + def app_maker(): + + path = os.path.join(g.base_path, c.repo_name) + repo = repository(g.baseui, path) + hgwebapp = hgweb(repo, c.repo_name) + return hgwebapp + + a = wsgiapplication(app_maker) + resp = a(environ, start_response) + http_accept = request.environ.get('HTTP_ACCEPT', False) if not http_accept: return abort(status_code=400, detail='no http accept in header') @@ -48,18 +68,17 @@ #for mercurial protocols and raw files we can't wrap into mako if http_accept.find("mercurial") != -1 or \ request.environ['PATH_INFO'].find('raw-file') != -1: - return response + return resp try: - tmpl = u''.join(response) + tmpl = u''.join(resp) template = Template(tmpl, lookup=request.environ['pylons.pylons']\ .config['pylons.app_globals'].mako_lookup) except (RuntimeError, UnicodeDecodeError): log.info('disabling unicode due to encoding error') - response = g.hgapp(request.environ, self.start_response) - tmpl = ''.join(response) + resp = g.hgapp(request.environ, self.start_response) + tmpl = ''.join(resp) template = Template(tmpl, lookup=request.environ['pylons.pylons']\ .config['pylons.app_globals'].mako_lookup, disable_unicode=True) - return template.render(g=g, c=c, session=session, h=h) diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/shortlog.py --- a/pylons_app/controllers/shortlog.py Wed Apr 21 00:22:20 2010 +0200 +++ b/pylons_app/controllers/shortlog.py Wed Apr 21 00:26:11 2010 +0200 @@ -19,14 +19,9 @@ def index(self): hg_model = HgModel() - lim = 20 p = int(request.params.get('page', 1)) repo = hg_model.get_repo(c.repo_name) - cnt = repo.revisions[-1] - gen = repo.get_changesets(None) - repo_changesets = list(gen) - - c.repo_changesets = Page(repo_changesets, page=p, item_count=cnt, items_per_page=lim) + c.repo_changesets = Page(repo, page=p, items_per_page=20) c.shortlog_data = render('shortlog_data.html') if request.params.get('partial'): return c.shortlog_data diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/controllers/tags.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/controllers/tags.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,16 @@ +import logging + +from pylons import request, response, session, tmpl_context as c, url +from pylons.controllers.util import abort, redirect + +from pylons_app.lib.base import BaseController, render + +log = logging.getLogger(__name__) + +class TagsController(BaseController): + + def index(self): + # Return a rendered template + #return render('/tags.mako') + # or, return a string + return 'Hello World' diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/lib/app_globals.py --- a/pylons_app/lib/app_globals.py Wed Apr 21 00:22:20 2010 +0200 +++ b/pylons_app/lib/app_globals.py Wed Apr 21 00:26:11 2010 +0200 @@ -23,35 +23,53 @@ """ self.cache = CacheManager(**parse_cache_config_options(config)) - self.hgapp = wsgiapplication(self.make_web_app) + self.baseui = self.make_ui('hgwebdir.config') + - def make_web_app(self): - repos = "hgwebdir.config" + def make_ui(self, path='hgwebdir.config'): + """ + A funcion that will read python rc files and make an ui from read options + + @param path: path to mercurial config file + """ + #propagated from mercurial documentation + sections = [ + 'alias', + 'auth', + 'decode/encode', + 'defaults', + 'diff', + 'email', + 'extensions', + 'format', + 'merge-patterns', + 'merge-tools', + 'hooks', + 'http_proxy', + 'smtp', + 'patch', + 'paths', + 'profiling', + 'server', + 'trusted', + 'ui', + 'web', + ] + + repos = path baseui = ui.ui() cfg = config.config() cfg.read(repos) - paths = cfg.items('paths') - self.paths = paths - self.check_repo_dir(paths) - + self.paths = cfg.items('paths') + self.base_path = self.paths[0][1].replace('*', '') + self.check_repo_dir(self.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)) - self.baseui = baseui - #baseui.setconfig('web', 'description', '') - #baseui.setconfig('web', 'name', '') - #baseui.setconfig('web', 'contact', '') - #baseui.setconfig('web', 'allow_archive', '') - #baseui.setconfig('web', 'style', 'monoblue_plain') - #baseui.setconfig('web', 'baseurl', '') - #baseui.setconfig('web', 'staticurl', '') + + for section in sections: + for k, v in cfg.items(section): + baseui.setconfig(section, k, v) - hgwebapp = hgwebdir(paths, baseui=baseui) - return hgwebapp - + return baseui def set_statics(self, cfg): ''' diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py Wed Apr 21 00:22:20 2010 +0200 +++ b/pylons_app/lib/utils.py Wed Apr 21 00:26:11 2010 +0200 @@ -1,7 +1,8 @@ def get_repo_slug(request): path_info = request.environ.get('PATH_INFO') - repo_name = path_info.split('/')[-2] - action = path_info.split('/')[-1] - + uri_lst = path_info.split('/') + print uri_lst + print 'len', len(uri_lst) + repo_name = uri_lst[1] return repo_name diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/model/hg_model.py --- a/pylons_app/model/hg_model.py Wed Apr 21 00:22:20 2010 +0200 +++ b/pylons_app/model/hg_model.py Wed Apr 21 00:26:11 2010 +0200 @@ -15,6 +15,7 @@ from vcs.backends.hg import get_repositories, MercurialRepository except ImportError: print 'You have to import vcs module' + raise class HgModel(object): """ @@ -49,7 +50,7 @@ tmp_d['rev'] = tip.rev() tmp_d['contact'] = mercurial_repo.contact tmp_d['contact_sort'] = tmp_d['contact'] - tmp_d['repo_archives'] = mercurial_repo._get_archives() + tmp_d['repo_archives'] = list(mercurial_repo._get_archives()) yield tmp_d diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/tests/functional/test_branches.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_branches.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,7 @@ +from pylons_app.tests import * + +class TestBranchesController(TestController): + + def test_index(self): + response = self.app.get(url(controller='branches', action='index')) + # Test response... diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/tests/functional/test_changelog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_changelog.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,7 @@ +from pylons_app.tests import * + +class TestChangelogController(TestController): + + def test_index(self): + response = self.app.get(url(controller='changelog', action='index')) + # Test response... diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/tests/functional/test_file.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_file.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,7 @@ +from pylons_app.tests import * + +class TestFileController(TestController): + + def test_index(self): + response = self.app.get(url(controller='file', action='index')) + # Test response... diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/tests/functional/test_files.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_files.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,7 @@ +from pylons_app.tests import * + +class TestFilesController(TestController): + + def test_index(self): + response = self.app.get(url(controller='files', action='index')) + # Test response... diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/tests/functional/test_graph.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_graph.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,7 @@ +from pylons_app.tests import * + +class TestGraphController(TestController): + + def test_index(self): + response = self.app.get(url(controller='graph', action='index')) + # Test response... diff -r 2968fb635787 -r aec4c0071cb3 pylons_app/tests/functional/test_tags.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/tests/functional/test_tags.py Wed Apr 21 00:26:11 2010 +0200 @@ -0,0 +1,7 @@ +from pylons_app.tests import * + +class TestTagsController(TestController): + + def test_index(self): + response = self.app.get(url(controller='tags', action='index')) + # Test response...