def init_session(g_vars, qaConf): g_vars.curr_date = qa_util.date() g_vars.session = g_vars.curr_date g_vars.session_logdir = os.path.join(g_vars.res_dir_path, 'session_logs', g_vars.curr_date) qaConf.addOpt('SESSION', g_vars.session) qaConf.addOpt('SESSION_LOGDIR', g_vars.session_logdir) if qaConf.isOpt('SHOW'): return qa_util.mkdirP(g_vars.session_logdir) # error --> exit with open(os.path.join(g_vars.session_logdir, 'pid.' + g_vars.pid), 'w') as fd: fd.write(os.getcwd() + '\n') for a in sys.argv: fd.write(' ' + a) fd.write(' --fpid ' + str(g_vars.pid) + '\n') return
def init_session(g_vars, qaOpts): g_vars.curr_date = qa_util.date() g_vars.session = g_vars.curr_date g_vars.session_logdir = os.path.join(g_vars.res_dir_path, 'session_logs', g_vars.curr_date) qaOpts.setOpt('SESSION', g_vars.session) qaOpts.setOpt('SESSION_LOGDIR', g_vars.session_logdir) if qaOpts.isOpt('SHOW'): return qa_util.mkdirP(g_vars.session_logdir) # error --> exit with open(os.path.join(g_vars.session_logdir, 'pid.' + g_vars.pid), 'w') as fd: fd.write( os.getcwd() + '\n') for a in sys.argv: fd.write(' ' + a) fd.write(' --fpid ' + str(g_vars.pid) + '\n') return
def set_preamble(self, opts): entry = ['---'] entry.append('# Log-file created by QA-DKRZ') entry.append('configuration:') s = self.indent[1] + 'command-line: ' for arg in sys.argv: s += ' ' + arg entry.append(s) entry.append(self.indent[1] + 'options:') for kv in qa_util.get_sorted_options(opts, sep=': '): if kv[:7] == 'TABLES:': entry.append(self.indent[2] + 'TABLES:') for tkv in qa_util.get_sorted_options(opts['TABLES'], sep=': '): entry.append(self.indent[3] + '- ' + tkv) continue elif kv[:6] == 'TABLE_': # taken into account above continue elif kv[:8] == 'install:': # skip internal opt continue entry.append(self.indent[2] + kv) entry.append('start:') entry.append(self.indent[1] + 'date: ' + qa_util.date()) entry.append(self.indent[1] + 'qa-revision: ' + self.opts['QA_VERSION']) entry.append('items:') return entry
def set_preamble(self, opts): entry = ['---'] entry.append('# Log-file created by QA-DKRZ') entry.append('configuration:') s = self.indent[1] + 'command-line: ' for arg in sys.argv: s += ' ' + arg entry.append(s) entry.append(self.indent[1] + 'options:') for kv in qa_util.get_sorted_options(opts, sep=': '): if kv[:7] == 'TABLES:': entry.append(self.indent[2] + 'TABLES:') for tkv in qa_util.get_sorted_options(opts['TABLES'], sep=': '): entry.append(self.indent[3] + '- ' + tkv) continue elif kv[:6] == 'TABLE_': # taken into account above continue elif kv[:8] == 'install:': # skip internal opt continue entry.append(self.indent[2] + kv) entry.append('start:') entry.append(self.indent[1] + 'date: ' + qa_util.date()) entry.append(self.indent[1] + 'qa-revision: ' + self.opts['QA_REVISION']) entry.append('items:') return entry
def append(self, entry_id='', f='', d_path='' , r_path ='' , start =[] , info =[] , txt ='', status =-1 , set_qa_lock = False, conclusion ='' , indent=-1, is_events =False, caption ='' , impact='', tag='', qa_res ='' , sub_path =''): # this is not self.entry entry = [] if entry_id == '': entry.append(self.indent[1] + '- date: ' + qa_util.date()) if len(f): entry.append(self.indent[3] + 'file: ' + f) if len(d_path): entry.append(self.indent[3] + 'data_path: ' + d_path) if len(r_path): entry.append(self.indent[3] + 'result_path: ' + r_path) if len(conclusion): entry.append(self.indent[3] + 'conclusion: ' + conclusion) if is_events: entry.append(self.indent[3] + 'events:') if len(caption): entry.append(self.indent[4] + '- event:') entry.append(self.indent[7] + 'caption: ' + caption) entry.append(self.indent[7] + 'impact:' + impact) entry.append(self.indent[7] + 'tag: ' + tag) if len(info): entry.append(self.indent[7] + 'text:') for s in info: entry.append(self.indent[8] + '- ' + s) if set_qa_lock: entry.append(self.indent[3] + 'status: ' + repr(status)) if status > 1: ff = f if ff[-3:] == '.nc': ff = ff[:-3] out = os.path.join(qa_res, 'data', sub_path, \ 'qa_lock_' + ff + '.txt') with open(out, 'w') as f_qa_lock: f_qa_lock.write('Path: ' + d_path + '\n') f_qa_lock.write('File: ' + f + '\n') f_qa_lock.write(impact + '-' + tag + ': ' + caption + '\n') if len(info): if indent > -1: entry.append(self.indent[indent]) entry.extend(info) if status > -1: entry.append(self.indent[3] + 'status: ' + repr(status)) (ix, entry_id) = self.get_entry_slot_ix(entry_id, entry) self.entry[ix].extend(entry) return entry_id
def append(self, entry_id='', f='', d_path='', r_path='', start=[], info=[], txt='', status=-1, set_qa_lock=False, period=[], conclusion='', indent=-1, is_events=False, annotation='', impact='', tag='', qa_res='', sub_path=''): # this is not self.entry entry = [] if entry_id == '': entry.append(self.indent[1] + '- date: ' + qa_util.date()) if len(f): if f[-3:] == '.nc' or f[-4:] == '.nc5': s0 = 'file: ' else: s0 = 'data-set: ' entry.append(self.indent[3] + s0 + f) if len(d_path): entry.append(self.indent[3] + 'data_path: ' + d_path) if len(r_path): entry.append(self.indent[3] + 'result_path: ' + r_path) if len(period): entry.append(self.indent[3] + 'period: ') entry.append(self.indent[4] + 'begin: ' + period[0]) entry.append(self.indent[4] + 'end: ' + period[1]) if len(conclusion): entry.append(self.indent[3] + 'conclusion: ' + conclusion) if is_events: entry.append(self.indent[3] + 'events:') if len(annotation): entry.append(self.indent[4] + '- event:') entry.append(self.indent[7] + 'annotation: ' + annotation) if len(impact): entry.append(self.indent[7] + 'impact: ' + impact) if len(tag): entry.append(self.indent[7] + 'tag: ' + tag) if len(info): entry.append(self.indent[7] + 'info:') for line in info: if len(line) > self.line_wrap_sz: # at first test for a line wrap of lines too long lines = self.line_wrap(line) else: lines = [line] for l in range(len(lines)): entry.append(self.indent[8] + '- ' + lines[l]) if status > -1: entry.append(self.indent[3] + 'status: ' + repr(status)) if set_qa_lock: ff = f if ff[-3:] == '.nc': ff = ff[:-3] elif ff[-4:] == '.nc4': ff = ff[:-4] out = os.path.join(qa_res, 'data', sub_path, \ 'qa_lock_' + ff + '.txt') with open(out, 'w') as f_qa_lock: f_qa_lock.write('Path: ' + d_path + '\n') f_qa_lock.write('File: ' + f + '\n') if len(impact) > 0 and len(tag) > 0: f_qa_lock.write(impact + '-' + tag) elif len(impact): f_qa_lock.write(impact) elif len(tag): f_qa_lock.write(tag) f_qa_lock.write(': ' + annotation + '\n') (ix, entry_id) = self.get_entry_slot_ix(entry_id, entry) self.entry[ix].extend(entry) return entry_id