changeset 248:fb7f066126cc

Added support for repository located in subdirectories.
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 03 Jun 2010 20:28:46 +0200
parents 51434007e21d
children bad9ccac26b7
files pylons_app/config/routing.py pylons_app/controllers/repos.py pylons_app/lib/middleware/simplehg.py pylons_app/lib/utils.py pylons_app/model/hg_model.py
diffstat 5 files changed, 58 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/config/routing.py	Thu Jun 03 16:01:47 2010 +0200
+++ b/pylons_app/config/routing.py	Thu Jun 03 20:28:46 2010 +0200
@@ -22,8 +22,32 @@
     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')
     
@@ -34,34 +58,34 @@
                   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
--- a/pylons_app/controllers/repos.py	Thu Jun 03 16:01:47 2010 +0200
+++ b/pylons_app/controllers/repos.py	Thu Jun 03 20:28:46 2010 +0200
@@ -2,6 +2,8 @@
     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
@@ -39,6 +41,7 @@
             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)
         
@@ -85,7 +88,7 @@
         
         #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'))
         
 
--- a/pylons_app/lib/middleware/simplehg.py	Thu Jun 03 16:01:47 2010 +0200
+++ b/pylons_app/lib/middleware/simplehg.py	Thu Jun 03 20:28:46 2010 +0200
@@ -50,8 +50,9 @@
                     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
@@ -63,6 +64,7 @@
             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
--- a/pylons_app/lib/utils.py	Thu Jun 03 16:01:47 2010 +0200
+++ b/pylons_app/lib/utils.py	Thu Jun 03 20:28:46 2010 +0200
@@ -6,10 +6,7 @@
 
 
 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):
     """
@@ -131,14 +128,7 @@
 
 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
--- a/pylons_app/model/hg_model.py	Thu Jun 03 16:01:47 2010 +0200
+++ b/pylons_app/model/hg_model.py	Thu Jun 03 20:28:46 2010 +0200
@@ -82,7 +82,13 @@
         repos_list = {}
         for name, path in repos:
             try:
-                repos_list[name] = MercurialRepository(path, baseui=baseui)
+                #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