From f5b31c59a6a04156f933ae920789efe8c9ed73fb Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Sun, 25 Nov 2018 16:07:50 +0100 Subject: [PATCH] prettier error messages --- camunda-overlay/camunda.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/camunda-overlay/camunda.py b/camunda-overlay/camunda.py index e975e22..b3c176c 100755 --- a/camunda-overlay/camunda.py +++ b/camunda-overlay/camunda.py @@ -5,6 +5,7 @@ import os import json import requests import argparse +from pprint import pprint CAMUNDA="http://localhost:8080/engine-rest/" @@ -16,11 +17,15 @@ def get_current_deployments(key = 'sentiment-analysis'): def cleanup_old_deployments(key='sentiment-analysis'): print ("Cleaning up old deployments") for deployment in get_current_deployments(key): - res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true") + res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true&skipCustomListeners=true") if (res.status_code == 204): print ("Cleaned up deployment {}".format(deployment['id'])) else: print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code)) + try: + pprint(res.json()) + except: + pprint(res.content) def create_deployment(cleanup=False): parameters = [ @@ -37,14 +42,13 @@ def create_deployment(cleanup=False): if (res.status_code == 200): print ("Successfully deployed Sentiment Analysis") else: - from pprint import pprint pprint ("Status Code: {}".format(res.status_code)) try: pprint(res.json()) except: pprint(res.content) -def submit_terms(terms=[]): +def submit_terms(terms): termlist = [{'term': term} for term in terms] # submit to camunda params = { @@ -62,12 +66,16 @@ def submit_terms(terms=[]): if (res.status_code == 200): print ("Successfully started Sentiment Analysis") else: - from pprint import pprint pprint ("Status Code: {}".format(res.status_code)) try: pprint(res.json()) except: - pprint(res.content) + try: + import xml.dom.minidom + content = res.content.decode('utf-8').replace('', '') + print(xml.dom.minidom.parseString(content).toprettyxml()) + except: + pprint(res.content) if __name__ == "__main__": parser = argparse.ArgumentParser() -- 2.43.0