Python学习笔记-清除项目下SVN文件
来源:互联网 发布:Ht.js 编辑:程序博客网 时间:2024/04/30 09:51
主要是OS库等一些常用库的操作
import osimport timeimport statdef clearSVN(destPath): if os.path.isdir(destPath) == False : return; else : destFileName = os.path.basename(destPath) print 'current dir name is %s' %destFileName if str(destFileName).find('svn') == -1 : print '%s is not svn file' %destFileName for fDir in os.listdir(destPath) : clearSVN(os.path.join(destPath, fDir)) else : print '%s is svn file' %destFileName os.chmod(destPath, stat.S_IMODE(os.stat(destPath)[stat.ST_MODE]) | stat.S_IREAD|stat.S_IWRITE) for root, dirs, files in os.walk(destPath, topdown=False): for fileN in files: try : f = os.path.join(root, fileN); os.chmod(f, stat.S_IMODE(os.stat(f)[stat.ST_MODE]) | stat.S_IREAD|stat.S_IWRITE) os.remove(f) except OSError as e: print f + 'remove error' + e.message finally : if os.path.exists(f) : os.system('del ' + f + ' /f /q') for dirN in dirs: print 'dirName is %s' %dirN try : print 'root is %s' %root os.chmod(root, stat.S_IMODE(os.stat(root)[stat.ST_MODE]) | stat.S_IREAD|stat.S_IWRITE) os.rmdir(root) except OSError as e: print root + 'remove error' + e.message finally : if os.path.exists(root) : os.system('del ' + root + ' /f /q') def search(destPath, destFile): if os.path.isdir(destPath) == False or os.path.isfile(destFile) == False : return for destF in os.listdir(destPath): if os.path.isfile(destF) and destF == os.path.basename(destFile) : return os.path.join(destPath, destF) elif os.path.isdir(destF) : search(os.path.join(destPath, destF), destFile) else : print 'can not find file %s' %destFile return None def iteratorHandle(srcPath, destPath, isNew = False): if os.path.isfile(srcPath) : destFile = search(destPath, srcPath) if destFile == None : if isNew == False : if os.path.isfile(srcPath) : try : os.chmod(srcPath, stat.S_IMODE(os.stat(srcPath)[stat.ST_MODE]) | stat.S_IREAD|stat.S_IWRITE) os.remove(srcPath) finally : os.system('del ' + srcPath + ' /F') else : print 'new file to add' else : newFileMT = time.localtime(os.stat(destFile).st_mtime) oldFileMT = time.localtime(os.stat(srcPath).st_mtime) if time.mktime(newFileMT) - time.mktime(oldFileMT) > 0 : oldFileDir = str(srcPath)[0:str(srcPath).rfind(os.path.sep)] oldFileName = os.path.basename(srcPath) oldFilenewName = str(srcPath)[0 : str(srcPath).rfind('.')] + '_backup' + str(srcPath)[str(srcPath).rfind('.') : ] os.rename(srcPath, os.path.join(oldFileDir, oldFilenewName)) open(os.path.join(oldFileDir, oldFileName), "wb").write(open(destFile, "rb").read()) elif os.path.isdir(srcPath) : for destFile in os.listdir(srcPath) : iteratorHandle(os.path.join(srcPath, destFile)) else : print 'iterator handle error' fileDir = 'C:\\Users\\Administrator\\Desktop\\project'clearSVN(fileDir)
0 0
- Python学习笔记-清除项目下SVN文件
- window下清除SVN文件
- eclipse下清除项目的svn信息
- 清除项目文件svn的关联
- Mac 下清除文件夹中的.svn文件
- Python学习笔记-清除变量
- 清除项目的svn
- python清除svn关联
- 【SVN】项目清除SVN标记
- 【SVN】项目清除SVN标记
- 快速清除项目中的.svn文件(svnClean)
- windows 下清除svn
- 清除svn版本号文件
- 清除SVN未版控文件
- 清除svn版本号文件
- 清除某个目录及其子目录下的.svn文件。
- 清除当前目录下的SVN文件批处理
- 清除文件中的.svn文件
- 简明 Vim 练级攻略
- HTML锚点
- PHP程序员如何突破技术瓶颈
- 关于div设置背景颜色透明度
- DELPHI 7 学习笔记
- Python学习笔记-清除项目下SVN文件
- 初学WIN8.1开发感想
- 生成不重复的防伪码
- 寻找知识不变的那部分
- Android 实现顶层窗口、悬浮窗口
- 嵌入式 2.6内核配置与裁剪浅析
- ubuntu解压文件命令和拷贝本件命令
- linux init执行顺序
- http://blog.csdn.net/ithomer/article/details/6688883