Changeset - fac1f62a1d71
[Not reviewed]
default
0 5 0
Marcin Kuzminski - 16 years ago 2010-02-28 02:24:44

Wrapped into mako templates,
changed templates info. Added session and cache middleware.
5 files changed with 30 insertions and 11 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/middleware.py
Show inline comments
 
"""Pylons middleware initialization"""
 
from beaker.middleware import CacheMiddleware, SessionMiddleware
 
from paste.cascade import Cascade
 
from paste.registry import RegistryManager
 
from paste.urlparser import StaticURLParser
 
from paste.deploy.converters import asbool
 
from pylons import config
 
from pylons.middleware import ErrorHandler, StatusCodeRedirect
 
from pylons.wsgiapp import PylonsApp
 
from routes.middleware import RoutesMiddleware
 

	
 
from pylons_app.config.environment import load_environment
 

	
 

	
 
def make_app(global_conf, full_stack = True, **app_conf):
 
    """Create a Pylons WSGI application and return it
 

	
 
    ``global_conf``
 
        The inherited configuration for this application. Normally from
 
        the [DEFAULT] section of the Paste ini file.
 

	
 
    ``full_stack``
 
        Whether or not this application provides a full WSGI stack (by
 
        default, meaning it handles its own exceptions and errors).
 
        Disable full_stack when this application is "managed" by
 
        another WSGI middleware.
 

	
 
    ``app_conf``
 
        The application's local configuration. Normally specified in
 
        the [app:<name>] section of the Paste ini file (where <name>
 
        defaults to main).
 

	
 
    """
 
    # Configure the Pylons environment
 
    load_environment(global_conf, app_conf)
 

	
 
    # The Pylons WSGI app
 
    app = PylonsApp()
 

	
 
    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
 

	
 
    # Routing/Session/Cache Middleware
 
    app = RoutesMiddleware(app, config['routes.map'])
 
    app = SessionMiddleware(app, config)
 
    app = CacheMiddleware(app, config)
 

	
 
    if asbool(full_stack):
 
        # Handle Python exceptions
 
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
 

	
 
        # Display error documents for 401, 403, 404 status codes (and
 
        # 500 when debug is disabled)
 
        if asbool(config['debug']):
 
            #don't handle 404, since mercurial does it for us.
 
            app = StatusCodeRedirect(app, [400, 401, 403, 500])
 
        else:
 
            app = StatusCodeRedirect(app, [400, 401, 403, 500])
 

	
 
    # Establish the Registry for this application
 
    app = RegistryManager(app)
 

	
 
    # Static files (If running in production, and Apache or another web
 
    # server is handling this static content, remove the following 3 lines)
 
    static_app = StaticURLParser(config['pylons.paths']['static_files'])
 
    app = Cascade([static_app, app])
 
    return app
 

	
pylons_app/controllers/hg.py
Show inline comments
 
#!/usr/bin/python
 
# -*- coding: utf-8 -*-
 
import logging
 
from pylons_app.lib.base import BaseController, render
 
from pylons import c, g, session, h, request
 
from mako.template import Template
 
from pprint import pprint
 
import os
 
from mercurial import ui, hg
 
from mercurial.error import RepoError
 
from ConfigParser import ConfigParser
 

	
 
log = logging.getLogger(__name__)
 

	
 
class HgController(BaseController):
 
    def index(self):
 
        return g.hgapp(request.environ, self.start_response)
 

	
 
    def __before__(self):
 
        c.repos_prefix = 'etelko'
 

	
 

	
 
    def view(self, *args, **kwargs):
 
        return g.hgapp(request.environ, self.start_response)
 
        response = g.hgapp(request.environ, self.start_response)
 
        #for mercurial protocols we can't wrap into mako
 
        if request.environ['HTTP_ACCEPT'].find("mercurial") >= 0:
 
                    return response
 

	
 
        #wrap the murcurial response in a mako template.
 
        template = Template("".join(response),
 
                            lookup = request.environ['pylons.pylons']\
 
                            .config['pylons.g'].mako_lookup)
 

	
 
        return template.render(g = g, c = c, session = session, h = h)
 

	
 
    def add_repo(self, new_repo):
 
        c.staticurl = g.statics
 

	
 
        #extra check it can be add since it's the command
 
        if new_repo == 'add':
 
            c.msg = 'you basstard ! this repo is a command'
 
            c.new_repo = ''
 
            return render('add.html')
 

	
 
        new_repo = new_repo.replace(" ", "_")
 
        new_repo = new_repo.replace("-", "_")
 

	
 
        try:
 
            self._create_repo(new_repo)
 
            c.new_repo = new_repo
 
            c.msg = 'added repo'
 
        except Exception as e:
 
            c.new_repo = 'Exception when adding: %s' % new_repo
 
            c.msg = str(e)
 

	
 
        return render('add.html')
 

	
 
    def _check_repo(self, repo_name):
 
        p = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
 
        config_path = os.path.join(p, 'hgwebdir.config')
 

	
 
        cp = ConfigParser()
 

	
 
        cp.read(config_path)
 
        repos_path = cp.get('paths', '/').replace("**", '')
 

	
 
        if not repos_path:
 
            raise Exception('Could not read config !')
 

	
 
        self.repo_path = os.path.join(repos_path, repo_name)
 

	
 
        try:
 
            r = hg.repository(ui.ui(), self.repo_path)
 
            hg.verify(r)
 
            #here we hnow that repo exists it was verified
 
            log.info('%s repo is already created', repo_name)
 
            raise Exception('Repo exists')
 
        except RepoError:
 
            log.info('%s repo is free for creation', repo_name)
 
            #it means that there is no valid repo there...
 
            return True
 

	
 

	
 
    def _create_repo(self, repo_name):
 
        if repo_name in [None, '', 'add']:
 
            raise Exception('undefined repo_name of repo')
 

	
 
        if self._check_repo(repo_name):
 
            log.info('creating repo %s in %s', repo_name, self.repo_path)
 
            cmd = """mkdir %s && hg init %s""" \
 
                    % (self.repo_path, self.repo_path)
 
            os.popen(cmd)
 

	
 
#def _make_app():
 
#    #for single a repo
 
#    #return hgweb("/path/to/repo", "Name")
 
#    repos = "hgwebdir.config"
 
#    return  hgwebdir(repos)
 
#
 

	
 
#    def view(self, environ, start_response):
 
#        #the following is only needed when using hgwebdir
 
#        app = _make_app()
 
#        #return wsgi_app(environ, start_response)
 
#        response = app(request.environ, self.start_response)
 
#
 
#        if environ['PATH_INFO'].find("static") != -1:
 
#            return response
 
#        else:
 
#            #wrap the murcurial response in a mako template.
 
#            template = Template("".join(response),
 
#                                lookup = environ['pylons.pylons']\
 
#                                .config['pylons.g'].mako_lookup)
 
#
 
#            return template.render(g = g, c = c, session = session, h = h)
pylons_app/templates/monoblue_custom/changelog.tmpl
Show inline comments
 
{header}
 
    <title>{repo|escape}: changelog</title>
 
    <link rel="alternate" type="application/atom+xml" href="{url}atom-log" title="Atom feed for {repo|escape}"/>
 
    <link rel="alternate" type="application/rss+xml" href="{url}rss-log" title="RSS feed for {repo|escape}"/>
 
</head>
 

	
 
<body>
 
<div id="container">
 
    <div class="page-header">
 
        <h1><a href="/">Home</a> / <a href="{url}summary{sessionvars%urlparameter}">{repo|escape}</a> / changelog</h1>
 

	
 
        <form action="{url}log">
 
            {sessionvars%hiddenformentry}
 
            <dl class="search">
 
                <dt><label>Search: </label></dt>
 
                <dd><input type="text" name="rev" /></dd>
 
            </dl>
 
        </form>
 

	
 
        <ul class="page-nav">
 
            <li><a href="{url}summary{sessionvars%urlparameter}">summary</a></li>
 
            <li><a href="{url}shortlog{sessionvars%urlparameter}">shortlog</a></li>
 
            <li class="current">changelog</li>
 
            <li><a href="{url}graph/{node|short}{sessionvars%urlparameter}">graph</a></li>
 
            <li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
 
            <li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
 
            <li><a href="{url}file/{node|short}{sessionvars%urlparameter}">files</a>{archives%archiveentry}</li>
 
        </ul>
 
            <li><a href="{url}file/{node|short}{sessionvars%urlparameter}">files</a></li>
 

	
 
      
 
    </div>
 

	
 
    <ul class="submenu">
 
        {archives%archiveentry}
 
    </ul>  
 
    <h2 class="no-link no-border">changelog</h2>
 
    <div>
 
    {entries%changelogentry}
 
    </div>
 

	
 
    <div class="page-path">
 
{changenav%naventry}
 
    </div>
 

	
 
{footer}
pylons_app/templates/monoblue_custom/index.tmpl
Show inline comments
 
{header}
 
    <title>{repo|escape}: Mercurial repositories index</title>
 
</head>
 

	
 
<body>
 
<div id="container">
 
    <div class="page-header">
 
        <h1> Mercurial Repositories</h1>
 
        <h1>${c.repos_prefix} Mercurial Repositories</h1>
 
        <ul class="page-nav">
 
        </ul>
 
    </div>
 
    
 
    <table cellspacing="0">
 
        <tr>
 
            <td><a href="?sort={sort_name}">Name</a></td>
 
            <td><a href="?sort={sort_description}">Description</a></td>
 
            <td><a href="?sort={sort_contact}">Contact</a></td>
 
            <td><a href="?sort={sort_lastchange}">Last change</a></td>
 
            <td>&nbsp;</td>
 
            <td>&nbsp;</td>
 
        </tr>
 
        {entries%indexentry}
 
    </table>
 
    <div class="page-footer">
 
        {motd}
 
    </div>
 

	
 
    <div id="powered-by">
 
        <p><a href="http://mercurial.selenic.com/" title="Mercurial"><img src="{staticurl}hglogo.png" width=75 height=90 border=0 alt="mercurial"></a></p>
 
    </div>
 

	
 
    <div id="corner-top-left"></div>
 
    <div id="corner-top-right"></div>
 
    <div id="corner-bottom-left"></div>
 
    <div id="corner-bottom-right"></div>
 

	
 
</div>
 
</body>
 
</html>
pylons_app/templates/monoblue_custom/shortlog.tmpl
Show inline comments
 
{header}
 
    <title>{repo|escape}: shortlog</title>
 
    <link rel="alternate" type="application/atom+xml" href="{url}atom-log" title="Atom feed for {repo|escape}"/>
 
    <link rel="alternate" type="application/rss+xml" href="{url}rss-log" title="RSS feed for {repo|escape}"/>
 
</head>
 

	
 
<body>
 
<div id="container">
 
    <div class="page-header">
 
        <h1><a href="/">Home</a> / <a href="{url}summary{sessionvars%urlparameter}">{repo|escape}</a> / shortlog</h1>
 

	
 
        <form action="{url}log">
 
            {sessionvars%hiddenformentry}
 
            <dl class="search">
 
                <dt><label>Search: </label></dt>
 
                <dd><input type="text" name="rev" /></dd>
 
            </dl>
 
        </form>
 

	
 
        <ul class="page-nav">
 
            <li><a href="{url}summary{sessionvars%urlparameter}">summary</a></li>
 
            <li class="current">shortlog</li>
 
            <li><a href="{url}log{sessionvars%urlparameter}">changelog</a></li>
 
            <li><a href="{url}graph/{node|short}{sessionvars%urlparameter}">graph</a></li>
 
            <li><a href="{url}tags{sessionvars%urlparameter}">tags</a></li>
 
            <li><a href="{url}branches{sessionvars%urlparameter}">branches</a></li>
 
            <li><a href="{url}file/{node|short}{sessionvars%urlparameter}">files</a>{archives%archiveentry}</li>
 
            <li><a href="{url}file/{node|short}{sessionvars%urlparameter}">files</a></li>
 
        </ul>
 
    </div>
 

	
 
    <ul class="submenu">
 
        {archives%archiveentry}
 
    </ul>  
 
    <h2 class="no-link no-border">shortlog</h2>
 

	
 
    <table>
 
{entries%shortlogentry}
 
        {entries%shortlogentry}
 
    </table>
 

	
 
    <div class="page-path">
 
{changenav%navshortentry}
 
        {changenav%navshortentry}
 
    </div>
 

	
 
{footer}
0 comments (0 inline, 0 general)