1 #!/usr/bin/env python

2 #coding=utf-8

3

4 #启动环境:linux,安装了python,svn客户端,并且具备python部分依赖包,xlrd,shutil,如果没有网上搜索安装

5 #启动方式:将文件MvSvnLibToNew.py和MvSvnLibToNew.xls放到机器的某个目录

6 #然后nohup python MvSvnLibToNew.py type > 1.log& 启动,type=0-只检测配置,不上传,type=1-既检测配置,又上传

7 #配置文件MvSvnLibToNew.xls,有7列配置项,分别为

8

9 #配置文件参数说明如下

10 #old_url:老库的待迁移的svn地址

11 #old_local_path:下载到本地的目录

12 #old_username:老库的svn用户名

13 #old_password:老库的svn密码

14 #new_url:新库的上传路径

15 #new_username:新库的svn用户名

16 #new_password:新库的svn密码

17

18 #有如下检测功能

19 #检测old_url是否存在,用户名密码是否正确

20 #检测new_url是否存在,用户名密码是否正确

21 #检测new_url路径配置是否跟old_new的子目录一样

22

23 importos24 importxlrd25 importsys26 importshutil27

28 #python 3.8不需要

29 #reload(sys)

30 #sys.setdefaultencoding('utf-8')

31

32 defexecCmd(cmd):33 r =os.popen(cmd)34 text =r.read()35 r.close()36 returntext37

38 #checkout文件到本地

39 defcheckOutOldLib(old_url, old_local_path, old_username, old_password):40 command_str = "svn co" + old_url + " " + old_local_path + "--username" + old_username + "--password" + old_password + "--non-interactive"

41 print(command_str)42 text =execCmd(command_str)43 print(text)44

45 #判断远程目录是否存在

46 defjudgeRemoteDirExist(old_url, old_username, old_password, new_url, new_username, new_password):47 #判断老库是否存在

48 command_str = "svn ls" + old_url + "--username" + old_username + "--password" +old_password49 print(command_str)50 text =execCmd(command_str)51 #print(text)

52 if len(text) ==0 :53 print("ERROR:old_url[%s]不存在!" %(old_url))54 return(False)55

56 #首先判断新老连接配置最后的目录是否,比如old:xxxxx/develop,new:yyyyyy/develop,则会上传失败

57 listDataOld = old_url.split("/")58 listDataNew = new_url.split("/")59 #如果配置一样,则需要检测新库目录是否存在

60 if listDataOld[len(listDataOld)-1] == listDataNew[len(listDataNew)-1] :61 print("ERROR old_url[%s] 和 new_url[%s] 子目录配置一样,配置错误,请重新配置!" %(old_url, new_url))62 return(False)63 else:64 command_str = "svn ls" + new_url + "--username" + new_username + "--password" +new_password65 print(command_str)66 text =execCmd(command_str)67 #print(text)

68 if len(text) ==0 :69 return(True)70

71 #检查目录是否存在

72 #print(listDataOld[len(listDataOld)-1])

73 nPos = text.find(listDataOld[len(listDataOld)-1])74 #print(nPos)

75 #如果存在

76 if nPos >=0 :77 print("ERROR new_url: [%s] 已存在 [%s],导入失败,请确保新库导入为新的空目录!" % (new_url, listDataOld[len(listDataOld)-1]))78 return(False)79 else:80 return(True)81

82 #全量检测

83 defallCheckConfig(sheetobj):84 iSuccess =085 iFailed =086 iBool =True87 nrows =sheetobj.nrows88 ncols =sheetobj.ncols89 print("*********************************************************************************************")90 #先做一个全量检测

91 for i in range(1, nrows):92 for j inrange(ncols):93 if j ==0:94 old_url =sheetobj.row_values(i)[j]95 print("old_url: %s" %(sheetobj.row_values(i)[j]))96 elif j == 1:97 old_local_path =sheetobj.row_values(i)[j]98 print("old_local_path: %s" %(sheetobj.row_values(i)[j]))99 elif j == 2:100 old_username =sheetobj.row_values(i)[j]101 print("old_username: %s" %(sheetobj.row_values(i)[j]))102 elif j == 3:103 old_password =sheetobj.row_values(i)[j]104 print("old_password: %s" %(sheetobj.row_values(i)[j]))105 elif j == 4:106 new_url =sheetobj.row_values(i)[j]107 print("new_url: %s" %(sheetobj.row_values(i)[j]))108 elif j == 5:109 new_username =sheetobj.row_values(i)[j]110 print("new_username: %s" %(sheetobj.row_values(i)[j]))111 elif j == 6:112 new_password =sheetobj.row_values(i)[j]113 print("new_password: %s" %(sheetobj.row_values(i)[j]))114 print(" ")115 listData = old_url.split("/")116 old_local_path = old_local_path + "/" + listData[len(listData)-1]117

118 if judgeRemoteDirExist(old_url, old_username, old_password, new_url, new_username, new_password) ==False :119 print("配置异常!")120 iFailed += 1

121 iBool =False122 else:123 print("配置正常!")124 iSuccess += 1

125 print("*********************************************************************************************")126

127 print("总共检测%s个,其中配置正常%s个,配置异常%s个" % (nrows-1, iSuccess, iFailed))128 print("*********************************************************************************************")129

130 return(iBool)131

132 #全量导入新库

133 defallImportSvn(sheetobj):134 nrows =sheetobj.nrows135 ncols =sheetobj.ncols136

137 #全量导入

138 for i in range(1, nrows):139 for j inrange(ncols):140 if j ==0:141 old_url =sheetobj.row_values(i)[j]142 print("old_url: %s" %(sheetobj.row_values(i)[j]))143 elif j == 1:144 old_local_path =sheetobj.row_values(i)[j]145 print("old_local_path: %s" %(sheetobj.row_values(i)[j]))146 elif j == 2:147 old_username =sheetobj.row_values(i)[j]148 print("old_username: %s" %(sheetobj.row_values(i)[j]))149 elif j == 3:150 old_password =sheetobj.row_values(i)[j]151 print("old_password: %s" %(sheetobj.row_values(i)[j]))152 elif j == 4:153 new_url =sheetobj.row_values(i)[j]154 print("new_url: %s" %(sheetobj.row_values(i)[j]))155 elif j == 5:156 new_username =sheetobj.row_values(i)[j]157 print("new_username: %s" %(sheetobj.row_values(i)[j]))158 elif j == 6:159 new_password =sheetobj.row_values(i)[j]160 print("new_password: %s" %(sheetobj.row_values(i)[j]))161 listData = old_url.split("/")162 old_local_path = old_local_path + "/" + listData[len(listData)-1]163

164 if judgeRemoteDirExist(old_url, old_username, old_password, new_url, new_username, new_password) ==True :165 new_url = new_url + "/" + listData[len(listData)-1]166 checkOutOldLib(old_url, old_local_path, old_username, old_password)167 importNewLib(new_url, old_local_path, new_username, new_password)168 shutil.rmtree(old_local_path, ignore_errors=True)169 print("*********************************************************************************************")170

171

172 #上传本地文件到新库

173 defimportNewLib(new_url, old_local_path, new_username, new_password):174 command_str = "svn import" + old_local_path + " " + new_url + "-m 老库迁移至新库 --username" + new_username + "--password" +new_password175 print(command_str)176 text =execCmd(command_str)177 print(text)178

179 #读取配置的xls配置文件

180 defreadExcelData(excel_path):181 bookobj = xlrd.open_workbook(excel_path,encoding_override="utf-8")182 sheetobj =bookobj.sheet_by_index(0)183 returnsheetobj184

185

186 if __name__ == "__main__":187 excel_path = "./MvSvnLibToNew.xls"

188 sheetobj =readExcelData(excel_path)189

190 if len(sys.argv) != 2:191 print("start: \tpython MvSvnLibToNew.py type")192 print("param:")193 print("\ttype:")194 print("\t0-只检测配置,不上传")195 print("\t1-既检测配置,又上传")196 exit(1)197

198

199 #如果带了参数,type=0,只检测,不上传,type为其他,既检测又上传

200 #如果不带参数,既检测又上传

201 if len(sys.argv) == 2:202 type = sys.argv[1]203 #只检测,不上传

204 if type == '0':205 if allCheckConfig(sheetobj) ==False :206 exit(1)207 exit(1)208 elif type == '1':209 if allCheckConfig(sheetobj) ==False :210 exit(1)211 allImportSvn(sheetobj)

python svn库_python实现svn新老库迁移相关推荐

  1. python 删除第三方库_python 安装移动复制第三方库操作

    一.绪论 在使用python开发过程中经常会使用到第三方库.因此就涉及到了如何安装.复制移动. 二.安装方式 第三方库的安装方式 1.python自带包管理器:使用pip命令自动安装.例如:pip i ...

  2. python升级第三方库_python一键升级所有第三方库

    import pip from subprocess import call for dist in pip.get_installed_distributions(): call("pip ...

  3. python复制库_python 安装移动复制第三方库操作

    一.绪论 在使用python开发过程中经常会使用到第三方库.因此就涉及到了如何安装.复制移动. 二.安装方式 第三方库的安装方式 1.python自带包管理器:使用pip命令自动安装.例如:pip i ...

  4. 用python画熊_Python数据可视化:Pandas库,只要一行代码就能实现

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 以下文章一级AI入门学习 ,作者小伍哥 刚接触Python的新手.小白,可以复制下面的链接去免费观 ...

  5. python有什么好玩的库_python有什么好玩的库

    python好玩的库有:1.PyGame,一个游戏开发框架:2.Pillow,一个有关图片操作处理的软件:3.Selenium,一款浏览器自动化测试框架:4.Asciimatics等等. Python ...

  6. python beautifulsoup库_Python爬虫系列:BeautifulSoup库详解

    点击上方蓝字关注"程序员Bob"呀~ 每个人的生命都是通向自我的征途,是对一条道路的尝试,是一条小径的悄然召唤.人们从来都无法以绝对的自我之相存在,每一个人都在努力变成绝对自我,有 ...

  7. datahub文档_新老DataHub迁移手册

    DataHub服务用户迁移文档 前言 原Odps版内测DataHub(下文统称为老DataHub服务),于2016年11月21日起已经处于维护状态,新版DataHub届时已经开启公测,公测至今已有半年 ...

  8. 如何用python画长方形_python opencv 画矩形跟老齐学Python之用Python计算

    一提到计算机,当然现在更多人把她叫做电脑,这两个词都是指computer.不管什么,只要提到她,普遍都会想到她能够比较快地做加减乘除,甚至乘方开方等.乃至于,有的人在口语中区分不开计算机和计算器. 那 ...

  9. python 生成动态库_Python 项目转.so动态库

    最近, 作者遇到一个需求, 需要把Python的工程部署到别的集群, 但是又要保证Python代码的安全性. 于是上网搜索, 搜到几个解决方案, 但是都不是符合需求. 综合搜到的几个解决方案, 最终作 ...

最新文章

  1. Monkey测试2——Monkey测试策略
  2. 平滑线反锯齿工具_PS大神常用选框类工具有哪些?其实很简单,小白认真学也能懂...
  3. 微信小程序支付最容易犯的坑notify_url(支付回调)
  4. sklearn的train_test_split函数
  5. matlab与树莓派通信
  6. AutoHotKey在魔兽中显示文字或图片
  7. java中的gridy_JAVA格局管教器.
  8. CompletableFuture 详解
  9. sql azure 语法_使用Visual Studio和SQL Azure数据库
  10. predicate 列存储索引扫描_MySQL中IS NULL、IS NOT NULL、!=不能用索引?胡扯!
  11. 神经网络drop out
  12. ARTS Share6 miniUI getData(true,false)获取form表单数据问题
  13. 15个常用excel函数公式_工作中常用的excel函数公式大全,拿来即用!
  14. 微商史上最全软文标题写作套路(收藏版)
  15. 程序员段子:电脑在手,代码我有!
  16. win10动态壁纸怎么设置_教程丨WIN10系统下设置固定IP或动态IP
  17. AcWing120 防线
  18. Jsp显示应用外服务器的图片,jsp显示服务器的绝对路径图片
  19. 教程:在C#中创建带有表格、图表、图片的PPT演示文稿
  20. ZCANPRO的.can文件解析

热门文章

  1. angularJS的$http.post请求,.net后台接收不到参数值的解决方案
  2. Wo Cloud CentOS 挂载磁盘小计
  3. 如何从iPhone / iPod Touch / iPad连接
  4. python 某个数是不是在某个范围内_教写一个简单的python小程序(04)
  5. base64是哪个jar包的_涨知识 | 用maven轻松管理jar包
  6. xml文件c语言读取函数,读写xml文件的2个小函数
  7. Kruskal(P)和Prim(K)算法
  8. 在Python3中将字符串转换为字节的最佳方法
  9. kotlin键值对数组_Kotlin程序检查数组是否包含给定值
  10. kotlin 查找id_Kotlin程序查找平行四边形的区域