Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: jb-dev
Fetching contributors…

Cannot retrieve contributors at this time

executable file 142 lines (102 sloc) 3.768 kB
#!/usr/bin/env python
#coding=utf-8
import sys
import os
class fold:
files = {} #文件名 --- 全路径名 字典
filelist = [] #文件名 列表
foldlist = [] #目录名 列表
def __init__(self, fold):
get_files = os.popen('find ' + fold + ' -type f ').readlines()
get_folds = os.popen('find ' + fold + ' -type d ').readlines()
for _file in get_files :
fullpath = _file.rstrip('\n')
(pathname, filename) = fullpath.rsplit('/',1)
self.filelist.append(filename)
self.files[filename] = (fullpath, pathname)
for _fold in get_folds:
self.foldlist.append(_fold.rstrip('\n'))
class check:
output_same = []
output_diff = []
output_nofound = []
output_warning = []
action_copy = []
def __init__(self, local, source):
local_fold = fold(local)
for _file in local_fold.filelist :
file_finder = os.popen('find ' + source + ' -name ' + _file ).readlines()
if len(file_finder) == 1:
output=os.popen('diff -q ' + file_finder[0].rstrip('\n') + ' ' + local_fold.files[_file][0]).readlines()
if len(output) > 0 :
self.action_copy.append((file_finder[0].rstrip('\n'), local_fold.files[_file][0]))
for output_line in output :
self.output_diff.append((output_line.rstrip('\n')))
else :
self.output_same.append(file_finder[0].rstrip('\n') )
elif len(file_finder) > 1 :
for fd in file_finder :
output = os.popen('diff -s -q ' + fd.rstrip('\n') + ' ' + local_fold.files[_file][0]).readlines()
for output_line in output :
self.output_warning.append((output_line.rstrip('\n')))
else :
self.output_nofound.append((local_fold.files[_file][0] ))
def do_check(local, source):
c = check(local, source)
print('------------------------same---------------------')
for output in c.output_same :
print(output)
print('-------------------------------------------------')
print
print('------------------------nofound------------------')
for output in c.output_nofound :
print(output)
print('-------------------------------------------------')
print
print('------------------------diff---------------------')
for output in c.output_diff :
print(output)
print('-------------------------------------------------')
print
print('------------------------warning------------------')
for output in c.output_warning :
print(output)
print('-------------------------------------------------')
print
def do_copy(local, source):
c = check(local, source)
print('------------------------copy---------------------')
for copy in c.action_copy:
print(copy[0] + ' : ' + copy[1] )
output_copy = os.popen('cp -f ' + copy[0] + ' ' + copy[1] ).readlines()
for error in output_copy :
print(error.rstrip('\n'))
print('-------------------------------------------------')
print('------------------------nofound------------------')
for output in c.output_nofound :
print(output)
print('-------------------------------------------------')
print
print('------------------------warning------------------')
for output in c.output_warning :
print(output)
print('-------------------------------------------------')
print
def print_usage():
print('usage: vendor -check/--check local_fold source_fold')
print(' vendor -copy/--copy local_fold source_fold')
def main(argv):
if(len(argv) != 4):
print_usage()
return
if((argv[1] != '-copy') and (argv[1] != '-check') and (argv[1] != '--copy') and (argv[1] != '--check')) :
print_usage()
return
assert(os.path.exists(argv[2]))
assert(os.path.exists(argv[3]))
if(argv[1] == '-copy' or argv[1] == '--copy'):
do_copy(argv[2], argv[3])
elif(argv[1] == '-check' or argv[1] == '--check'):
do_check(argv[2], argv[3])
if __name__ == '__main__' :
main(sys.argv)
Jump to Line
Something went wrong with that request. Please try again.