Skip to content

Commit

Permalink
fmt: run black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
pktpls committed Sep 20, 2023
1 parent 4f53d5c commit f4a29d8
Show file tree
Hide file tree
Showing 7 changed files with 597 additions and 383 deletions.
23 changes: 13 additions & 10 deletions roles/buildbot/files/asyncbuild.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- python -*-
# ex: set filetype=python:

from buildbot.plugins import util, steps
from typing import List

from buildbot.plugins import steps, util
from buildbot.process import build, buildstep, factory, logobserver
from twisted.internet import defer
from twisted.python import log

from typing import List

# AsyncBuildGenerator dynamically generates build steps from command output.
#
Expand All @@ -19,14 +20,14 @@ def __init__(self, stepFunc, **kwargs):
kwargs = self.setupShellMixin(kwargs)
super().__init__(**kwargs)
self.observer = logobserver.BufferLogObserver()
self.addLogObserver('stdio', self.observer)
self.addLogObserver("stdio", self.observer)
self.stepFunc = stepFunc

def getLines(self, stdout):
archs = []
for line in stdout.split('\n'):
for line in stdout.split("\n"):
arch = str(line.strip())
if arch and not arch.startswith('#'):
if arch and not arch.startswith("#"):
archs.append(arch)
return archs

Expand All @@ -36,11 +37,12 @@ def run(self):
yield self.runCommand(cmd)
result = cmd.results()
if result == util.SUCCESS:
self.build.addStepsAfterCurrentStep([
self.stepFunc(a) for a in self.getLines(self.observer.getStdout())
])
self.build.addStepsAfterCurrentStep(
[self.stepFunc(a) for a in self.getLines(self.observer.getStdout())]
)
return result


# AsyncTrigger is a Trigger step which executes in parallel with other AsyncTriggers.
# It's a useful middleground between waitForFinish=False and waitForFinish=True.
#
Expand All @@ -60,8 +62,8 @@ def _createStep(self):
self.name = yield self.build.render(self.name)
self.build.setUniqueStepName(self)
self.stepid, self.number, self.name = yield self.master.data.updates.addStep(
buildid=self.build.buildid,
name=self.name)
buildid=self.build.buildid, name=self.name
)

@defer.inlineCallbacks
def addStep(self):
Expand Down Expand Up @@ -91,6 +93,7 @@ def run(self):

return results


# AsyncBuild is a Build which can execute AsyncTrigger steps in parallel.
# It's a useful middleground between waitForFinish=False and waitForFinish=True.
#
Expand Down
28 changes: 19 additions & 9 deletions roles/buildbot/files/generate_autoupdate_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,33 @@
import json
import os


parser = argparse.ArgumentParser()
parser.add_argument('-v', dest='version', type=str, required=True,
help='falter-version that the autoupdate-file is for.')
parser.add_argument('-p', dest='dir', type=str, required=True,
help='version directory, in which there are tunneldigger- and notunnel- dirs. autoupdate.json will be placed in that directory too.')
parser.add_argument(
"-v",
dest="version",
type=str,
required=True,
help="falter-version that the autoupdate-file is for.",
)
parser.add_argument(
"-p",
dest="dir",
type=str,
required=True,
help="version directory, in which there are tunneldigger- and notunnel- dirs. autoupdate.json will be placed in that directory too.",
)
args = parser.parse_args()

# build autoupdate.json
autoupdate_json = {}
autoupdate_json[
"image_url"] = "https://firmware.berlin.freifunk.net/stable/{falter-version}/{flavour}/{target}"
"image_url"
] = "https://firmware.berlin.freifunk.net/stable/{falter-version}/{flavour}/{target}"
autoupdate_json["target"] = {}
autoupdate_json["falter-version"] = args.version

# get paths of all json-files
file_list = os.popen('find ' + args.dir + ' -name "*.json"').read().split()
file_list = os.popen("find " + args.dir + ' -name "*.json"').read().split()

# aggregate the content of all files
for fpath in file_list:
Expand All @@ -36,12 +46,12 @@
# print(profiles)

# get flavour and omit backbone-images
flavour = fpath.split('/')[-4]
flavour = fpath.split("/")[-4]
if flavour == "backbone":
continue

# get target and create dict, if not already created
target = '/'.join(fpath.split('/')[-3:-1])
target = "/".join(fpath.split("/")[-3:-1])
if autoupdate_json.get("target").get(target) == None:
autoupdate_json["target"][target] = {}

Expand Down
81 changes: 47 additions & 34 deletions roles/buildbot/files/notify.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
# -*- python -*-
# ex: set filetype=python:

from buildbot.plugins import util, steps
import pprint

from buildbot.plugins import steps, util
from buildbot.process.results import statusToString
from buildbot.reporters.base import ReporterBase
from buildbot.reporters.generators.build import BuildStartEndStatusGenerator
from buildbot.reporters.generators.buildrequest import BuildRequestGenerator
from buildbot.reporters.message import MessageFormatterRenderable
from buildbot.util import httpclientservice
from buildbot.process.results import statusToString

from twisted.internet import defer
from twisted.python import log

import pprint

class MatrixNotifier(ReporterBase):

def __init__(self, homeserver=None, accessToken=None, room=None, **kwargs):
self.homeserver = homeserver
self.accessToken = accessToken
self.room = room
super().__init__(**kwargs)

def checkConfig(self, context=None, debug=None, verify=None, generators=None,
**kwargs):
def checkConfig(
self, context=None, debug=None, verify=None, generators=None, **kwargs
):
if generators is None:
generators = self._create_default_generators()

super().checkConfig(generators=generators, **kwargs)

@defer.inlineCallbacks
def reconfigService(self, context=None, debug=None,
verify=None, generators=None, **kwargs):
def reconfigService(
self, context=None, debug=None, verify=None, generators=None, **kwargs
):
self.debug = debug
self.verify = verify
self.context = self.setup_context(context)
Expand All @@ -41,50 +42,62 @@ def reconfigService(self, context=None, debug=None,
yield super().reconfigService(generators=generators, **kwargs)

def setup_context(self, context):
return context or util.Interpolate('buildbot/%(prop:buildername)s')
return context or util.Interpolate("buildbot/%(prop:buildername)s")

# This is needed but I have no clue what it does.
def _create_default_generators(self):
start_formatter = MessageFormatterRenderable('Build started.')
end_formatter = MessageFormatterRenderable('Build done.')
pending_formatter = MessageFormatterRenderable('Build pending.')
start_formatter = MessageFormatterRenderable("Build started.")
end_formatter = MessageFormatterRenderable("Build done.")
pending_formatter = MessageFormatterRenderable("Build pending.")

return [
BuildRequestGenerator(formatter=pending_formatter),
BuildStartEndStatusGenerator(start_formatter=start_formatter,
end_formatter=end_formatter)
BuildStartEndStatusGenerator(
start_formatter=start_formatter, end_formatter=end_formatter
),
]

@defer.inlineCallbacks
def sendMessage(self, reports):
b = reports[0]['builds'][0]
builder = b['builder']['name']

if 'number' not in b or b['complete'] != True or (builder != 'builds/targets' and builder != 'builds/packages'):
b = reports[0]["builds"][0]
builder = b["builder"]["name"]

if (
"number" not in b
or b["complete"] != True
or (builder != "builds/targets" and builder != "builds/packages")
):
return

# pp = pprint.PrettyPrinter(indent=4)
# log.msg(f'MatrixNotifier.sendMessage - {pp.pformat(reports)}')

version = b['properties']['branch'][0]
if builder == 'builds/targets':
version = b['properties']['falterVersion'][0]
version = b["properties"]["branch"][0]
if builder == "builds/targets":
version = b["properties"]["falterVersion"][0]

result = statusToString(b['results'])
color = '#ff0000'
if b['results'] == 0:
color = '#008000'
result = statusToString(b["results"])
color = "#ff0000"
if b["results"] == 0:
color = "#008000"

url = b['url']
url = b["url"]

msg = f'{builder} @ {version} · {result} · {url}'
htmlmsg = f'{builder} @ {version} · <font color="{color}">{result}</font> · {url}'
msg = f"{builder} @ {version} · {result} · {url}"
htmlmsg = (
f'{builder} @ {version} · <font color="{color}">{result}</font> · {url}'
)

http = yield httpclientservice.HTTPClientService.getService(
self.master, self.homeserver)
self.master, self.homeserver
)

res = http.post(
f'/_matrix/client/r0/rooms/{self.room}/send/m.room.message?access_token={self.accessToken}',
json={'msgtype':'m.notice', 'body':msg,
'format':'org.matrix.custom.html', 'formatted_body':htmlmsg})

f"/_matrix/client/r0/rooms/{self.room}/send/m.room.message?access_token={self.accessToken}",
json={
"msgtype": "m.notice",
"body": msg,
"format": "org.matrix.custom.html",
"formatted_body": htmlmsg,
},
)
Loading

0 comments on commit f4a29d8

Please sign in to comment.