Merge #68 Add support for sending messages

This commit is contained in:
Dennis Gilmore 2015-11-25 14:56:51 +00:00
commit 6f00f20b3d
9 changed files with 244 additions and 2 deletions

20
bin/pungi-fedmsg-notification Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import fedmsg
import json
import sys
def send(cmd, data):
topic = 'compose.%s' % cmd.replace('-', '.').lower()
fedmsg.publish(topic=topic, modname='pungi', msg=data)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('cmd')
opts = parser.parse_args()
data = json.load(sys.stdin)
send(opts.cmd, data)

View file

@ -26,6 +26,7 @@ locale.setlocale(locale.LC_ALL, "C")
COMPOSE = None
NOTIFIER = None
def main():
@ -187,8 +188,19 @@ def main():
def run_compose(compose):
import pungi.phases
import pungi.metadata
import pungi.notifier
errors = []
# initializer notifier
compose.notifier = pungi.notifier.PungiNotifier(compose)
try:
compose.notifier.validate()
except ValueError as ex:
errors.extend(["NOTIFIER: %s" % m for m in ex.message.split('\n')])
compose.write_status("STARTED")
compose.notifier.send('start')
compose.log_info("Host: %s" % socket.gethostname())
compose.log_info("User name: %s" % getpass.getuser())
compose.log_info("Working directory: %s" % os.getcwd())
@ -216,7 +228,6 @@ def run_compose(compose):
test_phase = pungi.phases.TestPhase(compose)
# check if all config options are set
errors = []
for phase in (init_phase, pkgset_phase, createrepo_phase,
buildinstall_phase, productimg_phase, gather_phase,
extrafiles_phase, createiso_phase, liveimages_phase,
@ -230,6 +241,7 @@ def run_compose(compose):
errors.append("%s: %s" % (phase.name.upper(), i))
if errors:
for i in errors:
compose.notifier.send('abort')
compose.log_error(i)
print(i)
sys.exit(1)
@ -319,6 +331,7 @@ def run_compose(compose):
compose.log_info("Compose finished: %s" % compose.topdir)
compose.write_status("FINISHED")
compose.notifier.send('finish')
if __name__ == "__main__":
@ -333,6 +346,8 @@ if __name__ == "__main__":
COMPOSE.write_status("DOOMED")
import kobo.tback
open(tb_path, "w").write(kobo.tback.Traceback().get_traceback())
if COMPOSE.notifier:
COMPOSE.notifier.send('doomed')
else:
print("Exception: %s" % ex)
raise