def _parseStatusX(self, lines): adder = lambda a, b: utils.QM('=====' not in b and b != '\n', a + b, a) remap = { 'destination': 'dest', 'status reason': 'reason', 'status info for the job': 'id', 'current status': 'status', 'submitted': 'timestamp', 'reached': 'timestamp', 'exit code': 'gridexit' } for section in utils.accumulate(lines, lambda x, buf: ('=' * 70) in x, '', opAdd=adder): data = utils.DictFormat(':').parse( str.join('', section), keyParser={None: lambda k: remap.get(k, str)}) data = utils.filterDict(data, vF=lambda v: v) if data: try: if 'failed' in data['status']: data['status'] = 'failed' else: data['status'] = data['status'].split()[0].lower() except Exception: pass try: data['timestamp'] = int( time.mktime(parsedate(data['timestamp']))) except Exception: pass yield data
def parseParameterOption(option): result = map(str.strip, utils.split_advanced(option.lower(), lambda t: t in ')]}', lambda t: True)) if len(result) and '(' in result[0]: validChar = lambda c: c.isalnum() or (c in ['_']) result[0] = tuple(utils.accumulate(result[0], '', lambda i, b: not validChar(i), lambda i, b: validChar(i))) elif len(result) == 1: result = map(str.strip, result[0].split(' ', 1)) if len(result) == 1: result.append(None) return tuple(result)
def _parse(self, proc): for section in utils.accumulate(proc.stdout.iter(self._timeout), '', lambda x, buf: x == '\n'): try: lines = section.replace('\n\t', '').split('\n') job_info = utils.DictFormat(' = ').parse(lines[1:]) job_info[CheckInfo.WMSID] = lines[0].split(':')[1].split('.')[0].strip() job_info[CheckInfo.RAW_STATUS] = job_info.pop('job_state') job_info[CheckInfo.QUEUE] = job_info.pop('queue', None) if 'exec_host' in job_info: job_info[CheckInfo.WN] = job_info.pop('exec_host').split('/')[0] + '.' + job_info.get('server', '') except Exception: raise BackendError('Error reading job info:\n%s' % section) yield job_info
def parseStatus(self, status): for section in utils.accumulate(status, '', lambda x, buf: x == '\n'): try: lines = section.replace('\n\t', '').split('\n') jobinfo = utils.DictFormat(' = ').parse(lines[1:]) jobinfo['id'] = lines[0].split(':')[1].split('.')[0].strip() jobinfo['status'] = jobinfo.get('job_state') jobinfo['dest'] = 'N/A' if 'exec_host' in jobinfo: jobinfo['dest'] = '%s/%s' % ( jobinfo.get('exec_host').split('/')[0] + '.' + jobinfo.get('server', ''), jobinfo.get('queue')) except Exception: raise BackendError('Error reading job info:\n%s' % section) yield jobinfo
def parseParameterOption(option): # first token is variable / tuple - rest is option specifier: "a option" or "(a,b) option" tokens = list(utils.split_brackets(option.lower())) if len(tokens) and '(' in tokens[0]: # parse tuple in as general way as possible def validChar(c): return c.isalnum() or (c in ['_']) result = [tuple(utils.accumulate(tokens[0], '', lambda i, b: not validChar(i), lambda i, b: validChar(i)))] if tokens[1:]: result.append(str.join('', tokens[1:]).strip()) else: result = str.join('', tokens).strip().split(' ', 1) if len(result) == 1: result.append(None) return tuple(result)
def parseParameterOption(option): # first token is variable / tuple - rest is option specifier: "a option" or "(a,b) option" tokens = list(split_brackets(option.lower())) if len(tokens) and '(' in tokens[0]: # parse tuple in as general way as possible def validChar(c): return c.isalnum() or (c in ['_']) result = [tuple(utils.accumulate(tokens[0], '', lambda i, b: not validChar(i), lambda i, b: validChar(i)))] if tokens[1:]: result.append(str.join('', tokens[1:]).strip()) else: result = str.join('', tokens).strip().split(' ', 1) if len(result) == 1: result.append(None) return tuple(result)
def parseStatus(self, status): for section in utils.accumulate(status, '', lambda x, buf: x == '\n'): try: lines = section.replace('\n\t', '').split('\n') jobinfo = utils.DictFormat(' = ').parse(lines[1:]) jobinfo['id'] = lines[0].split(':')[1].split('.')[0].strip() jobinfo['status'] = jobinfo.get('job_state') jobinfo['dest'] = 'N/A' if 'exec_host' in jobinfo: jobinfo['dest'] = '%s/%s' % ( jobinfo.get('exec_host').split('/')[0] + '.' + jobinfo.get('server', ''), jobinfo.get('queue') ) except Exception: raise BackendError('Error reading job info:\n%s' % section) yield jobinfo
def _parse(self, proc): for section in utils.accumulate(proc.stdout.iter(self._timeout), '', lambda x, buf: x == '\n'): try: lines = section.replace('\n\t', '').split('\n') job_info = utils.DictFormat(' = ').parse(lines[1:]) job_info[CheckInfo.WMSID] = lines[0].split(':')[1].split( '.')[0].strip() job_info[CheckInfo.RAW_STATUS] = job_info.pop('job_state') job_info[CheckInfo.QUEUE] = job_info.pop('queue', None) if 'exec_host' in job_info: job_info[CheckInfo.WN] = job_info.pop('exec_host').split( '/')[0] + '.' + job_info.get('server', '') except Exception: raise BackendError('Error reading job info:\n%s' % section) yield job_info
def _parseTickets(self, cached = True): # Return cached results if requested if cached and self._cache: return self._cache # Call klist and parse results proc = utils.LoggedProcess(self._klistExec, '-v') retCode = proc.wait() self._cache = {} for sectionInfo in utils.accumulate(proc.getOutput(), '', lambda x, buf: buf.endswith('\n\n')): parseDate = lambda x: time.mktime(parsedate(x)) tmp = utils.DictFormat(':').parse(sectionInfo, valueParser = {'auth time': parseDate, 'start time': parseDate, 'end time': parseDate, 'renew till': parseDate}) if 'server' in tmp: self._cache[tmp['server']] = tmp else: self._cache[None] = tmp return self._cache
def _parseStatusX(self, lines): adder = lambda a, b: utils.QM('=====' not in b and b != '\n', a + b, a) remap = { 'destination': 'dest', 'status reason': 'reason', 'status info for the job': 'id', 'current status': 'status', 'submitted': 'timestamp', 'reached': 'timestamp', 'exit code': 'gridexit' } for section in utils.accumulate(lines, lambda x, buf: ('='*70) in x, '', opAdd = adder): data = utils.DictFormat(':').parse(str.join('', section), keyParser = {None: lambda k: remap.get(k, str)}) data = utils.filterDict(data, vF = lambda v: v) if data: try: if 'failed' in data['status']: data['status'] = 'failed' else: data['status'] = data['status'].split()[0].lower() except Exception: pass try: data['timestamp'] = int(time.mktime(parsedate(data['timestamp']))) except Exception: pass yield data