Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions tools/cwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,63 @@
concore.delay = 0.02

try:
apikey=open(concore.inpath+'1/concore.apikey',newline=None).readline().rstrip()
with open(concore.inpath+'1/concore.apikey',newline=None) as f:
apikey=f.readline().rstrip()
except (OSError, IOError):
try:
#perhaps this should be removed for security
apikey=open('./concore.apikey',newline=None).readline().rstrip()
with open('./concore.apikey',newline=None) as f:
apikey=f.readline().rstrip()
except (OSError, IOError):
apikey = ''

try:
yuyu=open(concore.inpath+'1/concore.yuyu',newline=None).readline().rstrip()
with open(concore.inpath+'1/concore.yuyu',newline=None) as f:
yuyu=f.readline().rstrip()
except (OSError, IOError):
try:
yuyu=open('./concore.yuyu',newline=None).readline().rstrip()
with open('./concore.yuyu',newline=None) as f:
yuyu=f.readline().rstrip()
except (OSError, IOError):
yuyu = 'yuyu'

try:
name1=open(concore.inpath+'1/concore.name1',newline=None).readline().rstrip()
with open(concore.inpath+'1/concore.name1',newline=None) as f:
name1=f.readline().rstrip()
except (OSError, IOError):
try:
name1=open('./concore.name1',newline=None).readline().rstrip()
with open('./concore.name1',newline=None) as f:
name1=f.readline().rstrip()
except (OSError, IOError):
name1 = 'u'

try:
name2=open(concore.inpath+'1/concore.name2',newline=None).readline().rstrip()
with open(concore.inpath+'1/concore.name2',newline=None) as f:
name2=f.readline().rstrip()
except (OSError, IOError):
try:
name2=open('./concore.name2',newline=None).readline().rstrip()
with open('./concore.name2',newline=None) as f:
name2=f.readline().rstrip()
except (OSError, IOError):
name2 = 'ym'

try:
init_simtime_u = open(concore.inpath+'1/concore.init1',newline=None).readline().rstrip()
with open(concore.inpath+'1/concore.init1',newline=None) as f:
init_simtime_u = f.readline().rstrip()
except (OSError, IOError):
try:
init_simtime_u = open('./concore.init1',newline=None).readline().rstrip()
with open('./concore.init1',newline=None) as f:
init_simtime_u = f.readline().rstrip()
except (OSError, IOError):
init_simtime_u = "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"

try:
init_simtime_ym = open(concore.inpath+'1/concore.init2',newline=None).readline().rstrip()
with open(concore.inpath+'1/concore.init2',newline=None) as f:
init_simtime_ym = f.readline().rstrip()
except (OSError, IOError):
try:
init_simtime_ym = open('./concore.init2',newline=None).readline().rstrip()
with open('./concore.init2',newline=None) as f:
init_simtime_ym = f.readline().rstrip()
except (OSError, IOError):
init_simtime_ym = "[0.0, 0.0, 0.0]"

Expand All @@ -82,10 +94,11 @@
logging.debug("CW outer loop")
while concore.unchanged():
u = concore.read(1,name1,init_simtime_u)
f = {'file1': open(concore.inpath+'1/'+name1, 'rb')}
logging.debug(f"CW: before post u={u}")
logging.debug(f'http://www.controlcore.org/pm/{yuyu}{apikey}&fetch={name2}')
r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max)
with open(concore.inpath+'1/'+name1, 'rb') as f1:
f = {'file1': f1}
logging.debug(f"CW: before post u={u}")
logging.debug(f'http://www.controlcore.org/pm/{yuyu}{apikey}&fetch={name2}')
r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max)
if r.status_code!=200:
logging.error(f"bad POST request {r.status_code}")
quit()
Expand All @@ -101,11 +114,12 @@
while oldt==t or len(r.content)==0:
time.sleep(concore.delay)
logging.debug(f"CW waiting status={r.status_code} content={r.content.decode('utf-8')} t={t}")
f = {'file1': open(concore.inpath+'1/'+name1, 'rb')}
try:
r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max)
except Exception:
logging.error("CW: bad request")
with open(concore.inpath+'1/'+name1, 'rb') as f1:
f = {'file1': f1}
try:
r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max)
except Exception:
logging.error("CW: bad request")
timeout_count += 1
if r.status_code!=200 or time.perf_counter()-t1 > 1.1*timeout_max: #timeout_count>100:
logging.error(f"timeout or bad POST request {r.status_code}")
Expand Down