"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.5.1/buildbot/www/hooks/base.py" (24 Nov 2019, 3548 Bytes) of package /linux/misc/buildbot-2.5.1.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 "base.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.3.1_vs_2.4.0.

    1 # This file is part of Buildbot.  Buildbot is free software: you can
    2 # redistribute it and/or modify it under the terms of the GNU General Public
    3 # License as published by the Free Software Foundation, version 2.
    4 #
    5 # This program is distributed in the hope that it will be useful, but WITHOUT
    6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8 # details.
    9 #
   10 # You should have received a copy of the GNU General Public License along with
   11 # this program; if not, write to the Free Software Foundation, Inc., 51
   12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   13 #
   14 # Copyright Buildbot Team Members
   15 #
   16 # code inspired/copied from contrib/github_buildbot
   17 #  and inspired from code from the Chromium project
   18 # otherwise, Andrew Melo <andrew.melo@gmail.com> wrote the rest
   19 # but "the rest" is pretty minimal
   20 
   21 
   22 import json
   23 
   24 from buildbot.util import bytes2unicode
   25 
   26 
   27 class BaseHookHandler:
   28     def __init__(self, master, options):
   29         self.master = master
   30         self.options = options
   31 
   32     def getChanges(self, request):
   33         """
   34         Consumes a naive build notification (the default for now)
   35         basically, set POST variables to match commit object parameters:
   36         revision, revlink, comments, branch, who, files, links
   37 
   38         files, links and properties will be de-json'd, the rest are interpreted as strings
   39         """
   40 
   41         def firstOrNothing(value):
   42             """
   43             Small helper function to return the first value (if value is a list)
   44             or return the whole thing otherwise.
   45 
   46             Make sure to properly decode bytes to unicode strings.
   47             """
   48             if (isinstance(value, type([]))):
   49                 value = value[0]
   50             return bytes2unicode(value)
   51 
   52         args = request.args
   53         # first, convert files, links and properties
   54         files = None
   55         if args.get(b'files'):
   56             files = json.loads(firstOrNothing(args.get(b'files')))
   57         else:
   58             files = []
   59 
   60         properties = None
   61         if args.get(b'properties'):
   62             properties = json.loads(firstOrNothing(args.get(b'properties')))
   63         else:
   64             properties = {}
   65 
   66         revision = firstOrNothing(args.get(b'revision'))
   67         when = firstOrNothing(args.get(b'when_timestamp'))
   68         if when is None:
   69             when = firstOrNothing(args.get(b'when'))
   70         if when is not None:
   71             when = float(when)
   72         author = firstOrNothing(args.get(b'author'))
   73         if not author:
   74             author = firstOrNothing(args.get(b'who'))
   75         committer = firstOrNothing(args.get(b'committer'))
   76         comments = firstOrNothing(args.get(b'comments'))
   77         branch = firstOrNothing(args.get(b'branch'))
   78         category = firstOrNothing(args.get(b'category'))
   79         revlink = firstOrNothing(args.get(b'revlink'))
   80         repository = firstOrNothing(args.get(b'repository')) or ''
   81         project = firstOrNothing(args.get(b'project')) or ''
   82         codebase = firstOrNothing(args.get(b'codebase'))
   83 
   84         chdict = dict(author=author, committer=committer, files=files, comments=comments,
   85                       revision=revision, when_timestamp=when,
   86                       branch=branch, category=category, revlink=revlink,
   87                       properties=properties, repository=repository,
   88                       project=project, codebase=codebase)
   89         return ([chdict], None)
   90 
   91 
   92 base = BaseHookHandler  # alternate name for buildbot plugin