"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.5.1/buildbot/configurators/janitor.py" (24 Nov 2019, 3243 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 "janitor.py" see the Fossies "Dox" file reference documentation.

    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 import datetime
   17 
   18 from twisted.internet import defer
   19 
   20 from buildbot.config import BuilderConfig
   21 from buildbot.configurators import ConfiguratorBase
   22 from buildbot.process.buildstep import BuildStep
   23 from buildbot.process.factory import BuildFactory
   24 from buildbot.process.results import SUCCESS
   25 from buildbot.schedulers.forcesched import ForceScheduler
   26 from buildbot.schedulers.timed import Nightly
   27 from buildbot.util import datetime2epoch
   28 from buildbot.worker.local import LocalWorker
   29 
   30 """ Janitor is a configurator which create a Janitor Builder with all needed Janitor steps
   31 """
   32 
   33 JANITOR_NAME = "__Janitor"  # If you read this code, you may want to patch this name.
   34 
   35 
   36 def now():
   37     """patchable now (datetime is not patchable as builtin)"""
   38     return datetime.datetime.utcnow()
   39 
   40 
   41 class LogChunksJanitor(BuildStep):
   42     name = 'LogChunksJanitor'
   43     renderables = ["logHorizon"]
   44 
   45     def __init__(self, logHorizon):
   46         super().__init__()
   47         self.logHorizon = logHorizon
   48 
   49     @defer.inlineCallbacks
   50     def run(self):
   51         older_than_timestamp = datetime2epoch(now() - self.logHorizon)
   52         deleted = yield self.master.db.logs.deleteOldLogChunks(older_than_timestamp)
   53         self.descriptionDone = ["deleted", str(deleted), "logchunks"]
   54         return SUCCESS
   55 
   56 
   57 class JanitorConfigurator(ConfiguratorBase):
   58     def __init__(self, logHorizon=None, hour=0, **kwargs):
   59         super().__init__()
   60         self.logHorizon = logHorizon
   61         self.hour = hour
   62         self.kwargs = kwargs
   63 
   64     def configure(self, config_dict):
   65         if self.logHorizon is None:
   66             return
   67         logHorizon = self.logHorizon
   68         hour = self.hour
   69         kwargs = self.kwargs
   70 
   71         super().configure(config_dict)
   72         nightly_kwargs = {}
   73 
   74         # we take the defaults of Nightly, except for hour
   75         for arg in ('minute', 'dayOfMonth', 'month', 'dayOfWeek'):
   76             if arg in kwargs:
   77                 nightly_kwargs[arg] = kwargs[arg]
   78 
   79         self.schedulers.append(Nightly(
   80             name=JANITOR_NAME, builderNames=[JANITOR_NAME], hour=hour, **nightly_kwargs))
   81 
   82         self.schedulers.append(ForceScheduler(
   83             name=JANITOR_NAME + "_force",
   84             builderNames=[JANITOR_NAME]))
   85 
   86         self.builders.append(BuilderConfig(
   87             name=JANITOR_NAME, workername=JANITOR_NAME, factory=BuildFactory(steps=[
   88                 LogChunksJanitor(logHorizon=logHorizon)
   89             ])
   90         ))
   91         self.protocols.setdefault('null', {})
   92         self.workers.append(LocalWorker(JANITOR_NAME))