Changeset 2407

Show
Ignore:
Timestamp:
07/07/07 15:56:37 (2 years ago)
Author:
Bombenbodo
Message:

TracSvnHooksPlugin:

new layout, more hocks + tools, additional docs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tracsvnhooksplugin/0.10/setup.py

    r2386 r2407  
    22 
    33PACKAGE = 'TracSVNHooks' 
    4 VERSION = '0.1
     4VERSION = '0.2
    55 
    66setup( 
  • tracsvnhooksplugin/0.10/svnhooks/svnhooks.py

    r2386 r2407  
    22from trac.web.chrome import ITemplateProvider, add_stylesheet 
    33from webadmin.web_ui import IAdminPageProvider 
     4from webadmin.plugin import TRAC_PATH 
    45from trac.config import Option 
    56import string 
     
    1112  'post-revprop-change': '', 
    1213  'pre-revprop-change' : '', 
    13   'start-commit'       : 'There is a bug in some versions of SVN connected to the start-commit hook! By filling the form you *have* to enable the hook.' 
     14  'start-commit'       : 'There is a bug in some versions of SVN connected to the start-commit hook! By filling the form you *have* to enable the hook.', 
     15  'pre-lock'           : '', 
     16  'post-lock'          : '', 
     17  'pre-unlock'         : '', 
     18  'post-unlock'        : '' 
    1419} 
    1520 
     
    2025    def get_admin_pages(self, req): 
    2126        if req.perm.has_permission('TRAC_ADMIN'): 
    22             for section in SECTIONS.keys(): 
    23                 yield ('svn', 'SVN Hooks', section, section) 
     27            yield ('svn', 'Subversion', 'hooks', 'Hooks') 
    2428 
    2529    def process_admin_request(self, req, cat, page, path_info): 
    2630        assert req.perm.has_permission('TRAC_ADMIN') 
    27         if page not in SECTIONS.keys(): 
    28             raise TracError("Invalid section %s" % page) 
    2931 
     32        sections = SECTIONS.keys() 
     33        sections.sort() 
     34 
     35        # catch selected section 
     36        if req.method == 'POST' and req.args.get('sections'): 
     37          section = req.args.get('sections') 
     38        else: 
     39          section = sections[0] 
     40 
     41        # validate section 
     42        if section not in sections: 
     43            raise TracError("Invalid section %s" % section) 
     44 
     45        # get config vars 
    3046        repository_type = self.config.get('trac', 'repository_type').upper() 
    3147        repository_dir = self.config.get('trac', 'repository_dir') + os.sep + 'hooks' 
     48        base_url = self.config.get('trac', 'base_url') 
     49        project_name = self.config.get('project', 'name') 
     50        smtp_default_domain = self.config.get('notification', 'smtp_default_domain') 
     51        smtp_from = self.config.get('notification', 'smtp_from') 
     52        smtp_replyto = self.config.get('notification', 'smtp_replyto') 
    3253         
    3354        # repository type must be SVN 
     
    3960            raise TracError("Can't access repository hook directory %s" % repository_dir) 
    4061 
    41         tmplfile = repository_dir + os.sep + page + '.tmpl' 
    42         hookfile = repository_dir + os.sep + page 
     62        tmplfile = repository_dir + os.sep + section + '.tmpl' 
     63        hookfile = repository_dir + os.sep + section 
    4364 
    4465        # evaluate forms 
    4566        if req.method == 'POST': 
    4667          # Change status 
    47           if req.args.get('status'): 
    48             if req.args.get('status')==' Enable ': 
     68          if req.args.get('tooglestatus'): 
     69            if req.args.get('tooglestatus')==' Enable ': 
    4970              os.chmod(hookfile,0770) 
    5071            else: 
    5172              os.chmod(hookfile,0660) 
    52           if req.args.get('apply'): 
    53             if req.args.get('apply')==' Apply ': 
    54               current=req.args.get('current').strip()     
    55               if current: 
    56                 try: 
    57                   fp = open(hookfile,'w') 
    58                   fp.write(current) 
    59                   fp.close() 
    60                 except: 
    61                   raise TracError("Can't write repository hook %s" % hookfile) 
    62               else: 
    63                 try: 
    64                   os.remove(hookfile) 
    65                 except: 
    66                   pass 
    67           elif req.args.get('add'): 
    68             if req.args.get('add')==' Add ' and req.args.get('emails'): 
     73          if req.args.get('savehookfile'): 
     74            current=req.args.get('current').strip()     
     75            if current: 
     76              try: 
     77                fp = open(hookfile,'w') 
     78                fp.write(current) 
     79                fp.close() 
     80              except: 
     81                raise TracError("Can't write repository hook %s" % hookfile) 
     82            else: 
     83              try: 
     84                os.remove(hookfile) 
     85              except: 
     86                pass 
     87          elif req.args.get('addemail'): 
     88            if req.args.get('emails'): 
    6989              emails = req.args.get('emails') 
    7090              subject = req.args.get('subject') 
    7191              mfilter = req.args.get('filter') 
    7292              try: 
     93                fp = open(hookfile,'r') 
     94                current = fp.read() 
     95                fp.close() 
    7396                fp = open(hookfile,'a') 
     97                fp.writelines('\n') 
     98                if 'REPOS="$1"' not in current: 
     99                  fp.writelines('REPOS="$1"\n') 
     100                if 'REV="$2"' not in current: 
     101                  fp.writelines('REV="$2"\n') 
    74102                fp.writelines('/usr/lib/subversion/hook-scripts/commit-email.pl "$REPOS" "$REV" \\\n') 
     103                if smtp_from: 
     104                  fp.writelines('--from "'+smtp_from+'" \\\n') 
     105                if smtp_replyto: 
     106                  fp.writelines('-r "'+smtp_replyto+'" \\\n') 
     107                if smtp_default_domain: 
     108                  fp.writelines('-h "'+smtp_default_domain+'" \\\n') 
    75109                if mfilter: 
    76110                  fp.writelines('-m "'+mfilter+'" \\\n') 
     
    81115                fp.writelines('\n') 
    82116                fp.close() 
     117              except: 
     118                raise TracError("Can't write repository hook %s" % hookfile) 
     119          elif req.args.get('addtrac'): 
     120              try: 
     121                fp = open(hookfile,'r') 
     122                current = fp.read() 
     123                fp.close() 
     124                fp = open(hookfile,'a') 
     125                fp.writelines('\n') 
     126                if 'REPOS="$1"' not in current: 
     127                  fp.writelines('REPOS="$1"\n') 
     128                if 'REV="$2"' not in current: 
     129                  fp.writelines('REV="$2"\n') 
     130                if 'LOG=' not in current: 
     131                  fp.writelines('LOG=`/usr/bin/svnlook log -r $REV $REPOS`\n') 
     132                if 'AUTHOR=' not in current: 
     133                  fp.writelines('AUTHOR=`/usr/bin/svnlook author -r $REV $REPOS`\n') 
     134                if 'TRAC_ENV=' not in current: 
     135                  fp.writelines('TRAC_ENV="'+self.env.path+'"\n') 
     136                if 'TRAC_URL=' not in current: 
     137                  fp.writelines('TRAC_URL="'+base_url+'"\n') 
     138                fp.writelines('/usr/bin/python /usr/share/trac/contrib/trac-post-commit-hook \\\n') 
     139                fp.writelines('-p "$TRAC_ENV" \\\n') 
     140                fp.writelines('-r "$REV" \\\n') 
     141                fp.writelines('-u "$AUTHOR" \\\n') 
     142                fp.writelines('-m "$LOG" \\\n') 
     143                fp.writelines('-s "$TRAC_URL"\n') 
     144                fp.writelines('\n') 
    83145              except: 
    84146                raise TracError("Can't write repository hook %s" % hookfile) 
     
    105167          pass 
    106168 
    107         req.hdf['svnhooks.section'] = page 
     169        req.hdf['svnhooks.section'] = section 
     170        req.hdf['svnhooks.sections'] = sections 
    108171        req.hdf['svnhooks.status'] = os.access(hookfile,os.X_OK) 
    109172        req.hdf['svnhooks.current'] = current 
    110         req.hdf['svnhooks.note'] = SECTIONS[page] 
     173        req.hdf['svnhooks.note'] = SECTIONS[section] 
     174        req.hdf['svnhooks.project_name'] = project_name 
    111175        req.hdf['svnhooks.description'] = description 
    112176         
  • tracsvnhooksplugin/0.10/svnhooks/templates/svnhooks.cs

    r2386 r2407  
    1 <h2>Subversion <?cs var:svnhooks.section ?> hook</h2> 
     1<h2>Subversion: Hooks</h2> 
    22 
    3 <form id="status" class="addnew" method="post"> 
     3 
     4<form id="tooglestatus" class="addnew" method="post"> 
    45  <fieldset> 
    56    <legend>Status</legend> 
    6     <p>Hook <?cs var:svnhooks.section ?> is currently <b><?cs if:svnhooks.status ?>ACTIVE<?cs else ?>INACTIVE<?cs /if ?></b>.</p> 
     7    <p class="help">Hook <?cs var:svnhooks.section ?> is currently <b style="color: black;"><?cs if:svnhooks.status ?>ACTIVE<?cs else ?>INACTIVE<?cs /if ?></b>.</p> 
     8    <?cs if:svnhooks.note ?><p class="help" style="color: red;"><?cs var:svnhooks.note ?></p><?cs /if ?> 
    79    <div class="buttons"> 
    8       <input type="submit" name="status" <?cs if:svnhooks.status ?>disabled="disabled"<?cs /if ?> value=" Enable " /> 
    9       <input type="submit" name="status" <?cs if:svnhooks.status==0 ?>disabled="disabled"<?cs /if ?> value=" Disable " /> 
     10      <input type="submit" name="tooglestatus" <?cs if:svnhooks.status ?>disabled="disabled"<?cs /if ?> value=" Enable " /> 
     11      <input type="submit" name="tooglestatus" <?cs if:svnhooks.status==0 ?>disabled="disabled"<?cs /if ?> value=" Disable " /> 
     12      <input type="hidden" name="sections" value="<?cs var:svnhooks.section ?>" /> 
    1013    </div> 
    1114  </fieldset> 
    1215</form> 
    1316 
    14 <form id="addemail" class="addnew" method="post"> 
    15   <fieldset> 
    16     <legend>Append email notification</legend> 
    17     <div class="field"> 
    18       <label>Subject prefix:</label><br /> 
    19       <input type="text" name="subject" /> 
    20       <br /> 
    21       <label>Filter (perl regexp):</label><br /> 
    22       <input size="40" type="text" name="filter" /> 
    23       <br /> 
    24       <label>E-mails: </label><br /> 
    25       <textarea style="width: 100%" rows="5" type="text" name="emails"></textarea> 
    26       <br /> 
    27     </div> 
    28     <p class="help">Helper tool for the SVN email notification script.</p> 
    29     <div class="buttons"> 
    30       <input type="submit" name="add" value=" Add " /> 
    31     </div> 
    32   </fieldset> 
     17<?cs if:svnhooks.section=='post-commit' ?><?cs include:"addtrac.cs" ?><?cs /if ?> 
     18 
     19<?cs if:svnhooks.section=='post-commit' ?><?cs include:"addemail.cs" ?><?cs /if ?> 
     20<?cs if:svnhooks.section=='post-revprop-change' ?><?cs include:"addemail.cs" ?><?cs /if ?> 
     21 
     22 
     23<form id="changesection" method="post"> 
     24  <?cs call:hdf_select(svnhooks.sections, "sections", svnhooks.section, 0) ?>  
     25  <input type="submit" name="changesection" value=" Select " /> 
    3326</form> 
    3427 
    35 <?cs if:svnhooks.note ?><p><?cs var:svnhooks.note ?></p><?cs /if ?> 
    36 <form id="hook" method="post"> 
     28<form id="savehookfile" method="post"> 
    3729  <div class="field"> 
    3830    <textarea rows="20" style="width:63%" name="current"><?cs var:svnhooks.current ?></textarea> 
    3931  </div> 
    4032  <div class="buttons"> 
    41     <input type="submit" name="apply" value=" Apply " /> 
     33    <input type="hidden" name="sections" value="<?cs var:svnhooks.section ?>" /> 
     34    <input type="submit" name="savehookfile" value=" Apply changes " /> 
    4235    <input type="reset" value=" Reset " /> 
    4336  </div> 
    4437</form> 
    4538 
     39<br /> 
     40 
     41<h2>Documentation</h2> 
    4642<?cs if:svnhooks.description ?> 
    47 <br /> 
    48 <h2>Help for <?cs var:svnhooks.section ?> hook</h2> 
     43<h3><?cs var:svnhooks.section ?>.tmpl</h3> 
    4944<pre><?cs var:svnhooks.description ?></pre> 
    5045<?cs /if ?> 
     46<h3>Links</h3> 
     47<ul> 
     48  <li><a href="http://svnbook.red-bean.com/nightly/en/svn.ref.reposhooks.<?cs var:svnhooks.section ?>.html">http://svnbook.red-bean.com/nightly/en/svn.ref.reposhooks.<?cs var:svnhooks.section ?>.html</a></li> 
     49</ul>