def get_from_conda(self): tag = '-' branch = '-' curr_id = '-' f = os.path.join(self.opts["QA_SRC"], "install.log") cmd = "cat " + f + " 2> /dev/null" try: t = subprocess.check_output(cmd, shell=True) except subprocess.CalledProcessError as e: istatus = e.returncode else: t = t.split('\n') branch = qa_util.lstrip(t[0], 'branch=') curr_id = qa_util.lstrip(t[1], 'hexa=') if len(t) > 2: if 'tag' in t[2]: tag = qa_util.lstrip(t[2], 'tag=') return branch, curr_id, tag
def sendMail(self): if self.no_email: return try: self.email_addr except: return import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEText import MIMEText from email.MIMEBase import MIMEBase from email import encoders fromA = self.email_addr[0] to = self.email_addr[0] msg = MIMEMultipart() msg['From'] = fromA msg['To'] = to msg['Subject'] = "QA: " \ + qa_util.lstrip(self.save_json_file, pat='##') body = "QA: \n" + os.getcwd() + "\n" + self.save_json_file msg.attach(MIMEText(body, 'plain')) f = self.save_json_file void, filename = os.path.split(f) attachment = open(f, "rb") part = MIMEBase('application', 'octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) part.add_header('Content-Disposition', "attachment; filename= %s" % filename) msg.attach(part) attachment.close() server = smtplib.SMTP('localhost') #server.starttls() text = msg.as_string() server.sendmail(fromA, to, text) server.quit() return
def clearInq(qa_var_path, fBase, logfile): # isFollowLink = False v_clear = qaConf.getOpt('CLEAR') if v_clear == 't': return clear(qa_var_path, fBase, logfile) isClear = False for f in v_clear.split(','): if f == 't': break # unconditional ''' if f == 'follow_links': if not getOpt.isOpt('DEREFERENCE_SYM_LINKS'): isFollowLink = True isClear = True el''' if f == 'only': isClear = True elif f == 'lock': # locked files if len( glob.glob( os.path.join(qa_var_path, 'qa_lock_' + fBase + '*'))): isClear = True elif f == 'note': if len( glob.glob( os.path.join(qa_var_path, 'qa_note_' + fBase + '*'))): isClear = True elif qa_util.rstrip(f, sep='=') == 'level': # clear specified level f = qa_util.lstrip(f, sep='=') + '-' elif qa_util.rstrip(f, '=') == 'tag': call = 'sed -n "/' + fBase + '/,/status:/ p" ' + logfile try: check_output = subprocess.check_output(call, shell=True) except: pass else: requ_tag = qa_util.lstrip(f, '=') words = check_output.split() sz = len(words) for i in range(sz - 1): w1 = qa_util.lstrip(words[i], '=') l_w1 = len(w1) l_tg = len(requ_tag) if words[i] == 'tag:' and w1 == requ_tag: isClear = True break ''' # e.g. 'L1-${tag}: where tag=CF_12 would match CF_12, CF_12x etc. f='[\w]*-*' + qa_util.lstrip(f, sep='=') + '.*: ' fls = glob.glob(os.path.join(qa_var_path, 'qa_note_' + fBase +'*') ) fls.extend(glob.glob(os.path.join(qa_var_path, 'qa_lock_' + fBase +'*') )) for fl in fls: try: subprocess.check_call('grep', '-q', f, fl) except: pass else: isClear = True break ''' else: # CLEAR=var=name pos = f.find('var=') if pos > -1: f = f[pos + 4:] # else: # CLEAR=varName regExp = re.match(f, fBase) if regExp: tmp_ls = glob.glob( os.path.join(qa_var_path, '*_' + fBase + '*')) if len(tmp_ls): isClear = True if isClear: # now do the clearance return clear(qa_var_path, fBase, logfile) return False
def get_external_version(self, prj): if self.isOpt("VERBOSE"): sep0 = '\n' sep1 = '\n ' else: sep0 = '|' sep1 = '' if len(self.p_projects) == 0: self.p_projects = os.path.join(self.opts["QA_TABLES"], "tables", "projects") vStr = '' if prj == "CMIP6": f = os.path.join(self.p_projects, prj, "CMIP6_CVs") if not os.path.isdir(f): self.no_such_table(prj, f) branch, curr_id = self.get_git_branch(f) vStr = sep0 + "CMIP6_CVs:" + sep1 vStr += branch + '-' + curr_id f = os.path.join(self.p_projects, prj, "CMIP6_MIP_tables.xlsx") if not os.path.isfile(f): self.no_such_table(prj, f) cmd = "ls -l --time-style='+%F' " + f + "| awk '{print $6}'" try: t = subprocess.check_output(cmd, shell=True) except subprocess.CalledProcessError as e: istatus = e.returncode else: vStr += sep0 + "CMIP6_MIP_tables.xlsx:" + sep1 vStr += t.strip() if self.isOpt("PrePARE"): p = self.opts["PrePARE"] p = qa_util.rstrip(p, sep='/', max=2) f = os.path.join(p, "conda-meta", "cmor-*") cmd = "ls " + f + " 2> /dev/null" try: t = subprocess.check_output(cmd, shell=True) except subprocess.CalledProcessError as e: istatus = e.returncode else: t = qa_util.lstrip(t, sep='/', pat='##') t = qa_util.rstrip(t, sep='.') vStr += sep0 + "CMOR:" + sep1 + t f = os.path.join(self.p_projects, prj, "cmip6-cmor-tables") if not os.path.isdir(f): self.no_such_table(prj, f) branch, curr_id = self.get_git_branch(f) vStr += sep0 + "cmip6-cmor-tables:" + sep1 + branch + '-' + curr_id elif prj == "CMIP5": vStr = sep0 + "CMIP5_standard_output_20130815" elif prj == "CORDEX": f = os.path.join(self.p_projects, prj, "IS-ENES-Data.github.io") if not os.path.isdir(f): self.no_such_table(prj, f) branch, curr_id = self.get_git_branch(f) vStr = sep0 + "IS-ENES-Data.github.io:" + sep1 vStr += branch + '-' + curr_id elif prj == "CF": if self.isOpt("CF_STD_NAME_VERSION"): vStr = sep0 + "CF_STD_NAME_VERSION:" + sep1 vStr += self.opts["CF_STD_NAME_VERSION"] else: f = os.path.join(self.p_projects, prj, "standard-names.html") if not os.path.isfile(f): self.no_such_table(prj, f) if os.path.isfile(f): with open(f, 'r') as fd: for line in fd: if 'Standard Name Table' in line: p0 = line.find('(') + 1 p1 = line.find(')') if p0 > 1 and p1 > -1: s = line[p0:p1].split() vStr = sep0 + "std-name:" + sep1 for item in s: vStr += item elif 'Area Type Table' in line: p0 = line.find('(') + 1 p1 = line.find(')') if p0 > 1 and p1 > -1: s = line[p0:p1].split() vStr += sep0 + "area-type:" + sep1 for item in s: vStr += item break return vStr