Changeset - aec4c0071cb3
[Not reviewed]
development.ini
Show inline comments
 
@@ -44,13 +44,13 @@ repos_name = Python-works
 
###         BEAKER CACHE        ####
 
####################################
 
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*  ##
 
## Debug mode will enable the interactive debugging tool, allowing ANYONE to  ##
 
## execute malicious code after an exception is raised.                       ##
 
################################################################################
 
@@ -64,13 +64,13 @@ logview.pylons.templating = #bfb
 
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
 

	
 
################################
 
### LOGGING CONFIGURATION   ####
 
################################
 
@@ -100,15 +100,16 @@ qualname = routes.middleware
 
level = DEBUG
 
handlers = console
 
qualname = pylons_app
 

	
 

	
 
[logger_sqlalchemy]
 
level = DEBUG
 
level = INFO
 
handlers = console
 
qualname = sqlalchemy.engine
 
propagate = 0
 

	
 
##############
 
## HANDLERS ##
 
##############
 

	
 
[handler_console]
pylons_app/controllers/branches.py
Show inline comments
 
new file 100644
 
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'
pylons_app/controllers/changelog.py
Show inline comments
 
new file 100644
 
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
pylons_app/controllers/file.py
Show inline comments
 
new file 100644
 
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'
pylons_app/controllers/files.py
Show inline comments
 
new file 100644
 
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'
pylons_app/controllers/graph.py
Show inline comments
 
new file 100644
 
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'
pylons_app/controllers/hg.py
Show inline comments
 
#!/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):
 

	
 
    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()
 
        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
 
        c.cs_slug = cs.replace('-', '')
 
        sortables = ['name', 'description', 'last_change', 'tip', 'contact']
 
        
 
@@ -33,33 +45,40 @@ class HgController(BaseController):
 
                c.repos_list.sort(key=itemgetter(sort_key), reverse=True)
 
            else:
 
                c.repos_list.sort(key=itemgetter(sort_key), reverse=False)
 
            
 
        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')
 
        
 
        #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)
pylons_app/controllers/shortlog.py
Show inline comments
 
@@ -16,19 +16,14 @@ class ShortlogController(BaseController)
 
        c.staticurl = g.statics
 
        c.repo_name = get_repo_slug(request)
 
        
 
        
 
    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
 
        r = render('/shortlog.html')
 
        return r
pylons_app/controllers/tags.py
Show inline comments
 
new file 100644
 
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'
pylons_app/lib/app_globals.py
Show inline comments
 
@@ -20,41 +20,59 @@ class Globals(object):
 
        """One instance of Globals is created during application
 
        initialization and is available during requests via the
 
        'app_globals' variable
 

	
 
        """
 
        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):
 
        '''
 
        set's the statics for use in mako templates
 
        @param cfg:
 
        '''
pylons_app/lib/utils.py
Show inline comments
 
   
 
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
pylons_app/model/hg_model.py
Show inline comments
 
@@ -12,12 +12,13 @@ import os
 
from pylons import tmpl_context as c, app_globals as g, session, request, config
 
from pylons.controllers.util import abort
 
try:
 
    from vcs.backends.hg import get_repositories, MercurialRepository
 
except ImportError:
 
    print 'You have to import vcs module'
 
    raise
 

	
 
class HgModel(object):
 
    """
 
    Mercurial Model
 
    """
 

	
 
@@ -46,13 +47,13 @@ class HgModel(object):
 
            tmp_d['last_change_sort'] = last_change[1] - last_change[0]
 
            tmp_d['tip'] = str(tip)
 
            tmp_d['tip_sort'] = tip.rev()
 
            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
 

	
 
    def get_repo(self, repo_name):
 
        path = g.paths[0][1].replace('*', '')
 
        repo = MercurialRepository(os.path.join(path, repo_name), baseui=g.baseui)
pylons_app/tests/functional/test_branches.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestBranchesController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='branches', action='index'))
 
        # Test response...
pylons_app/tests/functional/test_changelog.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestChangelogController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='changelog', action='index'))
 
        # Test response...
pylons_app/tests/functional/test_file.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestFileController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='file', action='index'))
 
        # Test response...
pylons_app/tests/functional/test_files.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestFilesController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='files', action='index'))
 
        # Test response...
pylons_app/tests/functional/test_graph.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestGraphController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='graph', action='index'))
 
        # Test response...
pylons_app/tests/functional/test_tags.py
Show inline comments
 
new file 100644
 
from pylons_app.tests import *
 

	
 
class TestTagsController(TestController):
 

	
 
    def test_index(self):
 
        response = self.app.get(url(controller='tags', action='index'))
 
        # Test response...
0 comments (0 inline, 0 general)