[ScryMUD] SVN Commit Info r838 - in trunk/tools/python: . scrymud

scrymud at wanfear.com scrymud at wanfear.com
Wed Jul 5 17:22:58 PDT 2006


Author: eroper
Date: 2006-07-05 17:22:57 -0700 (Wed, 05 Jul 2006)
New Revision: 838

Added:
   trunk/tools/python/feedJira.py
   trunk/tools/python/jellyWriter.py
Modified:
   trunk/tools/python/scrymud/util.py
Log:
Additions:

    jellyWriter.py: Used to perform an initial import of BC_BUGS/BC_IDEAS data
                    in to the Jira issue-tracking software.
                    
    feedJira.py   : After the initial import this script can be used to add
                    new bugs/ideas into Jira using the SOAP interface. This
                    importer is not designed to handle states other than open.

Added scrymud.utils.termedRead() to handle '~' terminated fields in various
ScryMUD files.


Added: trunk/tools/python/feedJira.py
===================================================================
--- trunk/tools/python/feedJira.py	2006-07-01 07:33:22 UTC (rev 837)
+++ trunk/tools/python/feedJira.py	2006-07-06 00:22:57 UTC (rev 838)
@@ -0,0 +1,132 @@
+#!/usr/bin/env python
+# $Id$
+# Copyright (C) 2006, Edward Roper <edro+scrymud at wanfear.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+"""
+Reads a configurable list of BC_BUGS, BC_IDEAS files and imports the issues
+into a Jira (http://atlassian.com/) installation via. SOAP.
+"""
+
+# User tuneable ##############################################################
+
+# Configure the username/password of the Jira account to use.
+jira_user = ''
+jira_pass = ''
+
+# This is discoverable in the Jira custom-field administration by
+# "configuring" the room number custom field and observing the
+# value in the customFieldId attribute of the GET URL.
+custom_field_id_room_num = 10000
+
+# URL to the Jira SOAP service. Don't forget to enable the service.
+soap_url = 'http://bugs.scrymud.net/rpc/soap/jirasoapservice-v2?wsdl'
+
+# sources is an array of tuples: ( Scry_World_Path, Jira_Project_ID )
+sources = [ ( '/home/scrymud/muds/mud/grrmud/World', 'TST' ),
+#            ( '/home/scrymud/muds/mud_dev/grrmud/World', 'TST'),
+          ]
+
+# Map ScryMUD(left-hand) status to Jira(right-hand) status
+# This isn't used at the moment. I'm leaving it here, commented out
+# for my own sanity in the near future.
+#status_map = { 0:1, # open       -> open
+#               1:1, # assigned   -> open
+#               2:5, # retest     -> resolved
+#               3:6, # closed     -> closed
+#               4:1, # deferred   -> open
+#               5:1, # all        -> open (have no idea what all means)
+#               6:1, # none       -> open (have no idea what none means)
+#               7:1, # high_state -> open (have no idea what high_state means)
+#             }
+
+# End user tuneable ##########################################################
+
+# Notes on Jira-Enterprise defaults (I think they're default anyway )#########
+# Issue-Types:
+#     1: Bug
+#     2: New Feature
+#     3: Task
+#     4: Improvement
+#
+# Priorities:
+#     1: Blocker
+#     2: Critical
+#     3: Major
+#     4: Minor
+#     5: Trivial
+#
+# Resolutions:
+#     1: Fixed
+#     2: Won't Fix
+#     3: Duplicate
+#     4: Incomplete
+#     5: Cannot Reproduce
+#
+# Statuses:
+#     1: Open
+#     2:
+#     3: In Progress
+#     4: Reopened
+#     5: Resolved
+#     6: Closed
+##############################################################################
+
+import SOAPpy, getpass, datetime
+from scrymud.bugs import *
+
+room_num_id = "customfield_%d" %(custom_field_id_room_num)
+
+soap = SOAPpy.WSDL.Proxy(soap_url)
+soap_auth = soap.login(jira_user, jira_pass)
+
+for (bugPath, project) in sources:
+
+    # This temporary list is probably overkill ;)
+    bugFiles = list()
+    bugFiles.append(bugPath + '/BC_BUGS')
+    bugFiles.append(bugPath + '/BC_IDEAS')
+
+    # For each "source" handle both "BC_BUGS" and "BC_IDEAS"
+    for bugFile in bugFiles:
+        myBugs = bugList(bugFile)
+
+        # Set the type of issue based on the source file.
+        if ( bugFile[-7:] == 'BC_BUGS' ):
+            bugType = 1
+        elif ( bugFile[-8:] == 'BC_IDEAS' ):
+            bugType = 4
+        else:
+            raise ValueError, "unexpected bugFile; not BC_BUGS or BC_IDEAS"
+
+        for bug in myBugs:
+            new_bug = soap.createIssue(soap_auth, {
+                                                   'project': project,
+                                                   'type'   : str(bugType),
+                                                   'summary': bug.summary,
+                                                  } )
+            # Add the bug comments, if applicable.
+            for comment in bug.comments:
+                soap.addComment(soap_auth, new_bug['key'], { 'body': "[%s]\n%s" %(comment.reporter, comment.report) })
+
+            # Set the room number and status.
+            soap.updateIssue(soap_auth, new_bug['key'], [ {'id':room_num_id, 'values':[str(bug.roomNum)] },
+                                                          {'id':'description', 'values':[ "[%s]\n%s" %(bug.reporter, bug.summary) ] },
+                                                          {'id':'issuetype', 'values':[str(bugType)] },
+                                                          {'id':'priority', 'values':['4'] },
+                                                        ] )
+
+
+soap.logout(soap_auth)


Property changes on: trunk/tools/python/feedJira.py
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/tools/python/jellyWriter.py
===================================================================
--- trunk/tools/python/jellyWriter.py	2006-07-01 07:33:22 UTC (rev 837)
+++ trunk/tools/python/jellyWriter.py	2006-07-06 00:22:57 UTC (rev 838)
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+# $Id$
+# Copyright (C) 2006, Edward Roper <edro+scrymud at wanfear.net>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+"""
+This program generates a Jelly script for importing existing BC_BUGS
+and BC_IDEAS files into Jira. This is really only intended to be run
+once, for an initial import. Subsequent updates should be performed
+using feedJira.py which utilizes Jira's SOAP interface.
+"""
+
+# [ Configuration ] ##########################################################
+
+jira_project_id = "TST"
+
+sources = { "/home/scrymud/muds/mud/grrmud/World/BC_BUGS":"Bug",
+            "/home/scrymud/muds/mud_dev/grrmud/World/BC_BUGS":"Bug",
+            "/home/scrymud/muds/mud/grrmud/World/BC_IDEAS":"New Feature",
+            "/home/scrymud/muds/mud_dev/grrmud/World/BC_IDEAS":"New Feature",
+          }
+
+##############################################################################
+
+tplIssue = """
+<jira:CreateIssue project-key="%s" issueType="%s" summary="%s" issueKeyVar="key" issueIdVar="id" priority="%s" created="%s" updated="%s" description="%s" reporter="mud">
+<jira:AddCustomFieldValue id="customfield_10000" value="%d"/>
+</jira:CreateIssue>
+"""
+
+tplComment = """<jira:AddComment comment="%s" issue-key="${key}" created="%s" reporter="mud"/>"""
+
+tplWorkflow = """<jira:TransitionWorkflow key="${key}" workflowAction="%s" resolution="Fixed"/>"""
+
+def cheezyEscape(input):
+    """Because I didn't have much luck figuring out how to make the various
+    python XML generate XML trees."""
+    
+    output = input.replace("&",'&amp;')
+    output = output.replace('"','&quot;')
+    output = output.replace('\n','&#10;')
+    output = output.replace('<','&lt;')
+    output = output.replace('<','&gt;')
+    output = output.replace('\'','&apos;')
+    output = output.replace('[','&#91;')
+    output = output.replace(']','&#93;')
+    return(output)
+
+
+from scrymud.bugs import *
+
+if ( __name__ == '__main__' ):
+    print """<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.JiraTagLib">"""
+
+    for (filePath, fileType) in sources.iteritems():
+        myBugs = bugList(filePath)
+        for bug in myBugs:
+
+            if ( bug.summary == '' ):
+                sys.stderr.write("WARNING %s:bug-%d has no summary.\n" %(filePath, bug.bugNum))
+                bug.summary = "[ScryBUG:%s:%d][no summary available]" %(filePath, bug.bugNum)
+
+            print tplIssue %( jira_project_id, fileType, cheezyEscape(bug.summary[:254]), "Minor", time.strftime("%Y-%m-%d %H:%M:%S.0",bug.date),
+                              time.strftime("%Y-%m-%d %H:%M:%S.0",bug.getLastUpdate()), cheezyEscape("[%s]\n%s"%(bug.reporter.strip(), bug.summary)), bug.roomNum )
+            for comment in bug.comments:
+                print tplComment %( cheezyEscape("[%s]\n%s"%(comment.reporter.strip(), comment.report)), time.strftime("%Y-%m-%d %H:%M:%S.0",comment.date))
+
+            if ( bug.state == 2 ):
+                print tplWorkflow %("Resolve issue")
+            elif ( bug.state == 3):
+                print tplWorkflow %("Close issue")
+
+    print """</JiraJelly>"""


Property changes on: trunk/tools/python/jellyWriter.py
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/tools/python/scrymud/util.py
===================================================================
--- trunk/tools/python/scrymud/util.py	2006-07-01 07:33:22 UTC (rev 837)
+++ trunk/tools/python/scrymud/util.py	2006-07-06 00:22:57 UTC (rev 838)
@@ -18,23 +18,39 @@
 """Various small utility functions"""
 
 def paragraphs(str, seperator=None):
-   """Can be used as an iterator, returning one paragraph at a time from a body
-      of text.
-   """
-   if not callable(seperator):
-      if ( seperator != None ): raise TypeError, "seperator must return bool"
-      def seperator(line): return line == '\n'
-   paragraph = []
-   for line in str.splitlines(True):
-      if seperator(line):
-         if paragraph:
-            yield "".join(paragraph)
-            paragraph = [];
-      else:
-         paragraph.append(line)
-   if paragraph: yield "".join(paragraph)
+    """Can be used as an iterator, returning one paragraph at a time from a body
+       of text.
+    """
+    if not callable(seperator):
+       if ( seperator != None ): raise TypeError, "seperator must return bool"
+       def seperator(line): return line == '\n'
+    paragraph = []
+    for line in str.splitlines(True):
+       if seperator(line):
+          if paragraph:
+             yield "".join(paragraph)
+             paragraph = [];
+       else:
+          paragraph.append(line)
+    if paragraph: yield "".join(paragraph)
 
+def termedRead(f):
+    """
+    A common serialization format found in ScryMUD files is a section of
+    multi-line text that ends with a '~' on a line by itself. This function,
+    given a file object will read until that "terminated" line, returning a
+    string.
+    """
+    buf = ""
+    while ( True ):
+        tmp = f.readline()
+        if ( tmp[0:1] == "~" ):
+            break
+        else:
+            buf += tmp
+    return(buf[:-1]) # we have an extra newline
+
 # This exists because I am too brain dead to come up with a better way
 # to build help indexes. --eroper
 alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
-	     "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ]
+             "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ]




More information about the ScryMUD mailing list