8 from pprint import pprint
10 CAMUNDA="http://localhost:8080/engine-rest/"
12 def get_current_deployments(key = 'sentiment-analysis'):
13 res = requests.get(CAMUNDA + "deployment")
14 #return [proc for proc in res.json() if proc['name'] == key]
17 def cleanup_old_deployments(key='sentiment-analysis'):
18 print ("Cleaning up old deployments")
19 for deployment in get_current_deployments(key):
20 res = requests.delete(CAMUNDA + "deployment/" + deployment['id'] + "?cascade=true&skipCustomListeners=true")
21 if (res.status_code == 204):
22 print ("Cleaned up deployment {}".format(deployment['id']))
24 print ("Error cleaning old deployment {}: Code: {}".format(deployment['id'], res.status_code))
30 def create_deployment(cleanup=False):
32 ("deployment-name", "sentiment-analysis"),
33 #("enable-duplicate-filtering", "true"),
34 #("deploy-changed-only", "true"),
35 ("file1", open("sentiment-analysis.bpmn")),
36 ("file2", open("forms/input-terms.html")),
37 ("file3", open("forms/download-pdf.html")),
40 cleanup_old_deployments()
41 res = requests.post(CAMUNDA + "deployment/create", files=parameters)
42 if (res.status_code == 200):
43 print ("Successfully deployed Sentiment Analysis")
45 pprint ("Status Code: {}".format(res.status_code))
51 def submit_terms(terms):
52 termlist = [{'term': term} for term in terms]
57 'value': json.dumps(termlist),
60 'serializationDataFormat': "application/json",
65 res = requests.post(CAMUNDA + "process-definition/key/sentiment-analysis/start", json=params)
66 if (res.status_code == 200):
67 print ("Successfully started Sentiment Analysis")
69 pprint ("Status Code: {}".format(res.status_code))
74 import xml.dom.minidom
75 content = res.content.decode('utf-8').replace('<!doctype html>', '')
76 print(xml.dom.minidom.parseString(content).toprettyxml())
80 if __name__ == "__main__":
81 parser = argparse.ArgumentParser()
82 parser.add_argument('--deploy', dest='deploy', default=True, action='store_false', help="Do deployment step")
83 parser.add_argument('--no-cleanup', dest='cleanup', default=True, action='store_false', help="Initial deploy does not need cleanup")
84 parser.add_argument('--autoclick', dest='autoclick', type=int, default=0, help="How many steps to autoclick")
85 args = parser.parse_args()
88 # initialize camunda process
89 create_deployment(cleanup=args.cleanup)
91 if args.autoclick >= 1:
93 submit_terms(["voting", "phonegate", "35c3"])