def update_3_resend_email(): os.chdir(site_path) st = pysvn.st("") #更新文件列表 if pywincmds.web_check(sit_url, site_keyword, inteveral_time, web_decode): #三段启动成功 svn_revision = pysvn.py_get_svn_info_revision(pysvn.info(co_path, username, password)) content = "更新包url:" + svn_url + "\n" + "更新包版本:" + svn_revision + "\n\n" content = content + "三段差异内容:" + "\n" content = content + '\n'.join(st).strip() content = content + "\n" + "详情见:" + "\n" + log_url title = site_name + "三段更新成功,请测试,谢谢!" #邮件 pyemail.send(to_list, title, content, [])
def update_3(flag): ''' py_file需要全局变量, pyfile不能在co_path内 co_path为更新包路径检出位置 py_file为更新文件列表存放文件 ''' global svn_revision pysvn.up("HEAD", site_path, username_online, password_online) if os.path.exists(co_path): pywincmds.del_dir(co_path) pysvn.co(svn_url, svn_revision, co_path, username, password) list_tree = pysvn.list_agile('svn list -R', svn_url, username, password) for i in range(0,len(list_tree)): list_tree[i] = list_tree[i].lower().strip().rstrip("/") list_tree_actual = [] pywincmds.py_write_svn_message_to_file(svn_url, url_file) pywincmds.py_robocopy(co_path, site_path, '.svn _svn', '') os.chdir(site_path) st = pysvn.st("") #更新文件列表 #使用svn list url和svn st产生列表的分隔符不一致,下面的方法只适用于windows for item in st: try: if list_tree.index(item.strip().split()[-1].strip().replace("\\", "/").lower()) > -1: list_tree_actual.append(item.strip().split()[-1].strip().replace("\\", "/")) except: pass if len(list_tree_actual) == 0: print("无更新内容!") exit(1) list_str = '\n'.join(list_tree_actual).strip() pywincmds.py_write_svn_message_to_file(list_str, changelist) if flag: pywincmds.restart_app_pool(workspace + os.sep + "sbp", apppool) if pywincmds.web_check(sit_url, site_keyword, inteveral_time, web_decode): #三段启动成功 svn_revision = pysvn.py_get_svn_info_revision(pysvn.info(co_path, username, password)) content = "更新包url:" + svn_url + "\n" + "更新包版本:" + svn_revision + "\n\n" content = content + "三段差异内容:" + "\n" content = content + '\n'.join(st).strip() content = content + "\n" + "详情见:" + "\n" + log_url title = site_name + "三段更新成功,请测试,谢谢!" #邮件 pyemail.send(to_list, title, content, [])
def commit_offline(self,site_name): product_dir = self.workspace + os.sep + self.sites[site_name]["product_dir"] online_dir = self.workspace + os.sep + self.sites[site_name]["online_dir"] site_dir = self.workspace + os.sep + self.sites[site_name]["site_dir"] pywincmds.del_all_except_hidden_directories(product_dir) pywincmds.robocopy(online_dir, product_dir, py_exclude_dirs=".svn _svn") try: self.substitute(site_dir + os.sep + "config_test" + os.sep + "config", product_dir + os.sep + self.sites[site_name]["config"]) self.substitute(site_dir + os.sep + "config_test" + os.sep + self.sites[site_name]["web_config"]["config_test"], product_dir + os.sep + self.sites[site_name]["web_config"]["online"]) except: pass pywincmds.robocopy(site_dir + os.sep + "config_online", product_dir + os.sep + "Config_online", py_exclude_dirs = ".svn _svn") os.chdir(product_dir + os.sep + "Config_online") os.rename(self.sites[site_name]["web_config"]["config_online"], self.sites[site_name]["web_config"]["online"]) os.chdir(online_dir) lines = pysvn.st("") lines = [line.strip() for line in lines] if len(lines) == 0: pyemail.send(self.to_list, site_name + "无变化内容", "") return else: pywincmds.py_write_svn_message_to_file("\n".join(lines), product_dir + os.sep + "changelist.txt") if os.path.exists(self.getversion_exe): pywincmds.call_cmd(self.getversion_exe + " \"" + self.sourcecode_dir + "\"") time.sleep(10) #pywincmds.copy(self.sourcecode_dir + os.sep + "my_version.txt", self.product_dir + os.sep + self.site_names[site_name] + os.sep + "revision_numbers.txt") svn_log_message = "sourcecode : " + pysvn.py_get_svn_info_url(site_dir, self.sourcecode_username, self.sourcecode_password) + '\n' + "version number : " + pysvn.py_get_svn_info_revision(site_dir, self.sourcecode_username, self.sourcecode_password) + '\n' svn_log_message = svn_log_message + "main updated contents : " + '\n' + self.message pywincmds.py_write_svn_message_to_file(svn_log_message, self.py_log_file) updated_content = pysvn.commit_all(product_dir, self.product_username, self.product_password, self.py_log_file) pyprocessemail.commit_to_product(site_name, self.to_list, updated_content, self.sites[site_name]["product_url"], svn_log_message, self.log_url)
def change_email(self, site_name): online_dir = self.workspace + os.sep + self.sites[site_name]["online_dir"] site_dir = self.workspace + os.sep + self.sites[site_name]["site_dir"] os.chdir(online_dir) lines = pysvn.st("") contents = [] for line in lines: path = site_dir + os.sep + line.strip().split()[-1].strip() #line.replace(line[0],'',1).strip() if path.lower().find(r'.dll') > -1 or path.lower().find(r'.pdb') > -1 or path.lower().find(r'.txt') > -1: contents.append(line) else: try: log_summary = pysvn.log(path, self.sourcecode_username, self.sourcecode_password,quite="-q") compiled_pattern = re.compile("r.*", re.M) log_summary = re.search(compiled_pattern, log_summary).group().strip() if log_summary.find("|") > -1: log_items = log_summary.split("|") contents.append(log_items[2].strip() + " " + log_items[1].strip() + " " + line)#"{0:<80},{1}".format(line, log_summary)) else: contents.append(log_summary) except: contents.append(line) contents.sort() updated_content = os.linesep.join(contents) pyprocessemail.build_success(site_name, self.to_list, pysvn.py_get_svn_info_url(site_dir, self.sourcecode_username, self.sourcecode_password), pysvn.py_get_svn_info_revision(site_dir, self.sourcecode_username, self.sourcecode_password), updated_content, self.log_url)
def resend_email(self): if pywincmds.web_check(self.website_verified_url, self.verified_keyword, self.inteveral_time, self.web_decode): os.chdir(self.online_site_path) updated_content = os.linesep.join(pysvn.st("")) pyprocessemail.update_to_three(self.full_site_name, self.to_list, self.product_trunk_url, pysvn.py_get_svn_info_revision(self.product_trunk_dir, self.product_username, self.product_password), updated_content, self.log_url) else: print("站点启动失败") exit("1")
def update(self, flag = True): self.check_sourcecode() pywincmds.del_all_except_hidden_directories(self.product_tag_dir) pywincmds.robocopy(self.product_trunk_dir, self.product_tag_dir, py_exclude_dirs = ".svn _svn config Config_online log", py_exclude_files = "web.config changelist.txt revision_numbers.txt") pywincmds.robocopy(self.product_trunk_dir + os.sep + "Config_online", self.product_tag_dir, py_exclude_dirs = ".svn _svn") self.del_files(self.product_tag_dir) pywincmds.robocopy(self.product_tag_dir, self.online_site_path, py_exclude_dirs = ".svn _svn Config_online log", py_exclude_files = "changelist.txt revision_numbers.txt") self.del_files(self.online_site_path) if flag: pywincmds.restart_app_pool(self.workspace + os.sep + "sbp_2.0", self.app_pool) if pywincmds.web_check(self.website_verified_url, self.verified_keyword, self.inteveral_time, self.web_decode): os.chdir(self.online_site_path) updated_content = os.linesep.join(pysvn.st("")) pyprocessemail.update_to_three(self.full_site_name, self.to_list, self.product_trunk_url, pysvn.py_get_svn_info_revision(self.product_trunk_dir, self.product_username, self.product_password), updated_content, self.log_url) else: print("站点启动失败") exit("1")