Chinaunix首页 | 论坛 | 博客
  • 博客访问: 534894
  • 博文数量: 128
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 1345
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-22 21:43
文章分类

全部博文(128)

文章存档

2009年(30)

2008年(98)

我的朋友

分类: Python/Ruby

2008-04-28 15:41:31

公司的CVS服务器,IP地址改变了,导致代码无法Update和Get
两种处理方法: 1.重新从CVS服务器上拉代码下来
             2.修改本地CVS目录中的ROOT中的CVS服务器地址

担心本地有些目录中的代码没有及时更新,所以使用第二种方法:使用Python解决
#coding=GB2312
#cvsRecover.py
# 修改本地目录中映射的CVS服务器地址
# Auth : PeiZhengfeng
# Date : 2008.04.28

import os 
import re

# 递归遍历指定的目录  
# level -- 递归的层数,用这个参数来控制打印的缩进  
# path  == 遍历起始绝对路径  
def listyoudir(level, path):  
    for i in os.listdir(path):  
        # print '  '*(level+1) + i
       
        # 修改内容
        if i == 'Root':
            filename = path + '\\' + i
            ReCVSRecover(filename)
       
        # 继承遍历
        if os.path.isdir(path + '\\' + i):  
            listyoudir(level+1, path + '\\' + i)
           
def ReCVSRecover(filename):
   
    f = file(filename, 'r')
    f_content = f.read()
    p = re.compile('192.168.1.196:2401')
    p_content = p.sub( '10.0.0.2:2401', f_content)
    f.close()
   
    f = file(filename, 'w')
    f.write(p_content)
    f.close()
           
if __name__ == '__main__':
    # 遍历当前目录
    rootpath = os.path.abspath('E:\\GtisLib')  
    print rootpath  
    listyoudir(0, rootpath) 

使用方法:拷几cvsRecover.py到本地CVS主目录,
E:\cvs\GtisLib>d:\python24\python cvsrecover.py

阅读(2438) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-06-05 16:48:42

很有用,多谢!