Changeset - fb7f066126cc
[Not reviewed]
default
0 5 0
Marcin Kuzminski - 15 years ago 2010-06-03 20:28:46
marcin@python-works.com
Added support for repository located in subdirectories.
5 files changed with 57 insertions and 32 deletions:
0 comments (0 inline, 0 general)
pylons_app/config/routing.py
Show inline comments
 
@@ -19,49 +19,73 @@ def make_map(config):
 
    map.connect('/error/{action}/{id}', controller='error')
 

	
 
    # CUSTOM ROUTES HERE
 
    map.connect('hg_home', '/', controller='hg', action='index')
 
    
 
    
 
    #REST controllers
 
    map.resource('repo', 'repos', path_prefix='/_admin')
 
    #REST routes
 
    with map.submapper(path_prefix='/_admin', controller='repos') as m:
 
        m.connect("repos", "/repos",
 
             action="create", conditions=dict(method=["POST"]))
 
        m.connect("repos", "/repos",
 
             action="index", conditions=dict(method=["GET"]))
 
        m.connect("formatted_repos", "/repos.{format}",
 
             action="index",
 
            conditions=dict(method=["GET"]))
 
        m.connect("new_repo", "/repos/new",
 
             action="new", conditions=dict(method=["GET"]))
 
        m.connect("formatted_new_repo", "/repos/new.{format}",
 
             action="new", conditions=dict(method=["GET"]))
 
        m.connect("/repos/{id:.*}",
 
             action="update", conditions=dict(method=["PUT"]))
 
        m.connect("/repos/{id:.*}",
 
             action="delete", conditions=dict(method=["DELETE"]))
 
        m.connect("edit_repo", "/repos/{id:.*}/edit",
 
             action="edit", conditions=dict(method=["GET"]))
 
        m.connect("formatted_edit_repo", "/repos/{id:.*}.{format}/edit",
 
             action="edit", conditions=dict(method=["GET"]))
 
        m.connect("repo", "/repos/{id:.*}",
 
             action="show", conditions=dict(method=["GET"]))
 
        m.connect("formatted_repo", "/repos/{id:.*}.{format}",
 
             action="show", conditions=dict(method=["GET"]))
 

	
 
    map.resource('user', 'users', path_prefix='/_admin')
 
    map.resource('permission', 'permissions', path_prefix='/_admin')
 
    
 
    #ADMIN
 
    with map.submapper(path_prefix='/_admin', controller='admin') as m:
 
        m.connect('admin_home', '/', action='index')#main page
 
        m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}',
 
                  action='add_repo')
 
    
 
    #FEEDS
 
    map.connect('rss_feed_home', '/{repo_name}/feed/rss',
 
    map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss',
 
                controller='feed', action='rss')
 
    map.connect('atom_feed_home', '/{repo_name}/feed/atom',
 
    map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom',
 
                controller='feed', action='atom')
 
    
 
    map.connect('login_home', '/login', controller='login')
 
    map.connect('logout_home', '/logout', controller='login', action='logout')
 
    
 
    map.connect('changeset_home', '/{repo_name}/changeset/{revision}',
 
    map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
 
                controller='changeset', revision='tip')
 
    map.connect('summary_home', '/{repo_name}/summary',
 
    map.connect('summary_home', '/{repo_name:.*}/summary',
 
                controller='summary')
 
    map.connect('shortlog_home', '/{repo_name}/shortlog',
 
    map.connect('shortlog_home', '/{repo_name:.*}/shortlog',
 
                controller='shortlog')
 
    map.connect('branches_home', '/{repo_name}/branches',
 
    map.connect('branches_home', '/{repo_name:.*}/branches',
 
                controller='branches')
 
    map.connect('tags_home', '/{repo_name}/tags',
 
    map.connect('tags_home', '/{repo_name:.*}/tags',
 
                controller='tags')
 
    map.connect('changelog_home', '/{repo_name}/changelog',
 
    map.connect('changelog_home', '/{repo_name:.*}/changelog',
 
                controller='changelog')    
 
    map.connect('files_home', '/{repo_name}/files/{revision}/{f_path:.*}',
 
    map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}',
 
                controller='files', revision='tip', f_path='')
 
    map.connect('files_diff_home', '/{repo_name}/diff/{f_path:.*}',
 
    map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}',
 
                controller='files', action='diff', revision='tip', f_path='')
 
    map.connect('files_raw_home', '/{repo_name}/rawfile/{revision}/{f_path:.*}',
 
    map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}',
 
                controller='files', action='rawfile', revision='tip', f_path='')
 
    map.connect('files_annotate_home', '/{repo_name}/annotate/{revision}/{f_path:.*}',
 
    map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}',
 
                controller='files', action='annotate', revision='tip', f_path='')    
 
    map.connect('files_archive_home', '/{repo_name}/archive/{revision}/{fileformat}',
 
    map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}',
 
                controller='files', action='archivefile', revision='tip')
 
    return map
pylons_app/controllers/repos.py
Show inline comments
 
from pylons import request, response, session, tmpl_context as c, url, \
 
    app_globals as g
 
from pylons.controllers.util import abort, redirect
 
from pylons_app.lib.auth import LoginRequired
 
from pylons.i18n.translation import _
 
from pylons_app.lib import helpers as h
 
from pylons_app.lib.base import BaseController, render
 
from pylons_app.lib.filters import clean_repo
 
from pylons_app.lib.utils import check_repo, invalidate_cache
 
from pylons_app.model.hg_model import HgModel
 
import logging
 
import os
 
@@ -36,12 +38,13 @@ class ReposController(BaseController):
 
        name = request.POST.get('name')
 

	
 
        try:
 
            self._create_repo(name)
 
            #clear our cached list for refresh with new repo
 
            invalidate_cache('cached_repo_list')
 
            h.flash(_('created repository %s') % name, category='success')
 
        except Exception as e:
 
            log.error(e)
 
        
 
        return redirect('repos')
 
        
 
    def _create_repo(self, repo_name):        
 
@@ -82,13 +85,13 @@ class ReposController(BaseController):
 
        log.info("Removing %s", rm_path)
 
        shutil.move(os.path.join(rm_path, '.hg'), os.path.join(rm_path, 'rm__.hg'))
 
        shutil.move(rm_path, os.path.join(path, 'rm__%s-%s' % (datetime.today(), id)))
 
        
 
        #clear our cached list for refresh with new repo
 
        invalidate_cache('cached_repo_list')
 
                    
 
        h.flash(_('deleted repository %s') % rm_path, category='success')            
 
        return redirect(url('repos'))
 
        
 

	
 
    def show(self, id, format='html'):
 
        """GET /repos/id: Show a specific item"""
 
        # url('repo', id=ID)
pylons_app/lib/middleware/simplehg.py
Show inline comments
 
@@ -47,25 +47,27 @@ class SimpleHg(object):
 
                    AUTH_TYPE.update(environ, 'basic')
 
                    REMOTE_USER.update(environ, result)
 
                else:
 
                    return result.wsgi_application(environ, start_response)
 
            
 
            try:
 
                repo_name = environ['PATH_INFO'].split('/')[1]
 
            except:
 
                repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:])
 
            except Exception as e:
 
                log.error(e)
 
                return HTTPNotFound()(environ, start_response)
 
            
 
            #since we wrap into hgweb, just reset the path
 
            environ['PATH_INFO'] = '/'
 
            self.baseui = make_ui(self.config['hg_app_repo_conf'])
 
            self.basepath = self.baseui.configitems('paths')[0][1]\
 
                                                            .replace('*', '')
 
            self.repo_path = os.path.join(self.basepath, repo_name)
 
            try:
 
                app = wsgiapplication(self.__make_app)
 
            except Exception as e:
 
                log.error(e)
 
                return HTTPNotFound()(environ, start_response)
 
            action = self.__get_action(environ)            
 
            #invalidate cache on push
 
            if action == 'push':
 
                self.__invalidate_cache(repo_name)
 
            
pylons_app/lib/utils.py
Show inline comments
 
@@ -3,16 +3,13 @@ import logging
 
from mercurial import ui, config, hg
 
from mercurial.error import RepoError
 
log = logging.getLogger(__name__)
 

	
 

	
 
def get_repo_slug(request):
 
    path_info = request.environ.get('PATH_INFO')
 
    uri_lst = path_info.split('/')   
 
    repo_name = uri_lst[1]
 
    return repo_name
 
    return request.environ['pylons.routes_dict'].get('repo_name')
 

	
 
def is_mercurial(environ):
 
    """
 
    Returns True if request's target is mercurial server - header
 
    ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
 
    """
 
@@ -128,17 +125,10 @@ class EmptyChangeset(BaseChangeset):
 
        """
 
        return '0' * 12
 

	
 

	
 
def repo2db_mapper():
 
    """
 
    put !
 
    scann all dirs for .hgdbid
 
    if some dir doesn't have one generate one.
 
    """
 
    pass
 
    #scann all dirs for .hgdbid
 
    #if some dir doesn't have one generate one.
 
    #
 
    
 
    
 
    
 
    
 
    
 
    pass
 
\ No newline at end of file
pylons_app/model/hg_model.py
Show inline comments
 
@@ -79,13 +79,19 @@ class HgModel(object):
 
        if not isinstance(baseui, ui.ui):
 
            baseui = ui.ui()
 
    
 
        repos_list = {}
 
        for name, path in repos:
 
            try:
 
                #name = name.split('/')[-1]
 
                if repos_list.has_key(name):
 
                    raise RepositoryError('Duplicate repository name %s found in'
 
                                    ' %s' % (name, path))
 
                else:
 
                repos_list[name] = MercurialRepository(path, baseui=baseui)
 
                    repos_list[name].name = name
 
            except OSError:
 
                continue
 
        return repos_list
 
        
 
    def get_repos(self):
 
        for name, repo in _get_repos_cached().items():
0 comments (0 inline, 0 general)