Пример #1
0
    def query(self):

        try:
            sc = ShellCommand([self.queryCmd], self.logger, 100, None, True)
        except:
            self.status = -1
            self.output = 'query %s failed' % self.queryCmd
            return

        self.status = 0
        self.output = string.join(sc.getReply(), '\n')
Пример #2
0
 def stopJob(self):
     if self.done: return
     
     try:
         cmd = ['bkill ' + str(self.pid)]
         sc       = ShellCommand(cmd, self.logger, 100, None, True)
         self.logger.debug(sc.getReply())
     except Exception, e:
         m  = 'Job: ' + str(self.identifiedName)
         m += ' threw an exception while issuing cmd: %s' % cmd[0] 
         self.logger.warning(m)
Пример #3
0
    def fire(self, what):
        """
        Submits the job by spawning a subprocess.
        The Popen objects captures std error, and std out
        'what' is a a key in to tthe self.scripts dictionary
        """

        cmd = self.scripts[what]['cmd']

        m = 'fire commandL\n: %s' % cmd
        self.logger.debug(m)

        sc = ShellCommand([cmd], self.logger)
        self.subLog = sc.getReply()
Пример #4
0
def findJobOptionsSearchPath(cmds, paths, logger):

    logger.debug('Calculating JOBOPTIONSSEARCHPATH')

    # cmds.extend(['source setup.sh'])
    cmds.extend(['echo $JOBOPTSEARCHPATH', 'echo $PATH'])

    nlines = -1  # do not limit the number of lines
    shellCom = ShellCommand(cmds, logger, nlines)
    reply = shellCom.getReply()
    #m = 'Reply on setting up CMT to find JO searchpath: %s' % str(reply)
    #logger.debug(m)
    searchPath = ''
    # the env variable path will be used e.g. to locate pre athena scripts
    PATH = ''

    if len(reply) > 1:
        searchPath = reply[-2]
        PATH = reply[-1]
        # These paths are critical to all Athena jobs. As these are most
        # of the RTT jobs, give up if the search path is not set.
    else:
        m = """Could not obtain env vars JOBOPTSEARCHPATH and PATH,
        cmds sent to seek env variables:
        %s
        Reply:  %s
        abandoning run """ % (str(cmds), str(reply))
        logger.critical(m)
        raise RTTInputError(m)

    # logger.debug('Found JOBOPTSEARCHPATH: %s' % searchPath)
    # logger.debug('Found PATH: %s' % PATH)

    def jobOpSearchPathSepChar():
        if paths.isNightly: return ':'
        if int(paths.release.split('.')[0]) < 13: return ','
        return ':'

    searchPaths = {
        'jobOptionsSearchPath': {
            'path': searchPath,
            'separater': jobOpSearchPathSepChar()
        },
        'PATH': {
            'path': PATH,
            'separater': ':'
        }
    }

    return searchPaths
Пример #5
0
def configureCMTDirs(localRTTRun, cmtConfigurer, logger):
    # Not necessary if this is a local run
    if localRTTRun:
        logger.info('Local run, not configuring CMT dir')
        return

    cmtConfigurer.makeHomeCMTDir()

    nlines = -1  # do not limit the number of lines
    cmds = [cmtConfigurer.configure()]
    logger.info('cmds to configure cmt dir:\n%s' % str(cmds))
    shellCom = ShellCommand(cmds, logger, nlines)
    reply = shellCom.getReply()
    m = 'Reply on configuring CMT: %s' % str(reply)
    logger.info(m)
Пример #6
0
 def batchReplyProvesJobIsAbsentFromQueue(self, reply):
     """if the original bjobs command returned a 1 line reply
     it might be the case that the job is part of the history.
     check the history to see if the job is known.
     if so, assume the job ran."""
     
     if not reply: return False
     if len(reply) == 1:
         sc = ShellCommand(['bhist %s' % str(self.pid)], self.logger)
         if len(sc.getReply())>1:
             return True
         else:
             return False
         
     return not self.batchReplyProvesJobIsInQueue(reply)
Пример #7
0
    def run(self):
        # check the macro exists. NOTE: this cannot be done in __init__ because
        # class instantiation occurs before copying of auxFilePatterns.
        if not self.macroExists():
            self.logger.warning("Root macro does not exit")
            return 1

        # note the current directory to reset it later
        currCwd = os.getcwd()

        # cmds = []
        # following cd must be part of the shell command has so other threads
        # cant mess it up
        # cmds.append('cd ' + self.runPath)
        # cmds.extend(self.rootCmds)
        self.logger.info("Launching macro " + str(self.rootCmds))

        # to import, need the RTT src dir. tried to do the import in __init__.
        # Could import there, but ShellCommand was not visible here.
        from ShellCommand import ShellCommand
        sc = ShellCommand(self.rootCmds, self.logger, self.maxPrintLines,
                          self.timeLimit)

        reply = sc.getReply()
        [self.logger.debug(str(l)) for l in reply]
        # reset the current directory as it was before
        os.chdir(currCwd)

        # reply is a list of strings, let's turn it into a single string
        replyString = reduce(lambda x, y: x + y + '\n', reply, '')

        # output reply to the logger
        name = str(self.identifiedName)
        msg = 'root command output for job %s\n %s' % (name, replyString)
        self.logger.info(msg)

        # Also output reply to file 'ROOToutput.log' in the run path
        # This file is a keep file pattern in the TopLevelJobGroup.xml file.
        h = open(os.path.join(self.runPath, 'ROOToutput.log'), 'a+')
        h.write(replyString)
        h.close()

        return 0
Пример #8
0
 def run( self ):
       if ( self.error == None ):
             try:
                   from ShellCommand import ShellCommand
                   # FIXME - self.logger could be just python False...
                   sc = ShellCommand( self.command,
                                      self.logger ) 
                   replay = sc.getReply()
                   reLine = re.compile("OVERALL STATISTICS STATUS")
                   status = 1
                   for line in replay:
                         for apiClass in self.__reAPIClasses:
                               if ( apiClass.search( line ) ):
                                     self.debug( line )
                                     if ( reLine.search( line ) ):
                                           if ( "OK" in line ): status = 0
                               
                   return status
             except ImportError: 
                   self.info("No ShellCommand in PYTHONPATH! 'No Cin-Cin, no run...'")
                   return 1
       else:
             self.info(self.error)
             return 1
Пример #9
0
    def run(self):
        if (self.error == None):
            try:
                from ShellCommand import ShellCommand
                # FIXME - self.logger could be just python False...
                sc = ShellCommand(self.command, self.logger)
                replay = sc.getReply()
                reLine = re.compile("OVERALL STATISTICS STATUS")
                status = 1
                for line in replay:
                    for apiClass in self.__reAPIClasses:
                        if (apiClass.search(line)):
                            self.debug(line)
                            if (reLine.search(line)):
                                if ("OK" in line): status = 0

                return status
            except ImportError:
                self.info(
                    "No ShellCommand in PYTHONPATH! 'No Cin-Cin, no run...'")
                return 1
        else:
            self.info(self.error)
            return 1
Пример #10
0
 def execute(self):
     for c in self.commands.keys():
         sc = ShellCommand([c], self.logger)
         reply = sc.getReply()
         # [self.logger.debug(r) for r in reply]
         self.commands[c].append(reply)