68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
'''
|
|
Created on 2016/1/25
|
|
|
|
@author: Fisher Yu
|
|
'''
|
|
|
|
proj_path = "D:/features/projects/"
|
|
cloc_exe = "D:/features/cloc.exe --strip-comments=nc --original-dir "
|
|
git_exe = "C:/Program Files (x86)/Git/bin/git.exe diff"
|
|
|
|
import subprocess
|
|
def StripCommentExtractor(proj_name):
|
|
#mdir = proj_path + proj_name
|
|
mdir = cloc_exe + "D:/features/di"
|
|
#print mdir
|
|
cmd = subprocess.Popen(mdir, stderr=subprocess.PIPE)
|
|
if cmd.stderr:
|
|
error = cmd.stderr.readlines()
|
|
error = ''.join(error)
|
|
if "error" in error:
|
|
print error
|
|
else:
|
|
pass
|
|
|
|
import os
|
|
import difflib
|
|
from unidiff import PatchSet
|
|
def ExtractCommentFromDiff(proj_name):
|
|
path = "D:/features/di"
|
|
if not os.path.isdir(path):
|
|
print "not a file path, error"
|
|
return
|
|
for root, dirs, files in os.walk(path):
|
|
for sfile in files:
|
|
#print file
|
|
subf = sfile.split(".")
|
|
if subf[-1] != "nc":
|
|
#print sfile
|
|
source_file = os.path.join(root, sfile)
|
|
nc_file = source_file + ".nc"
|
|
if os.path.exists(nc_file):
|
|
df = difflib.ndiff(open(source_file).readlines(), \
|
|
open(nc_file).readlines())
|
|
diff = list(df)
|
|
comments = []
|
|
for line_diff in diff:
|
|
if line_diff.startswith("-"):
|
|
comments.append(line_diff)
|
|
print line_diff
|
|
|
|
|
|
'''
|
|
git_cmd = "%s %s %s" % (git_exe, source_file, nc_file)
|
|
print git_cmd
|
|
cmd = subprocess.Popen(git_cmd, stdout=subprocess.PIPE)
|
|
if cmd.stdout:
|
|
diff_text = cmd.stdout.readlines()
|
|
print diff_text
|
|
#os.system('pause')
|
|
else:
|
|
print "no diff"
|
|
'''
|
|
#os.remove(dir)
|
|
#print dir+' remove'
|
|
|
|
|
|
ExtractCommentFromDiff("")
|
|
#StripCommentExtractor("11") |