def co_path(self, urls, dirs, username, password, revision="HEAD"): if isinstance(urls, list): length = len(urls) for j in range(0, length): if os.path.exists(dirs[j]): pysvn.up(dirs[j], username, password, revision) else: pysvn.co(urls[j], dirs[j], username, password, revision) elif isinstance(urls, str): if os.path.exists(dirs): pysvn.up(dirs, username, password, revision) else: pysvn.co(urls, dirs, username, password, revision)
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 update_3(): #pdb.set_trace() #更新样式线下和线上本地拷贝 for style_offline in style_offline_woringcopy: pysvn.up("HEAD", style_offline, style_offline_username, style_offline_password) for style_online in style_online_woringcopy: pysvn.up("HEAD", style_online, style_online_username , style_online_password) #读取文件http列表 #转换为路径 url_transfer_path() #拷贝文件 for i in range(0,len(offline_paths)): if os.path.isfile(offline_paths[i]): pywincmds.makedirs(os.path.dirname(online_paths[i])) if os.path.exists(offline_paths[i]): pywincmds.py_xcopy_file(offline_paths[i], online_paths[i]) else: pywincmds.py_robocopy(offline_paths[i].rstrip("\\"), online_paths[i].rstrip("\\"), "", "") #压缩png文件 for i in range(0,len(online_paths)): if online_paths[i].endswith('.png'): try: pywincmds.call_cmd(compress_png_path + " \"" + online_paths[i] + "\"") except: print(online_paths[i] +' error') atime = time.mktime(datetime.datetime(2000, 1, 1).utctimetuple()) mtime = time.mktime(datetime.datetime(2000, 1, 1).utctimetuple()) os.utime(online_paths[i], (atime, mtime)) print(online_paths[i]) #压缩js和css文件 for compress_js_path in compress_js_paths: os.chdir(os.path.dirname(compress_js_path)) pywincmds.call_cmd(compress_js_path) print(compress_js_path) #确认已更新,如何确认 #发送邮件 pyemail.send(["*****@*****.**"], content.strip() + "样式已更新", " ", [])
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 send_email_for_commit(self): if self.full_site_name == "ALL": for key in self.sites.keys(): self.commit_offline(key) else: self.commit_offline(self.full_site_name) pass if __name__ == '__main__': pysvn.up(r"C:\hudson\workspace\gameid_build_new\sbp_2.0", "301645", "//5173@#q") p = sites_pybuild("gameid") #print(p.site_names) print(p.build_batch) #print(p.copy_bats) #print(p.sites_src_dirs) #print(p.online_urls) #print(p.online_dirs) print(p.sourcecode_username, p.sourcecode_password) print(p.product_password) print(p.sourcecode_dirs) print(p.getversion_exe) #print(p.product_url) #print(p.product_dir) for key in p.sites.keys(): print(p.sites[key])
r"C:\projectin\IMAGES002.5173cdn.com", r"C:\projectin\IMAGES.5173cdn.com", r"C:\projectin\IMAGES001.5173cdn.com\tags"] style_offline_username = "******" style_offline_password = "******" style_online_woringcopy = [r"C:\project\IMAGES001.5173cdn.com", r"C:\project\IMAGES002.5173cdn.com", r"C:\project\IMAGES002.5173cdn.com", r"C:\project\IMAGES.5173cdn.com", r"C:\project\IMAGES001.5173cdn.com\tags"] style_online_wks = [r"C:\project\IMAGES001.5173cdn.com", r"C:\project\IMAGES002.5173cdn.com", r"C:\project\IMAGES.5173cdn.com"] style_online_username = os.getenv("style_online_username", "zhangyfsh") style_online_password = os.getenv("style_online_password", "9MHF774Q0WDAFH2") if os.path.exists(change_workingcopy): pysvn.up(change_revision, change_workingcopy, change_username, change_password) else: pysvn.co(change_url, change_revision, change_workingcopy, change_username, change_password) urls = [] offline_paths = [] online_paths = [] content = pysvn.log_path(change_workingcopy + os.sep + "change.txt", change_username, change_password) def url_transfer_path(): f = open(change_workingcopy + os.sep + "change.txt") temp_urls = f.readlines() f.close() for temp in temp_urls: if temp.strip() == "": continue
def check_sourcecode(self): if os.path.exists(self.product_tag_dir): pysvn.clear_workingcopy(self.product_tag_dir) self.co_path(self.product_tag_url, self.product_tag_dir, self.product_username, self.product_password, "HEAD") self.co_path(self.product_trunk_url, self.product_trunk_dir, self.product_username, self.product_password, self.revision) pysvn.up(self.online_site_path, self.online_username, self.online_password)