#!/usr/bin/python # -*- mode: python; coding: utf-8 -*- # Copyright © 2008 Jeffrey C. Ollie # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see # . import sys import re import os import time import pwd import socket from qpid.util import connect from qpid.connection import Connection from qpid.datatypes import Message, RangedSet, uuid4 from qpid.queue import Empty from lxml import etree host = '127.0.0.1' port = 5672 root_element = etree.Element('loginfo') timestamp = time.time() timestamp_element = etree.SubElement(root_element, 'timestamp') timestamp_element.text = '%17.6f' % timestamp uid = os.getuid() pwd_entry = pwd.getpwuid(uid) username = pwd_entry[0].decode('utf-8') username_element = etree.SubElement(root_element, 'username') username_element.text = username fullname = pwd_entry[4].decode('utf-8') fullname_element = etree.SubElement(root_element, 'fullname') fullname_element.text = fullname cvsserver_element = etree.SubElement(root_element, 'cvsserver') cvsserver_element.text = socket.gethostname() cvsroot = os.environ['CVSROOT'] cvsroot_element = etree.SubElement(root_element, 'cvsroot') cvsroot_element.text = cvsroot directory_re = re.compile(r'^Update of %s/(.*)$' % (cvsroot,), re.M) message = sys.stdin.read().decode('utf-8', 'replace') directory_match = directory_re.search(message) assert(directory_match) directory = directory_match.group(1) directory_element = etree.SubElement(root_element, 'directory') directory_element.text = directory filespecs = sys.argv[1].decode('utf-8') assert(filespecs.startswith(directory + ' ')) filespecs = filespecs[len(directory)+1:] new_dir_re = re.compile('(.*) - New directory') filespec_re = re.compile(r'^(.*?),(\d+(?:\.\d+)+|NONE),(\d+(?:\.\d+)+|NONE),(\S*)\s*') files_element = etree.SubElement(root_element, 'files') while len(filespecs) > 0: filespec_match = filespec_re.match(filespecs) assert(filespec_match) file_element = etree.SubElement(files_element, 'file') filename_element = etree.SubElement(file_element, 'filename') filename_element.text = filespec_match.group(1) old_version_element = etree.SubElement(file_element, 'old-version') old_version_element.text = filespec_match.group(2) new_version_element = etree.SubElement(file_element, 'new-version') new_version_element.text = filespec_match.group(3) if filespec_match.group(4): tag_element = etree.SubElement(file_element, 'tag') tag_element.text = filespec_match.group(4) filespecs = filespecs[filespec_match.end():] message_element = etree.SubElement(root_element, 'message') message_element.text = message socket = connect(host, port) connection = Connection(sock = socket) connection.start() session = connection.session(str(uuid4())) properties = session.delivery_properties(routing_key = 'loginfo') session.message_transfer(destination='cvs_exchange', message = Message(properties, etree.tostring(root_element, encoding = 'utf-8', xml_declaration = True))) session.close(timeout=10)