Changeset - e8fc875467bd
[Not reviewed]
default
0 3 0
Marcin Kuzminski - 15 years ago 2010-07-14 16:51:19
marcin@python-works.com
implemented manual repo rescann and remapping
3 files changed with 60 insertions and 4 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/admin/settings.py
Show inline comments
 
@@ -20,20 +20,22 @@
 
"""
 
Created on July 14, 2010
 
settings controller for pylons
 
@author: marcink
 
"""
 
from formencode import htmlfill
 
from pylons import request, session, tmpl_context as c, url
 
from pylons import request, session, tmpl_context as c, url, app_globals as g
 
from pylons.controllers.util import abort, redirect
 
from pylons.i18n.translation import _
 
from pylons_app.lib import helpers as h
 
from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator
 
from pylons_app.lib.base import BaseController, render
 
from pylons_app.lib.utils import repo2db_mapper, invalidate_cache
 
from pylons_app.model.db import User, UserLog
 
from pylons_app.model.forms import UserForm
 
from pylons_app.model.hg_model import HgModel
 
from pylons_app.model.user_model import UserModel
 
import formencode
 
import logging
 

	
 
log = logging.getLogger(__name__)
 

	
 
@@ -71,12 +73,26 @@ class SettingsController(BaseController)
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="PUT" />
 
        # Or using helpers:
 
        #    h.form(url('admin_setting', id=ID),
 
        #           method='put')
 
        # url('admin_setting', id=ID)
 
        if id == 'mapping':
 
            rm_obsolete = request.POST.get('destroy', False)
 
            log.debug('Rescanning directories with destroy=%s', rm_obsolete)
 

	
 
            initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
 
            repo2db_mapper(initial, rm_obsolete)
 
            invalidate_cache('cached_repo_list')
 
            
 
            
 
        return redirect(url('admin_settings'))
 

	
 

	
 

	
 

	
 

	
 
    def delete(self, id):
 
        """DELETE /admin/settings/id: Delete an existing item"""
 
        # Forms posted to this method should contain a hidden field:
 
        #    <input type="hidden" name="_method" value="DELETE" />
 
        # Or using helpers:
pylons_app/lib/utils.py
Show inline comments
 
@@ -174,17 +174,16 @@ class EmptyChangeset(BaseChangeset):
 
        Returns raw string identifing this changeset, useful for web
 
        representation.
 
        """
 
        return '0' * 12
 

	
 

	
 
def repo2db_mapper(initial_repo_list):
 
def repo2db_mapper(initial_repo_list, remove_obsolete=False):
 
    """
 
    maps all found repositories into db
 
    """
 
    from pylons_app.model.meta import Session
 
    from pylons_app.model.repo_model import RepoModel
 
    
 
    sa = Session()
 
    user = sa.query(User).filter(User.admin == True).first()
 
    
 
    rm = RepoModel()
 
@@ -197,6 +196,15 @@ def repo2db_mapper(initial_repo_list):
 
                         'repo_name':name,
 
                         'description':repo.description if repo.description != 'unknown' else \
 
                                        'auto description for %s' % name,
 
                         'private':False
 
                         }
 
            rm.create(form_data, user, just_db=True)
 

	
 

	
 
    if remove_obsolete:
 
        #remove from database those repositories that are not in the filesystem
 
        for repo in sa.query(Repository).all():
 
            if repo.repo_name not in initial_repo_list.keys():
 
                sa.delete(repo)
 
                sa.commit()
 

	
pylons_app/templates/admin/settings/settings.html
Show inline comments
 
@@ -13,9 +13,41 @@
 
	${self.menu('admin')}
 
	${self.submenu('settings')}
 
</%def>
 
<%def name="main()">
 
	<div>
 
	<h2>${_('Settings administration')}</h2>
 
	
 

	
 
     ${h.form(url('admin_setting', id='mapping'),method='put')}
 
       <table class="table_disp">
 
           <tr class="header">
 
            <td colspan="2">${_('Remap andv rescan repositories')}</td>
 
           </tr>
 
           <tr align="right">
 
            <td><span class="tooltip" tooltip_title="${h.tooltip(_('In case a repository was deleted from filesystem and there are leftovers in the database check this option to scan obsolete data in database and remove it.'))}">
 
            ${_('destroy old data')}</span> ${h.checkbox('destroy',True)}</td>
 
            <td>${h.submit('rescan','rescan repositories')}</td>   
 
       </table>
 
     ${h.end_form()}
 
     <br/>	
 
     ${h.form(url('admin_setting', id='global'),method='put')}
 
	   <table class="table_disp">
 
	       <tr class="header">
 
	           <td colspan="3">${_('Global application settings')}</td>
 
	       </tr>
 
	       <tr>
 
	           <td>${_('Application name')}</td>
 
	           <td>${h.text('app_title')}</td>
 
	       </tr>
 
           <tr>
 
               <td>${_('Realm text')}</td>
 
               <td>${h.text('app_auth_realm')}</td>
 
           </tr>
 
           <tr>
 
	           <td></td>
 
	           <td>${h.submit('save','save settings')}</td>   
 
           </tr>
 
	   </table>
 
     ${h.end_form()}
 
    
 
    </div>
 
</%def>    
0 comments (0 inline, 0 general)