# HG changeset patch # User Marcin Kuzminski # Date 2010-04-20 22:26:11 # Node ID aec4c0071cb367393d68e3d49f089b83a580ba84 # Parent 2968fb635787b38ce99712b09a57dbde8dd481a5 added empty controllers for branches tags files graph, routing and test for them diff --git a/development.ini b/development.ini --- a/development.ini +++ b/development.ini @@ -47,7 +47,7 @@ beaker.cache.data_dir=/tmp/cache/data 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 @@ logview.pylons.util = #eee ### 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 @@ qualname = pylons_app [logger_sqlalchemy] -level = DEBUG +level = INFO handlers = console qualname = sqlalchemy.engine +propagate = 0 ############## ## HANDLERS ## diff --git a/pylons_app/controllers/branches.py b/pylons_app/controllers/branches.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/branches.py @@ -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 --git a/pylons_app/controllers/changelog.py b/pylons_app/controllers/changelog.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/changelog.py @@ -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 --git a/pylons_app/controllers/file.py b/pylons_app/controllers/file.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/file.py @@ -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 --git a/pylons_app/controllers/files.py b/pylons_app/controllers/files.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/files.py @@ -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 --git a/pylons_app/controllers/graph.py b/pylons_app/controllers/graph.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/graph.py @@ -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 --git a/pylons_app/controllers/hg.py b/pylons_app/controllers/hg.py --- a/pylons_app/controllers/hg.py +++ b/pylons_app/controllers/hg.py @@ -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 @@ class HgController(BaseController): 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 @@ class HgController(BaseController): 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 @@ class HgController(BaseController): #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 --git a/pylons_app/controllers/shortlog.py b/pylons_app/controllers/shortlog.py --- a/pylons_app/controllers/shortlog.py +++ b/pylons_app/controllers/shortlog.py @@ -19,14 +19,9 @@ class ShortlogController(BaseController) 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 --git a/pylons_app/controllers/tags.py b/pylons_app/controllers/tags.py new file mode 100644 --- /dev/null +++ b/pylons_app/controllers/tags.py @@ -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 --git a/pylons_app/lib/app_globals.py b/pylons_app/lib/app_globals.py --- a/pylons_app/lib/app_globals.py +++ b/pylons_app/lib/app_globals.py @@ -23,35 +23,53 @@ class Globals(object): """ 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 --git a/pylons_app/lib/utils.py b/pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py +++ b/pylons_app/lib/utils.py @@ -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 --git a/pylons_app/model/hg_model.py b/pylons_app/model/hg_model.py --- a/pylons_app/model/hg_model.py +++ b/pylons_app/model/hg_model.py @@ -15,6 +15,7 @@ try: 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 @@ class HgModel(object): 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 --git a/pylons_app/tests/functional/test_branches.py b/pylons_app/tests/functional/test_branches.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_branches.py @@ -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 --git a/pylons_app/tests/functional/test_changelog.py b/pylons_app/tests/functional/test_changelog.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_changelog.py @@ -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 --git a/pylons_app/tests/functional/test_file.py b/pylons_app/tests/functional/test_file.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_file.py @@ -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 --git a/pylons_app/tests/functional/test_files.py b/pylons_app/tests/functional/test_files.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_files.py @@ -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 --git a/pylons_app/tests/functional/test_graph.py b/pylons_app/tests/functional/test_graph.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_graph.py @@ -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 --git a/pylons_app/tests/functional/test_tags.py b/pylons_app/tests/functional/test_tags.py new file mode 100644 --- /dev/null +++ b/pylons_app/tests/functional/test_tags.py @@ -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...