"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.3.1/buildbot/data/logs.py" (23 May 2019, 5209 Bytes) of package /linux/misc/buildbot-2.3.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 "logs.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.0.1_vs_2.1.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 
   17 from twisted.internet import defer
   18 
   19 from buildbot.data import base
   20 from buildbot.data import types
   21 from buildbot.util import identifiers
   22 
   23 
   24 class EndpointMixin:
   25 
   26     def db2data(self, dbdict):
   27         data = {
   28             'logid': dbdict['id'],
   29             'name': dbdict['name'],
   30             'slug': dbdict['slug'],
   31             'stepid': dbdict['stepid'],
   32             'complete': dbdict['complete'],
   33             'num_lines': dbdict['num_lines'],
   34             'type': dbdict['type'],
   35         }
   36         return defer.succeed(data)
   37 
   38 
   39 class LogEndpoint(EndpointMixin, base.BuildNestingMixin, base.Endpoint):
   40 
   41     isCollection = False
   42     pathPatterns = """
   43         /logs/n:logid
   44         /steps/n:stepid/logs/i:log_slug
   45         /builds/n:buildid/steps/i:step_name/logs/i:log_slug
   46         /builds/n:buildid/steps/n:step_number/logs/i:log_slug
   47         /builders/n:builderid/builds/n:build_number/steps/i:step_name/logs/i:log_slug
   48         /builders/n:builderid/builds/n:build_number/steps/n:step_number/logs/i:log_slug
   49         /builders/i:buildername/builds/n:build_number/steps/i:step_name/logs/i:log_slug
   50         /builders/i:buildername/builds/n:build_number/steps/n:step_number/logs/i:log_slug
   51     """
   52 
   53     @defer.inlineCallbacks
   54     def get(self, resultSpec, kwargs):
   55         if 'logid' in kwargs:
   56             dbdict = yield self.master.db.logs.getLog(kwargs['logid'])
   57             return (yield self.db2data(dbdict)) if dbdict else None
   58 
   59         stepid = yield self.getStepid(kwargs)
   60         if stepid is None:
   61             return
   62 
   63         dbdict = yield self.master.db.logs.getLogBySlug(stepid,
   64                                                         kwargs.get('log_slug'))
   65         return (yield self.db2data(dbdict)) if dbdict else None
   66 
   67 
   68 class LogsEndpoint(EndpointMixin, base.BuildNestingMixin, base.Endpoint):
   69 
   70     isCollection = True
   71     pathPatterns = """
   72         /steps/n:stepid/logs
   73         /builds/n:buildid/steps/i:step_name/logs
   74         /builds/n:buildid/steps/n:step_number/logs
   75         /builders/n:builderid/builds/n:build_number/steps/i:step_name/logs
   76         /builders/n:builderid/builds/n:build_number/steps/n:step_number/logs
   77         /builders/i:buildername/builds/n:build_number/steps/i:step_name/logs
   78         /builders/i:buildername/builds/n:build_number/steps/n:step_number/logs
   79     """
   80 
   81     @defer.inlineCallbacks
   82     def get(self, resultSpec, kwargs):
   83         stepid = yield self.getStepid(kwargs)
   84         if not stepid:
   85             return []
   86         logs = yield self.master.db.logs.getLogs(stepid=stepid)
   87         results = []
   88         for dbdict in logs:
   89             results.append((yield self.db2data(dbdict)))
   90         return results
   91 
   92 
   93 class Log(base.ResourceType):
   94 
   95     name = "log"
   96     plural = "logs"
   97     endpoints = [LogEndpoint, LogsEndpoint]
   98     keyFields = ['stepid', 'logid']
   99     eventPathPatterns = """
  100         /logs/:logid
  101         /steps/:stepid/logs/:slug
  102     """
  103 
  104     class EntityType(types.Entity):
  105         logid = types.Integer()
  106         name = types.String()
  107         slug = types.Identifier(50)
  108         stepid = types.Integer()
  109         complete = types.Boolean()
  110         num_lines = types.Integer()
  111         type = types.Identifier(1)
  112     entityType = EntityType(name)
  113 
  114     @defer.inlineCallbacks
  115     def generateEvent(self, _id, event):
  116         # get the build and munge the result for the notification
  117         build = yield self.master.data.get(('logs', str(_id)))
  118         self.produceEvent(build, event)
  119 
  120     @base.updateMethod
  121     @defer.inlineCallbacks
  122     def addLog(self, stepid, name, type):
  123         slug = identifiers.forceIdentifier(50, name)
  124         while True:
  125             try:
  126                 logid = yield self.master.db.logs.addLog(
  127                     stepid=stepid, name=name, slug=slug, type=type)
  128             except KeyError:
  129                 slug = identifiers.incrementIdentifier(50, slug)
  130                 continue
  131             self.generateEvent(logid, "new")
  132             return logid
  133 
  134     @base.updateMethod
  135     @defer.inlineCallbacks
  136     def appendLog(self, logid, content):
  137         res = yield self.master.db.logs.appendLog(logid=logid, content=content)
  138         self.generateEvent(logid, "append")
  139         return res
  140 
  141     @base.updateMethod
  142     @defer.inlineCallbacks
  143     def finishLog(self, logid):
  144         res = yield self.master.db.logs.finishLog(logid=logid)
  145         self.generateEvent(logid, "finished")
  146         return res
  147 
  148     @base.updateMethod
  149     def compressLog(self, logid):
  150         return self.master.db.logs.compressLog(logid=logid)