예제 #1
0
    def wait(self, tid):
        """Wait for the task to finish."""

        assert(self.finished(tid))

        params = self._params[tid]
        popsno = self._popsno[tid]
        index = popsno - 1

        tmpInput = "/tmp/" + params.name + "Input." + str(popsno)
        tmpOutput = "/tmp/" + params.name + "Output." + str(popsno)

        output_dict = {}
        for adverb in params.output_list:
            # Need to parse whole file each time as order not specified
            out_file = open(tmpOutput, mode='r')
            output_dict[adverb] = self.__read_adverb(params, out_file, adverb)
            out_file.close()

        if os.access(tmpInput, os.F_OK):
            os.unlink(tmpInput)         # Remove input file.
        if os.access(tmpOutput, os.F_OK):
            os.unlink(tmpOutput)        # Remove output file.

        _free_popsno(popsno)

        del self._params[tid]
        del self._popsno[tid]
        Task.wait(self, tid)

        return output_dict
예제 #2
0
 def __init__(self):
     Task.__init__(self)
     self._params = {}
     self._popsno = {}
     self._userno = {}
     self._msgno = {}
     self._msgkill = {}
예제 #3
0
파일: ObitScriptP.py 프로젝트: mauch/Obit-1
 def __init__(self):
     Task.__init__(self)
     self._popsno = {}
     self._userno = {}
     self._msgno = {}
     self._msgkill = {}
     self.POPSpid = os.getpid()
예제 #4
0
    def wait(self, tid):
        """Wait for the task to finish."""

        assert (self.finished(tid))

        params = self._params[tid]
        popsno = self._popsno[tid]
        index = popsno - 1

        tmpInput = "/tmp/" + params.name + "Input." + str(popsno)
        tmpOutput = "/tmp/" + params.name + "Output." + str(popsno)

        output_dict = {}
        for adverb in params.output_list:
            # Need to parse whole file each time as order not specified
            out_file = open(tmpOutput, mode='r')
            output_dict[adverb] = self.__read_adverb(params, out_file, adverb)
            out_file.close()

        if os.access(tmpInput, os.F_OK):
            os.unlink(tmpInput)  # Remove input file.
        if os.access(tmpOutput, os.F_OK):
            os.unlink(tmpOutput)  # Remove output file.

        _free_popsno(popsno)

        del self._params[tid]
        del self._popsno[tid]
        Task.wait(self, tid)

        return output_dict
예제 #5
0
 def __init__(self):
     Task.__init__(self)
     self._params = {}
     self._popsno = {}
     self._userno = {}
     self._msgno = {}
     self._msgkill = {}
예제 #6
0
    def messages(self, tid):
        """Return task's messages."""

        # Make sure we read the messages, even if we throw them away
        # later to prevent the task from blocking.
        messages = Task.messages(self, tid)

        # Strip out all formal messages.
        start = '%-5s%d' % (self._params[tid].name.upper(), self._popsno[tid])
        messages = [msg for msg in messages if not msg.startswith(start)]

        messages = [(1, msg) for msg in messages]

        user = ehex(self._userno[tid], 3, 0)
        ms_name = os.environ['DA01'] + '/MS' + AIPS.revision \
                  + user + '000.' + user + ';'
        ms_file = open(ms_name, mode='r')

        (msgno,) = struct.unpack('i', ms_file.read(4))
        while self._msgno[tid] < msgno:
            (task, popsno, priority, msg) = \
                   self.__read_message(ms_file, self._msgno[tid])
            # Filter
            if popsno == self._popsno[tid]:
                messages.append((priority, '%-5s%d: %s' % (task, popsno, msg)))
                pass
            self._msgno[tid] += 1
            continue

        ms_file.close()
        return messages
예제 #7
0
    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
예제 #8
0
    def messages(self, tid):
        """Return task's messages."""

        # Make sure we read the messages, even if we throw them away
        # later to prevent the task from blocking.
        messages = Task.messages(self, tid)

        # Strip out all formal messages.
        name = self._params[tid].name.upper()
        start = '%-5s%c' % (name, ehex(self._popsno[tid]))
        messages = [msg for msg in messages if not msg.startswith(start)]

        messages = [(1, msg) for msg in messages]

        user = ehex(self._userno[tid], 3, 0)
        ms_name = os.environ['DA01'] + '/MS' + AIPS.revision \
                  + user + '000.' + user + ';'
        ms_file = open(ms_name, mode='rb')

        (msgno,) = struct.unpack('i', ms_file.read(4))
        while self._msgno[tid] < msgno:
            (task, popsno, priority, msg) = \
                   self.__read_message(ms_file, self._msgno[tid])
            # Filter
            if popsno == self._popsno[tid]:
                msg = '%-5s%c: %s' % (task, ehex(popsno), msg)
                messages.append((priority, msg))
                pass
            self._msgno[tid] += 1
            continue

        ms_file.close()
        return messages
예제 #9
0
파일: AIPSTask.py 프로젝트: mauch/Obit
    def messages(self, tid):
        """Return task's messages.
        
        Return a list of messages each as a tuple (1, message)
        tid   = Task id in pid table of process
        """

        # Make sure we read the messages, even if we throw them away
        # later to prevent the task from blocking.
        messages = Task.messages(self, tid)
        #print "Raw",messages

        # Check that tid in bounds
        #if tid>len(self._popsno):
        #    print "DEBUG Proxy/AIPSTask", messages, tid, len(self._popsno)
        #    return messages

        # Convert into list of lines
        tmessage = []
        for msg in messages:
            lmess = msg.splitlines(True)
            for mm in lmess:
                tmessage.append(mm)

        # Strip out all formal messages.
        start = '%-5s%d' % (self._params[tid].name.upper(), self._popsno[tid])
        lmessages = [msg for msg in tmessage if msg.startswith(start)]
        #print "Filtered",lmessages
        pmessages = [msg for msg in tmessage if not msg.startswith(start)]
        #print "Print",pmessages

        # These messages will be looked up in the AIPS message log
        #messages = [(1, msg) for msg in lmessages]
        messages = []

        user = ehex(self._userno[tid], 3, 0)
        ms_name = os.environ['DA01'] + '/MS' + AIPS.revision \
                  + user + '000.' + user + ';'
        ms_file = open(ms_name, mode='r')

        (msgno,) = struct.unpack('i', ms_file.read(4))
        while self._msgno[tid] < msgno:
            (task, popsno, priority, msg) = \
                   self.__read_message(ms_file, self._msgno[tid])
            # Filter
            if popsno == self._popsno[tid]:
                messages.append((priority, '%-5s%d: %s\n' % (task, popsno, msg)))
                pass
            self._msgno[tid] += 1
            continue

        ms_file.close()
        # Add "print" messages
        if len(pmessages)>0:
            for msg in pmessages:
                messages.append((1,msg))
        #print "returned messages",messages
        return messages
예제 #10
0
파일: ObitTask.py 프로젝트: mauch/Obit-1
    def wait(self, tid):
        """Wait for the task to finish.
        
        Waits for Obit task to finishes, reads the task output
        parameter file and deleted tas input and output parameter
        file. 
        Returns output parameters in adictionary.
        tid   = Task id in pid table of process
        """

        assert (self.finished(tid))

        params = self._params[tid]
        popsno = self._popsno[tid]
        index = popsno - 1

        tmpInput = "/tmp/" + params.name + "Input." + str(popsno)
        tmpOutput = "/tmp/" + params.name + "Output." + str(popsno)

        output_dict = {}
        for adverb in params.output_list:
            out_file = open(tmpOutput, mode='r')
            # Need to parse whole file each time as order not specified
            val = self.__read_adverb(params, out_file, adverb)
            output_dict[adverb] = val
            out_file.close()

        _free_popsno(popsno)  # Release Pops number

        if os.access(tmpInput, os.F_OK):
            os.unlink(tmpInput)  # Remove input file.
        if os.access(tmpOutput, os.F_OK):
            os.unlink(tmpOutput)  # Remove output file.

        # Check if terminated normally
        retCode = output_dict["retCode"]
        if retCode != 0:
            msg = "Task '%s' returns '%d'" % (params.name, retCode)
            raise RuntimeError(msg)

        del self._params[tid]
        del self._popsno[tid]
        Task.wait(self, tid)

        return output_dict
예제 #11
0
파일: AIPSTask.py 프로젝트: mauch/Obit-1
    def wait(self, tid):
        """Wait for the task to finish.

        When task returns, the output parameters are parser from the
        TD file.
        Returns output parameters in adictionary.
        tid   = Task id in pid table of process
        """

        assert (self.finished(tid))

        params = self._params[tid]
        popsno = self._popsno[tid]
        index = popsno - 1

        td_name = os.environ['DA00'] + '/TDD000004;'
        try:
            td_file = open(td_name, mode='rb')

            td_file.seek(index * 20 + 8)
            (result, ) = struct.unpack('i', td_file.read(4))
            if result != 0:
                msg = "Task '%s' returns '%d'" % (params.name, result)
                raise RuntimeError(msg)

            td_file.seek(1024 + index * 4096 + 40)
            output_dict = {}
            for adverb in params.output_list:
                output_dict[adverb] = self.__read_adverb(
                    params, td_file, adverb)

            td_file.close()

        finally:
            _free_popsno(popsno)
            pass

        del self._params[tid]
        del self._popsno[tid]
        del self._userno[tid]
        del self._msgno[tid]
        Task.wait(self, tid)

        return output_dict
예제 #12
0
파일: ObitTask.py 프로젝트: mauch/Obit-1
    def messages(self, tid):
        """Return task's messages.
        
        Return a list of messages each as a tuple (1, message)
        tid   = Task id in pid table of process
        """

        # Add a default priority to the messages
        messages = Task.messages(self, tid)
        return [(1, msg) for msg in messages]
예제 #13
0
    def abort(self, tid, sig=signal.SIGTERM):
        """Abort a task."""

        _free_popsno(self._popsno[tid])

        del self._params[tid]
        del self._popsno[tid]
        del self._userno[tid]
        del self._msgno[tid]

        return Task.abort(self, tid, sig)
예제 #14
0
    def abort(self, tid, sig=signal.SIGTERM):
        """Abort a task."""

        _free_popsno(self._popsno[tid])

        del self._params[tid]
        del self._popsno[tid]
        del self._userno[tid]
        del self._msgno[tid]

        return Task.abort(self, tid, sig)
예제 #15
0
파일: ObitScriptP.py 프로젝트: mauch/Obit-1
    def messages(self, tid):
        """Return script's messages.
        
        Return a list of messages each as a tuple (1, message)
        tid   = Script id in pid table of process
        """

        # Make sure we read the messages, even if we throw them away
        # later to prevent the script from blocking.
        messages = Task.messages(self, tid)

        return [(1, msg) for msg in messages]
예제 #16
0
    def wait(self, tid):
        """Wait for the task to finish."""

        assert(self.finished(tid))

        params = self._params[tid]
        popsno = self._popsno[tid]
        index = popsno - 1

        td_name = os.environ['DA00'] + '/TDD000004;'

        try:
            td_file = open(td_name, mode='rb')

            td_file.seek(index * 20 + 8)
            (result,) = struct.unpack('i', td_file.read(4))
            if result != 0:
                msg = "Task '%s' returns '%d'" % (params.name, result)
                raise RuntimeError, msg

            td_file.seek(1024 + index * 4096 + 40)
            output_dict = {}
            for adverb in params.output_list:
                output = self.__read_adverb(params, td_file, adverb)
                output_dict[adverb] = output
                continue

            td_file.close()

        finally:
            _free_popsno(popsno)
            pass

        del self._params[tid]
        del self._popsno[tid]
        del self._userno[tid]
        del self._msgno[tid]
        Task.wait(self, tid)

        return output_dict
예제 #17
0
파일: ObitScriptP.py 프로젝트: mauch/Obit-1
    def wait(self, tid):
        """Wait for the script to finish.

        Waits until script is finished
        tid   = Script id in pid table of process
        """

        assert(self.finished(tid))
        
        # Cleanup
        popsno = self._popsno[tid]
        _free_popsno(self._popsno[tid])
        del self._popsno[tid]
        del self._userno[tid]
        del self._msgno[tid]
        # wait
        Task.wait(self, tid)
        
        # Delete Script text file
        sc_name = "/tmp/" + self.name+ "Script." + str(popsno)+".py"
        if os.access(sc_name, os.F_OK):
            os.unlink(sc_name)
        
        return True  # Return something other than None
예제 #18
0
파일: ObitScriptP.py 프로젝트: mauch/Obit-1
    def abort(self, tid, sig=signal.SIGTERM):
        """Abort the script specified by PROXY and TID.
        
        Calls abort function for script tid on proxy.
        No return value
        proxy = Proxy giving access to server
        tid   = Script id in pid table of process to be terminated
        sig   = signal to sent to the script
                ObitScript seems to ignore SIGINT, so use SIGTERM instead.
        """

        _free_popsno(self._popsno[tid])

        del self._popsno[tid]
        del self._userno[tid]
        del self._msgno[tid]

        return Task.abort(self, tid, sig)
예제 #19
0
    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
예제 #20
0
    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
예제 #21
0
    def messages(self, tid):
        """Return task's messages."""

        # Add a default priority to the messages
        messages = Task.messages(self, tid)
        return [(1, msg) for msg in messages]
예제 #22
0
파일: ObitScriptP.py 프로젝트: mauch/Obit-1
    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
예제 #23
0
파일: ObitTask.py 프로젝트: mauch/Obit-1
 def __init__(self):
     Task.__init__(self)
     self._params = {}
     self._popsno = {}
예제 #24
0
 def __init__(self):
     Task.__init__(self)
     self._params = {}
     self._popsno = {}
예제 #25
0
파일: ObitTask.py 프로젝트: mauch/Obit-1
    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
예제 #26
0
파일: AIPSTask.py 프로젝트: mauch/Obit-1
    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
예제 #27
0
    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
예제 #28
0
    def messages(self, tid):
        """Return task's messages."""

        # Add a default priority to the messages
        messages = Task.messages(self, tid)
        return [(1, msg) for msg in messages]