#!/usr/bin/env python
#-*- coding=utf-8 -*-
import sys, os, stat
#清除项目里面的svn版本信息
def purge(path):
count = 0
for item in os.listdir(path):
subpath = os.path.join(path,item)
mode = os.stat(subpath)[stat.ST_MODE]
if stat.S_ISDIR(mode):
count = purge(subpath)
else:
os.chmod(subpath,stat.S_IREAD|stat.S_IWRITE)
os.unlink(subpath)
count = 1
os.rmdir(path)
count = 1
return count
#递归循环目录
def walk(path):
for item in os.listdir(path):
subpath = os.path.join(path, item)
mode = os.stat(subpath)[stat.ST_MODE]
if stat.S_ISDIR(mode):
if item == ".svn":
print "清除 %s 的版本信息..." %subpath
print "%d 被删除" % purge(subpath)
else:
walk(subpath)
#清除完毕,退出
#if len(sys.argv) != 2:
# print "已经清除.svn文件"
# sys.exit(1)
调用函数,以清除版本信息
walk(raw_input('请输入你项目的绝对目录:'))
#递归目录
def walkread(path):
for item in os.listdir(path):
subpath = os.path.join(path, item)
mode = os.stat(subpath)[stat.ST_MODE]
if stat.S_ISDIR(mode):
walkread(subpath)
else:
filework(subpath)
print '%s是文件' % subpath
#以下函数较为简单,具体实现依据你个人的统计
#全局变量 记录项目总行数
codeline = 0
def filework(filepath):
global codeline
if filepath[-4:] != '.pyc':
codename = open('/home/scr/my/code','ab')
line = os.linesep
codename.write(filepath)
codeline += 1
codename.write(line)
coderead = open(filepath,'rb')
for cont in coderead:
codename.write(cont)
codeline += 1
codename.write(line)
coderead.close()
codename.close()
walkread(raw_input('请输入你项目的绝对目录:'))#例如'/var/www/html/iuuc/'
print '总行数 %d' % codeline
转载于:https://my.oschina.net/tenking/blog/29359