def spawn(self, name, version, userno, msgkill, isbatch, input_dict): """Start the task.""" params = _ObitTaskParams(name, version) popsno = _allocate_popsno() index = popsno - 1 # Set input and output text parameter/result files tmpInput = "/tmp/" + params.name + "Input." + str(popsno) tmpOutput = "/tmp/" + params.name + "Output." + str(popsno) in_file = open(tmpInput, mode="w") for adverb in params.input_list: self.__write_adverb(params, in_file, adverb, input_dict[adverb]) in_file.close() # If debugging add a link to the input file to preserve it. if input_dict['DEBUG']: tmpDebug = tmpInput + 'Dbg' if os.access(tmpDebug, os.F_OK): os.unlink(tmpDebug) # Remove any old version file. os.link(tmpInput, tmpDebug) # Add new link. # Tell about it. print "Saving copy of Obit task input in" + tmpDebug path = os.environ['OBIT'] +'/bin/' + os.environ['ARCH'] + '/' + name arglist = [name, "-input", tmpInput, "-output", tmpOutput, "-pgmNumber", str(popsno), "-AIPSuser", str(userno)] tid = Task.spawn(self, path, arglist) self._params[tid] = params self._popsno[tid] = popsno return tid
def spawn(self, name, version, userno, msgkill, isbatch, input_dict): """Start the task.""" params = _ObitTaskParams(name, version) popsno = _allocate_popsno() index = popsno - 1 # Set input and output text parameter/result files tmpInput = "/tmp/" + params.name + "Input." + str(popsno) tmpOutput = "/tmp/" + params.name + "Output." + str(popsno) in_file = open(tmpInput, mode="w") for adverb in params.input_list: self.__write_adverb(params, in_file, adverb, input_dict[adverb]) in_file.close() # If debugging add a link to the input file to preserve it. if input_dict['DEBUG']: tmpDebug = tmpInput + 'Dbg' if os.access(tmpDebug, os.F_OK): os.unlink(tmpDebug) # Remove any old version file. os.link(tmpInput, tmpDebug) # Add new link. # Tell about it. print(("Saving copy of Obit task input in" + tmpDebug)) path = os.environ['OBIT'] + '/bin/' + os.environ['ARCH'] + '/' + name arglist = [ name, "-input", tmpInput, "-output", tmpOutput, "-pgmNumber", str(popsno), "-AIPSuser", str(userno) ] tid = Task.spawn(self, path, arglist) self._params[tid] = params self._popsno[tid] = popsno return tid
def spawn(self, name, version, userno, msgkill, isbatch, tv, input_dict): """Start the task.""" params = _AIPSTaskParams(name, version) popsno = _allocate_popsno() index = popsno - 1 try: # A single hardcoded TV will do until support for multiple # TVs is implemented. ntvdev = 1 # Construct the environment for the task. For the adverbs # like 'infile', 'outfile' and 'outprint', we split off # the directory component of the pathname and use that as # the area. env = os.environ.copy() area = 'a' for adverb in self._file_adverbs: if adverb in input_dict: assert(ord(area) <= ord('z')) dirname = os.path.dirname(input_dict[adverb]) if dirname: if not os.path.isdir(dirname): msg = "Direcory '%s' does not exist" % dirname raise RuntimeError, msg env[area] = dirname basename = os.path.basename(input_dict[adverb]) input_dict[adverb] = area + ':' + basename area = chr(ord(area) + 1) pass pass continue # Send output to the TV running on this machine. env['TVDEV'] = 'TVDEV01' env['TVDEV' + ehex(ntvdev, 2, 0)] = tv if tv.find(':') == -1: env['TVLOK'] = 'TVLOK01' env['TVLOK' + ehex(ntvdev, 2, 0)] = tv.replace('DEV', 'LOK') pass td_name = os.environ['DA00'] + '/TD' + AIPS.revision + '000004;' td_file = open(td_name, mode='r+b') td_file.seek(index * 20) td_file.write(struct.pack('8s', name.upper().ljust(8))) td_file.write(struct.pack('l', -999)) td_file.write(struct.pack('2l', 0, 0)) td_file.seek(1024 + index * 4096) td_file.write(struct.pack('i', userno)) td_file.write(struct.pack('i', ntvdev)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('i', msgkill + 32000 - 1)) td_file.write(struct.pack('i', isbatch)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('i', 1)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('f', 1.0)) td_file.write(struct.pack('4s', ' ')) for adverb in params.input_list: self.__write_adverb(params, td_file, adverb, input_dict[adverb]) continue td_file.close() # Create the message file if necessary and record the # number of messages currently in it. user = ehex(userno, 3, 0) ms_name = os.environ['DA01'] + '/MS' + AIPS.revision \ + user + '000.' + user + ';' if not os.path.exists(ms_name): ms_file = open(ms_name, mode='w') ms_file.truncate(1024) ms_file.close() os.chmod(ms_name, 0664) pass ms_file = open(ms_name, mode='r') (msgno,) = struct.unpack('i', ms_file.read(4)) ms_file.close() path = params.version + '/' + os.environ['ARCH'] + '/LOAD/' \ + name.upper() + ".EXE" tid = Task.spawn(self, path, [name.upper() + ehex(popsno)], env) except Exception, exception: _free_popsno(popsno) raise exception
def spawn(self, name, version, userno, msgkill, isbatch, input_dict): """Start the script.in an externak ObitTalk Writes script test into temporary file in /tmp and executes ObitTalk asynchronously returning immediately. Messages must be retrieved calling messages. name script name version version of any AIPS tasks userno AIPS user number msgkill AIPStask msgkill level, isbatch True if this is a batch process input_dict Input info as dictionary Returns script id """ popsno = _allocate_popsno() index = popsno - 1 self.name = name self.userno = userno try: # Construct the environment for the script. # Set AIPS and FITS directory variables env = os.environ.copy() # AIPS directories i = 0 for dirname in input_dict["AIPSDirs"]: i = i+1 area = 'DA' + ehex(i, 2, '0') env[area] = dirname # end AIPS dirs # FITS directories i = 0 for dirname in input_dict["FITSDirs"]: i = i+1 if i==1: area = "FITS" else: area = 'FITS' + ehex(i, 2, '0') env[area] = dirname # End FITS Dirs # print "script environment",env # print "PYTHONPATH",env["PYTHONPATH"] # Script text file sc_name = "/tmp/" + name+ "Script." + str(popsno)+".py" # Write script to file self.__write_script (self.name, userno, popsno, sc_name, input_dict) # If debugging add a link to the input file to preserve it. if input_dict['debug']: tmpDebug = "/tmp/" + name+ "Script." + str(popsno)+"Dbg.py" if os.access(tmpDebug, os.F_OK): os.unlink(tmpDebug) # Remove any old version file. os.link(sc_name, tmpDebug) # Add new link. # Tell about it. print("Saving copy of Obit task input in " + tmpDebug) # Start script in separate ObitTalk process. path = 'ObitTalk' tid = Task.spawn(self, path, ["ObitTalk", sc_name], env) except Exception as exception: _free_popsno(popsno) raise exception self._popsno[tid] = popsno self._userno[tid] = userno self._msgkill[tid] = msgkill self._msgno[tid] = 0 return tid
def spawn(self, name, version, userno, msgkill, isbatch, input_dict): """Start the task. Writes task input parameters in theTD file and starts the task asynchronously returning immediately. Messages must be retrieved calling messages. Attempts to use singel hardcoded AIPS TV name task name version version of task userno AIPS user number msgkill AIPS msgkill level, isbatch True if this is a batch process input_dict Input parameters as dictionary Returns task id """ params = _AIPSTaskParams(name, version) popsno = _allocate_popsno() index = popsno - 1 try: # A single hardcoded TV will do until support for multiple # TVs is implemented. ntvdev = 1 # Construct the environment for the task. For the 'infile', # 'outfile' and 'outprint' adverbs, we split off the directory # component of the pathname and use that as the area. env = os.environ.copy() area = 'a' for adverb in self._file_adverbs: if adverb in input_dict: assert (ord(area) <= ord('z')) dirname = os.path.dirname(input_dict[adverb]) if dirname: if not os.path.isdir(dirname): msg = "Directory '%s' does not exist" % dirname raise RuntimeError(msg) env[area] = dirname basename = os.path.basename(input_dict[adverb]) input_dict[adverb] = area + ':' + basename area = chr(ord(area) + 1) pass pass continue # Send output to the TV running on this machine. env['TVDEV' + ehex(ntvdev, 2, 0)] = 'sssin:localhost' # DEBUG #print "aips environment",env td_name = os.environ['DA00'] + '/TD' + AIPS.revision + '000004;' td_file = open(td_name, mode='r+b') td_file.seek(index * 20) td_file.write( struct.pack('8s', six.ensure_binary(name.upper().ljust(8)))) td_file.write(struct.pack('l', -999)) td_file.write(struct.pack('2l', 0, 0)) td_file.seek(1024 + index * 4096) td_file.write(struct.pack('i', userno)) td_file.write(struct.pack('i', ntvdev)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('i', msgkill + 32000 - 1)) td_file.write(struct.pack('i', isbatch)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('2i', 0, 0)) td_file.write(struct.pack('f', 1.0)) td_file.write(struct.pack('4s', b' ')) for adverb in params.input_list: self.__write_adverb(params, td_file, adverb, input_dict[adverb]) continue td_file.close() # Pass aips directories i = 0 for dir in input_dict["AIPSdirs"]: i += 1 daname = "DA" + ehex(i, 2, 0) if not name in env: env[daname] = dir # Create the message file if necessary and record the # number of messages currently in it. user = ehex(userno, 3, 0) if 'DA01' in os.environ: # Use DA01 from environment if given da01 = os.environ['DA01'] else: # Else from AIPSdirs passed. da01 = input_dict["AIPSdirs"][0] # Grumble, grumble os.environ['DA01'] = da01 cmd = "export DA01=" + da01 # shell environment z = os.system(cmd) ms_name = da01 + '/MS' + AIPS.revision \ + user + '000.' + user + ';' if not os.path.exists(ms_name): ms_file = open(ms_name, mode='w') ms_file.truncate(1024) ms_file.close() os.chmod(ms_name, 0o664) pass ms_file = open(ms_name, mode='rb') (msgno, ) = struct.unpack('i', ms_file.read(4)) ms_file.close() path = params.version + '/' + os.environ['ARCH'] + '/LOAD/' \ + name.upper() + ".EXE" tid = Task.spawn(self, path, [name.upper() + str(popsno)], env) except Exception as exception: _free_popsno(popsno) raise exception self._params[tid] = params self._popsno[tid] = popsno self._userno[tid] = userno self._msgkill[tid] = msgkill self._msgno[tid] = msgno return tid
def spawn(self, name, version, userno, msgkill, isbatch, input_list, input_dict, type_dict, dim_dict): """Start the task. Writes task input parameters, data directories and other information in the task parameter file and starts the task asynchronously returning immediately. Messages must be retrieved calling messages. If the debug parameter is True then a "Dbg" copy of the task input file is created which will not br automatically destroyed. name task name version version of task userno AIPS user number msgkill AIPS msgkill level, not used in Obit tasks isbatch True if this is a batch process , not used in Obit tasks input_list Input parameters list in order input_dict Input parameters as dictionary type_dict Input parameter types as dictionary dim_dict Input parameter dimensions as dictionary Returns task id """ params = _ObitTaskParams(name, version) popsno = _allocate_popsno() index = popsno - 1 # Set input and output text parameter/result files tmpInput = "/tmp/" + params.name + "Input." + str(popsno) tmpOutput = "/tmp/" + params.name + "Output." + str(popsno) in_file = open(tmpInput, mode="w") # Add user id input file in_file.write("$Key = AIPSuser Int (1)\n") in_file.write(str(userno) + "\n") # Add directories to input file - both types for 'AIPS' inType = input_dict['DataType'] outType = input_dict['DataType'] if "outDType" in input_dict: outType = input_dict["outDType"] if (inType == 'AIPS') or (outType == 'AIPS'): AIPSdirs = input_dict["AIPSdirs"] nAIPS = len(AIPSdirs) in_file.write("$Key = nAIPS Int (1)\n") in_file.write(str(nAIPS) + "\n") in_file.write("$Key = AIPSdirs Str (128," + str(nAIPS) + ")\n") for x in AIPSdirs: in_file.write(x + "\n") FITSdirs = input_dict["FITSdirs"] nFITS = len(FITSdirs) in_file.write("$Key = nFITS Int (1)\n") in_file.write(str(nFITS) + "\n") in_file.write("$Key = FITSdirs Str (128," + str(nFITS) + ")\n") for x in FITSdirs: in_file.write(x + "\n") elif (input_dict['DataType'] == 'FITS') or (input_dict['outDType'] == 'FITS'): FITSdirs = input_dict["FITSdirs"] nFITS = len(FITSdirs) in_file.write("$Key = nFITS Int (1)\n") in_file.write(str(nFITS) + "\n") in_file.write("$Key = FITSdirs Str (128," + str(nFITS) + ")\n") for x in FITSdirs: in_file.write(x + "\n") for adverb in input_list: if adverb in type_dict: self.__write_adverb(self, in_file, adverb, \ input_dict[adverb], type_dict[adverb], dim_dict[adverb]) in_file.close() # If debugging add a link to the input file to preserve it. if input_dict['DEBUG']: tmpDebug = tmpInput + 'Dbg' if os.access(tmpDebug, os.F_OK): os.unlink(tmpDebug) # Remove any old version file. os.link(tmpInput, tmpDebug) # Add new link. # Tell about it. print("Saving copy of Obit task input in " + tmpDebug) path = name if (not os.access(path, os.F_OK)) and (os.getenv("OBITEXEC") != None): path = os.environ['OBITEXEC'] + '/bin/' + name if (not os.access(path, os.F_OK)) and (os.getenv("OBIT") != None): path = os.environ['OBIT'] + '/bin/' + name # Check OBITSD if needbe if (not os.access(path, os.F_OK)) and (os.getenv('OBITSD') != None): path = os.getenv('OBITSD') + '/bin/' + name # Check standard linux directory if needbe if (not os.access(path, os.F_OK)): path = "/usr/lib/obit/bin/" + name # Better have found it by here if (not os.access(path, os.F_OK)): # Oh bugger msg = "Task '%s' executable not found" % (name) print(msg) raise RuntimeError(msg) arglist = [ name, "-input", tmpInput, "-output", tmpOutput, "-pgmNumber", str(popsno), "-AIPSuser", str(userno) ] tid = Task.spawn(self, path, arglist) self._params[tid] = params self._popsno[tid] = popsno return tid
def spawn(self, name, version, userno, msgkill, isbatch, tv, input_dict): """Start the task.""" params = _AIPSTaskParams(name, version) popsno = _allocate_popsno() index = popsno - 1 try: # A single hardcoded TV will do until support for multiple # TVs is implemented. ntvdev = 1 # Construct the environment for the task. For the adverbs # like 'infile', 'outfile' and 'outprint', we split off # the directory component of the pathname and use that as # the area. env = os.environ.copy() area = 'a' for adverb in self._file_adverbs: if adverb in input_dict: assert(ord(area) <= ord('z')) dirname = os.path.dirname(input_dict[adverb]) if dirname: if not os.path.isdir(dirname): msg = "Direcory '%s' does not exist" % dirname raise RuntimeError(msg) env[area] = dirname basename = os.path.basename(input_dict[adverb]) input_dict[adverb] = area + ':' + basename area = chr(ord(area) + 1) pass pass continue # Send output to the TV running on this machine. env['TVDEV'] = 'TVDEV01' env['TVDEV' + ehex(ntvdev, 2, 0)] = tv if tv.find(':') == -1: env['TVLOK'] = 'TVLOK01' env['TVLOK' + ehex(ntvdev, 2, 0)] = tv.replace('DEV', 'LOK') pass td_name = os.environ['DA00'] + '/TD' + AIPS.revision + '000004;' td_file = open(td_name, mode='r+b') td_file.seek(index * 20) td_file.write(struct.pack('8s', name.upper().ljust(8).encode('utf-8'))) td_file.write(struct.pack('l', -999)) td_file.write(struct.pack('2l', 0, 0)) td_file.seek(1024 + index * 4096) td_file.write(struct.pack('i', userno)) td_file.write(struct.pack('i', ntvdev)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('i', msgkill + 32000 - 1)) td_file.write(struct.pack('i', isbatch)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('i', 1)) td_file.write(struct.pack('i', 0)) td_file.write(struct.pack('f', 1.0)) td_file.write(struct.pack('4s', b' ')) for adverb in params.input_list: self.__write_adverb(params, td_file, adverb, input_dict[adverb]) continue td_file.close() # Create the message file if necessary and record the # number of messages currently in it. user = ehex(userno, 3, 0) ms_name = os.environ['DA01'] + '/MS' + AIPS.revision \ + user + '000.' + user + ';' if not os.path.exists(ms_name): ms_file = open(ms_name, mode='wb') ms_file.truncate(1024) ms_file.close() os.chmod(ms_name, 0o664) pass ms_file = open(ms_name, mode='rb') (msgno,) = struct.unpack('i', ms_file.read(4)) ms_file.close() path = params.version + '/' + os.environ['ARCH'] + '/LOAD/' \ + name.upper() + ".EXE" tid = Task.spawn(self, path, [name.upper() + ehex(popsno)], env) except Exception as exception: _free_popsno(popsno) raise exception self._params[tid] = params self._popsno[tid] = popsno self._userno[tid] = userno self._msgkill[tid] = msgkill self._msgno[tid] = msgno return tid