[Python-checkins] r88767 - in tracker/instances/python-dev: extensions/create_patch.py html/issue.item.html schema.py

martin.v.loewis python-checkins at python.org
Sun Mar 13 14:59:31 CET 2011


Author: martin.v.loewis
Date: Sun Mar 13 14:59:30 2011
New Revision: 88767

Log:
Add mercurial branches to issues.


Added:
   tracker/instances/python-dev/extensions/create_patch.py
Modified:
   tracker/instances/python-dev/html/issue.item.html
   tracker/instances/python-dev/schema.py

Added: tracker/instances/python-dev/extensions/create_patch.py
==============================================================================
--- (empty file)
+++ tracker/instances/python-dev/extensions/create_patch.py	Sun Mar 13 14:59:30 2011
@@ -0,0 +1,66 @@
+import os, tempfile
+from roundup.cgi.actions import Action
+
+class NotChanged(ValueError):
+    pass
+
+def download_patch(source, lastrev):
+    from mercurial import hg, ui, localrepo, commands, bundlerepo
+    UI = ui.ui()
+    bundle = tempfile.mktemp()
+    cwd = os.getcwd()
+    os.chdir(base)
+    try:
+    	repo0 = hg.repository(UI,base)
+        repo0.ui.quiet=True
+        repo0.ui.pushbuffer()
+        commands.pull(repo0.ui, repo0, quiet=True)
+        commands.incoming(repo0.ui, repo0, source=source, branch=['default'], bundle=bundle, force=False)
+        rhead = repo0.ui.popbuffer()
+        if rhead:
+            rhead = rhead.split(':')[1]
+        if rhead == 'lastrev':
+            raise NotChanged
+        repo=bundlerepo.bundlerepository(UI, ".", bundle)
+        repo.ui.pushbuffer()
+        commands.diff(repo.ui, repo, rev=['ancestor(.,default)', 'default'])
+        result = repo.ui.popbuffer()
+    finally:
+        os.chdir(cwd)
+    return result, rhead
+
+class CreatePatch(Action):
+    def handle(self):
+        db = self.db
+        if not self.hasPermission('Create', 'file'):
+            raise exceptions.Unauthorised, self._(
+                "You do not have permission to create files")
+        if self.classname != 'issue':
+            raise Reject, "create_patch is only useful for issues"
+        if not self.form.has_key('@repo'):
+            self.client.error_message.append('hgrepo missing')
+            return
+        repo = self.form['@repo'].value
+        url = db.hgrepo.get(repo, 'url')
+        if not url:
+            self.client.error_message.append('unknown hgrepo url')
+            return
+        lastrev = db.hgrepo.get(repo, 'lastrev')
+        try:
+            diff, head = download_patch(url, lastrev)
+        except NotChanged:
+            self.client.error_message.append('%s is already available' % head)
+            return
+        fileid = db.file.create(name='default.diff',
+                                type='text/plain',
+                                content=diff)
+        files = db.issue.get(self.nodeid, 'files')
+        files.append(fileid)
+        db.issue.set(self.nodeid, files=files)
+        db.hgrepo.set(repo, lastrev=head)
+        db.commit()
+
+def init(instance):
+    global base
+    base = os.path.join(instance.tracker_home, 'cpython')
+    instance.registerAction('create_patch', CreatePatch) 

Modified: tracker/instances/python-dev/html/issue.item.html
==============================================================================
--- tracker/instances/python-dev/html/issue.item.html	(original)
+++ tracker/instances/python-dev/html/issue.item.html	Sun Mar 13 14:59:30 2011
@@ -197,6 +197,15 @@
  <th><tal:block i18n:translate="">File Description</tal:block>:</th>
  <td colspan=3><input type="edit" name="file-1 at description" size="40"></td>
 </tr>
+
+<tr tal:condition="context/is_edit_ok">
+ <th colspan=2><tal:block i18n:translate="">Mercurial Repo containing patches</tal:block>:</th>
+ <td colspan=2>
+  <input type="hidden" name="@link at hgrepos" value="hgrepo-1">
+   <input name="hgrepo-1 at url" size="60">
+ </td>
+</tr>
+
 </table>
 </fieldset>
 <table class="form">
@@ -258,6 +267,24 @@
  </tr>
 </table>
 
+<table class="files" tal:condition="context/hgrepos">
+ <tr><th class="Header" colspan="2">Repositories containing patches</th></tr>
+ <tr tal:repeat="hgrepo python:context.hgrepos.sorted('creation')">
+  <td>
+   <a tal:attributes="href hgrepo/url"
+      tal:content="hgrepo/url">link</a>
+  </td>
+  <td>
+   <form style="padding:0" method="post" tal:condition="context/is_edit_ok"
+         tal:attributes="action string:issue${context/id}">
+   <input type="hidden" name="@action" value="create_patch">
+    <input type="hidden" name="@repo" tal:attributes="value hgrepo/id">
+    <input type="submit" value="Create Patch" i18n:attributes="value">
+   </form>
+ </td>
+ </tr>
+</table>
+
 <table class="messages" tal:condition="context/messages">
  <tr><th colspan="4" class="header"
          tal:content="python:'Messages (%d)' % context.message_count"

Modified: tracker/instances/python-dev/schema.py
==============================================================================
--- tracker/instances/python-dev/schema.py	(original)
+++ tracker/instances/python-dev/schema.py	Sun Mar 13 14:59:30 2011
@@ -141,6 +141,10 @@
                  # patchset exists for the issue
                  patchset=String(),)
 
+hgrepo = Class(db, "hgrepo",
+                   url=String(),
+                   lastrev=String())
+
 # IssueClass automatically gets these properties in addition to the Class ones:
 #   title = String()
 #   messages = Multilink("msg")
@@ -161,7 +165,8 @@
                    keywords=Multilink("keyword"),
                    stage=Link('stage'),
                    nosy_count=Number(),
-                   message_count=Number())
+                   message_count=Number(),
+                   hgrepos=Multilink('hgrepo'))
 
 #
 # TRACKER SECURITY SETTINGS
@@ -189,10 +194,15 @@
 
 for cl in ('issue_type', 'severity', 'component',
            'version', 'priority', 'stage', 'status', 'resolution',
-           'issue', 'keyword'):
+           'issue', 'keyword', 'hgrepo'):
     db.security.addPermissionToRole('User', 'View', cl)
     db.security.addPermissionToRole('Anonymous', 'View', cl)
 
+db.security.addPermissionToRole('User', 'Create', 'hgrepo')
+p = db.security.addPermission(name='Edit', klass='hgrepo',
+                              properties=['url'])
+db.security.addPermissionToRole('User', p)
+
 class may_view_spam:
     def __init__(self, klassname):
         self.klassname = klassname
@@ -260,7 +270,7 @@
                               properties=('title', 'type',
                                           'components', 'versions',
                                           'severity',
-                                          'messages', 'files', 'nosy'),
+                                          'messages', 'files', 'nosy', 'hgrepos'),
                               description='User can report and discuss issues')
 db.security.addPermissionToRole('User', p)
 


More information about the Python-checkins mailing list