Changeset 2407
- Timestamp:
- 07/07/07 15:56:37 (2 years ago)
- Files:
-
- tracsvnhooksplugin/0.10/setup.py (modified) (1 diff)
- tracsvnhooksplugin/0.10/svnhooks/svnhooks.py (modified) (6 diffs)
- tracsvnhooksplugin/0.10/svnhooks/templates/svnhooks.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracsvnhooksplugin/0.10/setup.py
r2386 r2407 2 2 3 3 PACKAGE = 'TracSVNHooks' 4 VERSION = '0. 1'4 VERSION = '0.2' 5 5 6 6 setup( tracsvnhooksplugin/0.10/svnhooks/svnhooks.py
r2386 r2407 2 2 from trac.web.chrome import ITemplateProvider, add_stylesheet 3 3 from webadmin.web_ui import IAdminPageProvider 4 from webadmin.plugin import TRAC_PATH 4 5 from trac.config import Option 5 6 import string … … 11 12 'post-revprop-change': '', 12 13 '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' : '' 14 19 } 15 20 … … 20 25 def get_admin_pages(self, req): 21 26 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') 24 28 25 29 def process_admin_request(self, req, cat, page, path_info): 26 30 assert req.perm.has_permission('TRAC_ADMIN') 27 if page not in SECTIONS.keys():28 raise TracError("Invalid section %s" % page)29 31 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 30 46 repository_type = self.config.get('trac', 'repository_type').upper() 31 47 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') 32 53 33 54 # repository type must be SVN … … 39 60 raise TracError("Can't access repository hook directory %s" % repository_dir) 40 61 41 tmplfile = repository_dir + os.sep + page+ '.tmpl'42 hookfile = repository_dir + os.sep + page62 tmplfile = repository_dir + os.sep + section + '.tmpl' 63 hookfile = repository_dir + os.sep + section 43 64 44 65 # evaluate forms 45 66 if req.method == 'POST': 46 67 # 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 ': 49 70 os.chmod(hookfile,0770) 50 71 else: 51 72 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'): 69 89 emails = req.args.get('emails') 70 90 subject = req.args.get('subject') 71 91 mfilter = req.args.get('filter') 72 92 try: 93 fp = open(hookfile,'r') 94 current = fp.read() 95 fp.close() 73 96 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') 74 102 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') 75 109 if mfilter: 76 110 fp.writelines('-m "'+mfilter+'" \\\n') … … 81 115 fp.writelines('\n') 82 116 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') 83 145 except: 84 146 raise TracError("Can't write repository hook %s" % hookfile) … … 105 167 pass 106 168 107 req.hdf['svnhooks.section'] = page 169 req.hdf['svnhooks.section'] = section 170 req.hdf['svnhooks.sections'] = sections 108 171 req.hdf['svnhooks.status'] = os.access(hookfile,os.X_OK) 109 172 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 111 175 req.hdf['svnhooks.description'] = description 112 176 tracsvnhooksplugin/0.10/svnhooks/templates/svnhooks.cs
r2386 r2407 1 <h2>Subversion <?cs var:svnhooks.section ?> hook</h2>1 <h2>Subversion: Hooks</h2> 2 2 3 <form id="status" class="addnew" method="post"> 3 4 <form id="tooglestatus" class="addnew" method="post"> 4 5 <fieldset> 5 6 <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 ?> 7 9 <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 ?>" /> 10 13 </div> 11 14 </fieldset> 12 15 </form> 13 16 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 " /> 33 26 </form> 34 27 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"> 37 29 <div class="field"> 38 30 <textarea rows="20" style="width:63%" name="current"><?cs var:svnhooks.current ?></textarea> 39 31 </div> 40 32 <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 " /> 42 35 <input type="reset" value=" Reset " /> 43 36 </div> 44 37 </form> 45 38 39 <br /> 40 41 <h2>Documentation</h2> 46 42 <?cs if:svnhooks.description ?> 47 <br /> 48 <h2>Help for <?cs var:svnhooks.section ?> hook</h2> 43 <h3><?cs var:svnhooks.section ?>.tmpl</h3> 49 44 <pre><?cs var:svnhooks.description ?></pre> 50 45 <?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>
