github.com/sentienttechnologies/studio-go-runner@v0.0.0-20201118202441-6d21f2ced8ee/assets/multistep/metadata-test.py (about) 1 # Copyright 2018-2020 (c) Cognizant Digital Business, Evolutionary AI. All rights reserved. 2 # Issued under the Apache 2.0 License. 3 4 import sys 5 import time 6 7 import os 8 import os.path 9 10 import json 11 12 def touch(fname, times=None): 13 with open(fname, 'a'): 14 os.utime(fname, times) 15 # During the first pass we will inject a number of directives for document editing 16 17 data = { "experiment": {"name": "dummy pass"}} 18 print(json.dumps(data)) 19 20 # Look into the output dir for a file and wait until the job expires, and if that 21 # fails then bailout with an error 22 try: 23 if not os.path.isfile('/tmp/firstRun'): 24 touch('/tmp/firstRun') 25 edit = [{"op": "replace", "path": "/experiment/name", "value": "First pass"}] 26 print(json.dumps(edit)) 27 edit = [{"op": "remove", "path": "/experiment"}] 28 print(json.dumps(edit)) 29 sys.exit(-1) 30 except: 31 touch('/tmp/firstRun') 32 sys.exit(-1) 33 34 data = { 35 "experiment": { 36 "name": "Zaphod Beeblebrox", 37 } 38 } 39 40 # Output useful metadata 41 print (json.dumps(data)) 42 sys.stdout.flush()