ciabot/irker-cia-proxy.py | 152 +++++++++++++++++++++++++++++++++++++++ ciabot/libreoffice-bugzilla2.py | 19 +--- ciabot/run-libreoffice-ciabot.pl | 6 - 3 files changed, 160 insertions(+), 17 deletions(-)
New commits: commit 00bd505620f9c5f491c3dd0d15fe38ab383b98a3 Author: Guilhem Moulin <[email protected]> AuthorDate: Thu Jul 2 01:13:10 2020 +0200 Commit: Guilhem Moulin <[email protected]> CommitDate: Thu Jul 2 01:27:25 2020 +0200 ciabot: Port libreoffice-bugzilla2.py and irker-cia-proxy.py to python3. diff --git a/ciabot/irker-cia-proxy.py b/ciabot/irker-cia-proxy.py index c26996c..6ea6c83 100644 --- a/ciabot/irker-cia-proxy.py +++ b/ciabot/irker-cia-proxy.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ irker-cia-proxy - proxy CIA requests to an irker relay agent @@ -15,8 +15,8 @@ from the use of this software. import json, socket, posixpath, re, sys from xml.dom import minidom -from SimpleXMLRPCServer import SimpleXMLRPCServer -from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler +from xmlrpc.server import SimpleXMLRPCServer +from xmlrpc.server import SimpleXMLRPCRequestHandler bind_ip = '' bind_port = 8000 @@ -117,9 +117,9 @@ class CIAMessage: def get_template(self): # If there is a template for this branch, use it, otherwise fall back to the project or the global one. branch_template = "template-%s" % self.data()['branch'] - if projmap[self.project()].has_key(branch_template): + if branch_template in projmap[self.project()]: return projmap[self.project()][branch_template] - if projmap[self.project()].has_key('template'): + if 'template' in projmap[self.project()]: return projmap[self.project()]['template'] return template def get_target(self): diff --git a/ciabot/libreoffice-bugzilla2.py b/ciabot/libreoffice-bugzilla2.py index 8d11e31..8ba84e2 100644 --- a/ciabot/libreoffice-bugzilla2.py +++ b/ciabot/libreoffice-bugzilla2.py @@ -18,23 +18,14 @@ # - adds a comment to the report # - updates the whiteboard field with target information -from __future__ import print_function - import datetime import os import re import sys, getopt import git -import ConfigParser - -if hasattr(sys.version_info, "major") and sys.version_info.major >= 3: -# pylint: disable=F0401,E0611 - from urllib.parse import urlparse -else: - from urlparse import urlparse +import configparser import bugzilla -from bugzilla import Bugzilla master_target = "7.1.0" bug_regex = "\\b(?:bug|fdo|tdf|lo)[#:]?(\\d+)\\b" @@ -46,7 +37,7 @@ class FreedesktopBZ: bz = None def connect(self): - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(os.path.dirname(os.path.abspath(__file__)) + '/config.cfg') url = config.get('bugzilla', 'url') user = config.get('bugzilla', 'user') @@ -58,7 +49,7 @@ class FreedesktopBZ: def update_whiteboard(self, commit, bugnr, new_version, branch, repo_name): print(bugnr) if dry_run: - print("DRY RUN, we would set the whiteboard to: target:\n%s" % new_version) + print(("DRY RUN, we would set the whiteboard to: target:\n%s" % new_version)) else: bug = self.bz.getbug(bugnr) print(bug) @@ -99,7 +90,7 @@ https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.""" %(new_version) if dry_run: - print("DRY RUN, we would add the following comment:\n%s" % comment_msg) + print(("DRY RUN, we would add the following comment:\n%s" % comment_msg)) else: bug.addcomment(comment_msg) @@ -177,7 +168,7 @@ def find_bugid(repo, commit_id): return m def read_repo(repo_name): - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read(os.path.dirname(os.path.abspath(__file__)) + '/config.cfg') path = config.get(repo_name, 'location') repo = git.repo.base.Repo(path) diff --git a/ciabot/run-libreoffice-ciabot.pl b/ciabot/run-libreoffice-ciabot.pl index c48e821..eb90f0b 100755 --- a/ciabot/run-libreoffice-ciabot.pl +++ b/ciabot/run-libreoffice-ciabot.pl @@ -89,7 +89,7 @@ sub report($$$) { my %old = %{$old_ref}; my %new = %{$new_ref}; my $ciabot = "timeout 60 $cwd/libreoffice-ciabot.pl"; - my $ciaproxy = "| ( cd $cwd && python irker-cia-proxy.py -s )"; + my $ciaproxy = "| ( cd $cwd && python3 irker-cia-proxy.py -s )"; foreach my $key ( keys %new ) { my $branch_name = $key; @@ -127,13 +127,13 @@ sub report($$$) { my $branch = $branch_name; $branch = 'master' if ($branch eq ''); print "reporting to bugzilla: $_ and branch $branch\n"; - qx(python $cwd/libreoffice-bugzilla2.py -r $repo -c $_ -b $branch >>/var/log/ciabot/bugzilla.log); + qx(python3 $cwd/libreoffice-bugzilla2.py -r $repo -c $_ -b $branch >>/var/log/ciabot/bugzilla.log); } qx($ciabot $repo $_ $branch_name $ciaproxy); } } else { if ( is_valid_bugzilla_commit( $repo, $branch_name ) ) { - print "python $cwd/libreoffice-bugzilla2.py -r '$repo' -c '$_' -b '$branch_name'\n"; + print "python3 $cwd/libreoffice-bugzilla2.py -r '$repo' -c '$_' -b '$branch_name'\n"; } print "$ciabot '$repo' '$_' '$branch_name' $ciaproxy\n"; } commit 927bc365976758afa6de1f2edcfb03ad21ebd45e Author: Guilhem Moulin <[email protected]> AuthorDate: Thu Jul 2 01:21:03 2020 +0200 Commit: Guilhem Moulin <[email protected]> CommitDate: Thu Jul 2 01:27:25 2020 +0200 ciabot: Add irker-cia-proxy.py. diff --git a/ciabot/irker-cia-proxy.py b/ciabot/irker-cia-proxy.py new file mode 100644 index 0000000..c26996c --- /dev/null +++ b/ciabot/irker-cia-proxy.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python +""" +irker-cia-proxy - proxy CIA requests to an irker relay agent + +Copyright (c) 2012 William Pitcock <[email protected]> + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +This software is provided 'as is' and without any warranty, express or +implied. In no event shall the authors be liable for any damages arising +from the use of this software. +""" + +import json, socket, posixpath, re, sys +from xml.dom import minidom +from SimpleXMLRPCServer import SimpleXMLRPCServer +from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler + +bind_ip = '' +bind_port = 8000 +target_server = "localhost" +target_port = 6659 +template = "%(bold)s%(project)s:%(bold)s %(green)s%(author)s%(reset)s %(yellow)s%(branch)s%(reset)s * r%(bold)s%(revision)s%(bold)s %(module)s/%(files)s%(bold)s:%(bold)s %(log)s" + +projmap = json.load(open("projmap.json")) + +class CIAMessage: + "Abstract class which represents a CIA message." + def __init__(self, messagexml): + self._dom = minidom.parseString(messagexml) + def _render_files(self): + prefix, endings = self._consolidate_files() + endstr = ' '.join(endings) + if len(endstr) > 60: + endstr = self._summarize_files(endings) + if prefix.startswith('/'): + prefix = prefix[1:] + if endstr: + return "%s (%s)" % (prefix, endstr) + return prefix + def _consolidate_files(self): + files = [] + filenode = self.dig('message', 'body', 'commit', 'files') + if filenode is not None: + for child in filenode.childNodes: + if child.nodeName == 'file': + files.append(self._shallowtext(child)) + # Optimization: if we only have one file, don't waste CPU on any of the other + # stuff we do to pretend to be CIA. + if len(files) == 1: + return files[0], [] + prefix = re.sub("[^/]*$", "", posixpath.commonprefix(files)) + endings = [] + for file in files: + ending = file[len(prefix):].strip() + if ending == '': + ending = '.' + endings.append(ending) + return prefix, endings + def _summarize_files(self, files): + dirs = {} + for file in files: + dirs[posixpath.split(file)[0]] = True + if len(dirs) <= 1: + return "%d files" % len(files) + return "%d files in %d dirs" % (len(files), len(dirs)) + def _shallowtext_generator(self, node): + for child in node.childNodes: + if child.nodeType == child.TEXT_NODE: + yield child.data + def _shallowtext(self, node): + if node is None: + return None + return ''.join(self._shallowtext_generator(node)) + def dig(self, *subElements): + if not self._dom: + return None + node = self._dom + for name in subElements: + nextNode = None + for child in node.childNodes: + if child.nodeType == child.ELEMENT_NODE and child.nodeName == name: + nextNode = child + break + if nextNode: + node = nextNode + else: + return None + return node + def lookup(self, *subElements): + text = self._shallowtext(self.dig(*subElements)) + if text is not None: + return text.strip() + return None + def data(self): + paths = { + 'bold': '\x02', + 'green': '\x033', + 'blue': '\x032', + 'yellow': '\x037', + 'reset': '\x0F' + } + paths['project'] = self.lookup('message', 'source', 'project') + paths['branch'] = self.lookup('message', 'source', 'branch') + paths['module'] = self.lookup('message', 'source', 'module') + paths['revision'] = self.lookup('message', 'body', 'commit', 'revision') + paths['version'] = self.lookup('message', 'body', 'commit', 'version') + paths['author'] = self.lookup('message', 'body', 'commit', 'author') + paths['log'] = self.lookup('message', 'body', 'commit', 'log') + paths['files'] = self._render_files() + paths['url'] = self.lookup('message', 'body', 'commit', 'url') + return paths + def project(self): + return self.lookup('message', 'source', 'project') + def get_template(self): + # If there is a template for this branch, use it, otherwise fall back to the project or the global one. + branch_template = "template-%s" % self.data()['branch'] + if projmap[self.project()].has_key(branch_template): + return projmap[self.project()][branch_template] + if projmap[self.project()].has_key('template'): + return projmap[self.project()]['template'] + return template + def get_target(self): + return projmap[self.project()]['to'] + def message(self): + return self.get_template() % self.data() + def relay(self): + structure = {"to": self.get_target(), "privmsg": self.message()} + envelope = json.dumps(structure) + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + sock.sendto(envelope + "\n", (target_server, target_port)) + finally: + sock.close() + +if "-s" in sys.argv: + CIAMessage(sys.stdin.read()).relay() +else: + class CIARequestHandler(SimpleXMLRPCRequestHandler): + "A fake CIA server for receiving messages to translate and proxy." + rpc_paths = ('/RPC2') + + def deliver(message): + CIAMessage(message).relay() + return True + + server = SimpleXMLRPCServer((bind_ip, bind_port), CIARequestHandler) + server.register_introspection_functions() + server.register_function(deliver, 'hub.deliver') + server.serve_forever() _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
