"Fossies" - the Fresh Open Source Software Archive

Member "svnchecker-0.3/checks/Mantis.py" (12 Mar 2008, 2067 Bytes) of package /linux/privat/old/svnchecker-0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "Mantis.py" see the Fossies "Dox" file reference documentation.

    1 # pylint: disable-msg=W0612
    2 
    3 # Copyright 2008 German Aerospace Center (DLR)
    4 #
    5 # Licensed under the Apache License, Version 2.0 (the "License");
    6 # you may not use this file except in compliance with the License.
    7 # You may obtain a copy of the License at
    8 #
    9 #     http://www.apache.org/licenses/LICENSE-2.0
   10 #
   11 # Unless required by applicable law or agreed to in writing, software
   12 # distributed under the License is distributed on an "AS IS" BASIS,
   13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14 # See the License for the specific language governing permissions and
   15 # limitations under the License.
   16 
   17 """
   18 Checks if a log message contains one or more valid MANTIS ID,
   19 with a MANTIS ID <#> that is set to status 'in_progress' and
   20 handled by the correct user.
   21 """
   22 
   23 from modules import Mantis
   24 import re
   25 
   26 def run(transaction, config):
   27 
   28     mantis = Mantis.Mantis(config)
   29 
   30     logMessage = transaction.getCommitMsg()
   31     pattern = re.compile('MANTIS([:#]|[\s\-_]ID) ([0-9]+)')
   32     result = pattern.findall(logMessage)
   33 
   34     checkInProgress = config.getBoolean("Mantis.CheckInProgress", True)
   35     checkHandler = config.getBoolean("Mantis.CheckHandler", True)
   36 
   37     if len(result) == 0:
   38         msg = "Invalid log message: The message must contain 'MANTIS ID <#>'!"
   39         return (msg, 1)
   40 
   41     msg = ""
   42     exitCode = 0
   43 
   44     for (splitter, issueId) in result:
   45         if not mantis.issueExists(issueId):
   46             msg = "MANTIS ID %s not found!" % issueId
   47             exitCode = 1
   48             break
   49 
   50         if checkInProgress:
   51             status = mantis.issueGetStatus(issueId)
   52             if status != "in_progress":
   53                 msg = "MANTIS ID %s is not 'in_progress'!" % issueId
   54                 exitCode = 1
   55                 break
   56 
   57         if checkHandler:
   58             user = transaction.getUserID()
   59             handler = mantis.issueGetHandler(issueId)
   60 
   61             if (user != handler):
   62                 msg = "You are not the handler of MANTIS ID %s!" % issueId
   63                 exitCode = 1
   64                 break
   65 
   66     return (msg, exitCode)