5
5
6
6
import datetime
7
7
import sys
8
- import urllib .request
9
- import urllib .parse
10
- import urllib .error
11
8
import os
12
9
from subprocess import Popen , PIPE
13
10
import time
17
14
import glob
18
15
import itertools
19
16
import json
17
+ import shutil
20
18
from ipsframework import ipsutil , Component
21
19
from ipsframework .convert_log_function import convert_logdata_to_html
22
20
@@ -88,7 +86,6 @@ def __init__(self, services, config):
88
86
self .startTime = self .curTime
89
87
self .services = services
90
88
self .sim_map = {}
91
- self .runid_url = None
92
89
self .portal_url = None
93
90
self .done = False
94
91
self .first_event = True
@@ -109,14 +106,10 @@ def init(self, timestamp=0.0, **keywords):
109
106
Try to connect to the portal, subscribe to *_IPS_MONITOR* events and
110
107
register callback :py:meth:`.process_event`.
111
108
"""
112
- # try:
113
- # self.portal_url = self.PORTAL_URL
114
- # except AttributeError:
115
- # pass
116
- # try:
117
- # self.runid_url = self.RUNID_URL
118
- # except AttributeError:
119
- # pass
109
+ try :
110
+ self .portal_url = self .PORTAL_URL
111
+ except AttributeError :
112
+ pass
120
113
self .host = self .services .get_config_param ('HOST' )
121
114
self .services .subscribe ('_IPS_MONITOR' , "process_event" )
122
115
try :
@@ -268,16 +261,17 @@ def send_event(self, sim_data, event_data):
268
261
self .services .exception ("Error writing html file into USER_W3_DIR directory" )
269
262
self .write_to_htmldir = False
270
263
if self .portal_url :
271
- webmsg = urllib . parse . urlencode (event_data ). encode ( "utf-8" )
264
+ webmsg = json . dumps (event_data )
272
265
try :
273
266
if self .first_event : # First time, launch sendPost.py daemon
274
- cmd = os .path .join (sys .path [0 ], 'sendPost.py' )
275
- self .childProcess = Popen (cmd , shell = True , bufsize = 128 ,
267
+ cmd = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'sendPost.py' )
268
+ python_exec = shutil .which ('python' )
269
+ self .childProcess = Popen ([python_exec , cmd ], bufsize = 128 ,
276
270
stdin = PIPE , stdout = PIPE ,
277
271
stderr = PIPE , close_fds = True )
278
272
self .first_event = False
279
- self .childProcess .stdin .write ('%s %s\n ' %
280
- (self .portal_url , webmsg ))
273
+ self .childProcess .stdin .write (( '%s %s\n ' %
274
+ (self .portal_url , webmsg )). encode ( ))
281
275
self .childProcess .stdin .flush ()
282
276
except Exception as e :
283
277
self .services .exception ('Error transmitting event number %6d to %s : %s' ,
@@ -481,15 +475,6 @@ def init_simulation(self, sim_name, sim_root):
481
475
d = datetime .datetime .now ()
482
476
date_str = "%s.%03d" % (d .strftime ("%Y-%m-%dT%H:%M:%S" ), int (d .microsecond / 1000 ))
483
477
sim_data .portal_runid = "_" .join ([self .host , "USER" , date_str ])
484
- if self .runid_url is not None :
485
- self .services .debug ('PORTAL_RUNID_URL = %s' , str (self .runid_url ))
486
- try :
487
- f = urllib .request .urlopen (self .runid_url , None , 10 )
488
- sim_data .portal_runid = f .read ().strip ()
489
- except (urllib .error .URLError ) as e :
490
- self .services .error ('Error obtaining runID from service at %s : %s' %
491
- (self .runid_url , str (e )))
492
- self .services .error ('Using a datetime instead' )
493
478
try :
494
479
self .services .set_config_param ('PORTAL_RUNID' , sim_data .portal_runid ,
495
480
target_sim_name = sim_name )
0 commit comments