# HG changeset patch # User Marcin Kuzminski # Date 1279119079 -7200 # Node ID e8fc875467bdfcb79a56b81515c9bec00ca85c36 # Parent 40bccabf457467baf941146c2cd7fa34f78e8cf3 implemented manual repo rescann and remapping diff -r 40bccabf4574 -r e8fc875467bd pylons_app/controllers/admin/settings.py --- a/pylons_app/controllers/admin/settings.py Wed Jul 14 15:42:39 2010 +0200 +++ b/pylons_app/controllers/admin/settings.py Wed Jul 14 16:51:19 2010 +0200 @@ -23,14 +23,16 @@ @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 @@ -74,6 +76,20 @@ # 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""" diff -r 40bccabf4574 -r e8fc875467bd pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py Wed Jul 14 15:42:39 2010 +0200 +++ b/pylons_app/lib/utils.py Wed Jul 14 16:51:19 2010 +0200 @@ -177,11 +177,10 @@ 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() @@ -200,3 +199,12 @@ '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() + diff -r 40bccabf4574 -r e8fc875467bd pylons_app/templates/admin/settings/settings.html --- a/pylons_app/templates/admin/settings/settings.html Wed Jul 14 15:42:39 2010 +0200 +++ b/pylons_app/templates/admin/settings/settings.html Wed Jul 14 16:51:19 2010 +0200 @@ -16,6 +16,38 @@ <%def name="main()">

${_('Settings administration')}

- + + ${h.form(url('admin_setting', id='mapping'),method='put')} + + + + + + + +
${_('Remap andv rescan repositories')}
+ ${_('destroy old data')} ${h.checkbox('destroy',True)}${h.submit('rescan','rescan repositories')}
+ ${h.end_form()} +
+ ${h.form(url('admin_setting', id='global'),method='put')} + + + + + + + + + + + + + + + + +
${_('Global application settings')}
${_('Application name')}${h.text('app_title')}
${_('Realm text')}${h.text('app_auth_realm')}
${h.submit('save','save settings')}
+ ${h.end_form()} +