Edgewall Software

Ticket #2382: admin-resync.diff

File admin-resync.diff, 3.6 KB (added by Manuzhai, 3 years ago)

Adds a Resynchronization module to WebAdmin.

  • webadmin/htdocs/css/admin.css

     
    1919 min-height: 300px; 
    2020} 
    2121p.help { color: #666; font-size: 90%; margin: 1em .5em .5em } 
     22p.success { color: #080; } 
    2223 
    2324form.addnew { clear: right; float: right; margin: -2em 0 4em; width: 33% } 
    2425form.mod { margin-top: 1em; } 
  • webadmin/__init__.py

     
    44from webadmin.perm import * 
    55from webadmin.plugin import * 
    66from webadmin.ticket import * 
     7from webadmin.resync import * 
  • webadmin/resync.py

     
     1# -*- coding: iso8859-1 -*- 
     2# 
     3# Copyright (C) 2005 Edgewall Software 
     4# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de> 
     5# All rights reserved. 
     6# 
     7# This software is licensed as described in the file COPYING, which 
     8# you should have received as part of this distribution. The terms 
     9# are also available at http://trac.edgewall.com/license.html. 
     10# 
     11# This software consists of voluntary contributions made by many 
     12# individuals. For the exact contribution history, see the revision 
     13# history and logs, available at http://projects.edgewall.com/trac/. 
     14# 
     15# Author: Manuzhai <manuzhai@gmail.com> 
     16 
     17import os 
     18 
     19from trac.core import * 
     20from webadmin.web_ui import IAdminPageProvider 
     21 
     22__all__ = [] 
     23 
     24class ResyncAdminPage(Component): 
     25 
     26    implements(IAdminPageProvider) 
     27 
     28    # IAdminPageProvider methods 
     29 
     30    def get_admin_pages(self, req): 
     31        if (req.perm.has_permission('TRAC_ADMIN') and 
     32            hasattr(self.env.get_repository(), 'sync')): 
     33                yield ('general', 'General', 'resync', 'Resynchronization') 
     34     
     35    def do_resync(self): 
     36        cnx = self.env.get_db_cnx() 
     37        cursor = cnx.cursor() 
     38        cursor.execute("DELETE FROM revision") 
     39        cursor.execute("DELETE FROM node_change") 
     40        repos = self.env.get_repository() 
     41        cursor.execute("DELETE FROM system WHERE name='repository_dir'") 
     42        cursor.execute("INSERT INTO system (name,value) " 
     43                       "VALUES ('repository_dir',%s)", (repos.name,)) 
     44        repos.sync() 
     45     
     46    def process_admin_request(self, req, cat, page, path_info): 
     47        if req.method == 'POST': 
     48            self.do_resync() 
     49            req.hdf['resync.results'] = 'The environment has been synchronized.' 
     50         
     51        return 'admin_resync.cs', None 
  • webadmin/templates/admin_resync.cs

    Property changes on: webadmin/resync.py
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    
     
     1<h2>Resynchronization</h2> 
     2 
     3<form class="mod" id="modresync" method="post"> 
     4  <?cs if:resync.results ?> 
     5    <p class="success"><?cs var:resync.results ?></p> 
     6  <?cs /if ?> 
     7  <p>Click 'Resynchronize' below to resynchronize the Trac 
     8  environment with the version control repository.</p> 
     9 <div class="buttons"> 
     10  <input type="submit" value="Resynchronize"> 
     11 </div> 
     12</form>