2015-11-23 15:09:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-06-16 15:26:22 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-11-23 15:09:01 +00:00
|
|
|
import argparse
|
2020-06-16 15:26:22 +00:00
|
|
|
import fedora_messaging.api
|
|
|
|
import fedora_messaging.config
|
|
|
|
import fedora_messaging.exceptions
|
2015-11-23 15:09:01 +00:00
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def send(cmd, data):
|
2020-02-03 03:50:06 +00:00
|
|
|
topic = "compose.%s" % cmd.replace("-", ".").lower()
|
2020-06-16 15:26:22 +00:00
|
|
|
try:
|
|
|
|
msg = fedora_messaging.api.Message(topic="pungi.{}".format(topic), body=data)
|
|
|
|
fedora_messaging.api.publish(msg)
|
|
|
|
except fedora_messaging.exceptions.PublishReturned as e:
|
|
|
|
print("Fedora Messaging broker rejected message %s: %s" % (msg.id, e))
|
|
|
|
sys.exit(1)
|
|
|
|
except fedora_messaging.exceptions.ConnectionException as e:
|
|
|
|
print("Error sending message %s: %s" % (msg.id, e))
|
|
|
|
sys.exit(1)
|
|
|
|
except Exception as e:
|
|
|
|
print("Error sending fedora-messaging message: %s" % (e))
|
|
|
|
sys.exit(1)
|
2015-11-23 15:09:01 +00:00
|
|
|
|
2019-12-06 02:54:11 +00:00
|
|
|
|
|
|
|
def main():
|
2015-11-23 15:09:01 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
2020-02-03 03:50:06 +00:00
|
|
|
parser.add_argument("cmd")
|
2020-06-16 15:26:22 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--config",
|
|
|
|
dest="config",
|
|
|
|
help="fedora-messaging configuration file to use. "
|
|
|
|
"This allows overriding the default "
|
|
|
|
"/etc/fedora-messaging/config.toml.",
|
|
|
|
)
|
2015-11-23 15:09:01 +00:00
|
|
|
opts = parser.parse_args()
|
2015-12-08 17:29:12 +00:00
|
|
|
|
2020-06-16 15:26:22 +00:00
|
|
|
if opts.config:
|
|
|
|
fedora_messaging.config.conf.load_config(opts.config)
|
2015-12-08 17:29:12 +00:00
|
|
|
|
2015-11-23 15:09:01 +00:00
|
|
|
data = json.load(sys.stdin)
|
|
|
|
send(opts.cmd, data)
|