2 # -*- coding: utf-8 -*-
7 dir1
= '''/Applications/Microsoft Word.app/'''
8 dir2
= '''/Applications/Microsoft Excel.app/'''
11 def get_common_files_helper(base_dir
, dcmp
):
12 if os
.path
.islink(os
.path
.join(dcmp
.right
)):
13 # print "skip dir link %s" % os.path.join(dcmp.left, base_dir)
17 rs0
= filecmp
.cmpfiles(dcmp
.left
, dcmp
.right
, dcmp
.same_files
, False)
19 rs
.append(os
.path
.join(base_dir
, name
))
21 # print "%s is false same" % os.path.join(base_dir, name)
23 for name
, sub_dcmp
in dcmp
.subdirs
.iteritems():
24 path
= os
.path
.join(base_dir
, name
)
25 rs
+= get_common_files_helper(path
, sub_dcmp
)
30 def get_common_files(dir1
, dir2
):
31 return get_common_files_helper("", filecmp
.dircmp(dir1
, dir2
))
35 return os
.stat(path
).st_ino
39 print "calculating common files..."
40 common_files
+= get_common_files(dir1
, dir2
)
43 print "Error: %s" % ex
.strerror
44 print "Maybe you have installed Office in a non-default location."
47 n_common_files
= len(common_files
)
48 print "n_common_files: %s" % n_common_files
50 for filename
in common_files
:
51 path1
= os
.path
.join(dir1
, filename
)
52 path2
= os
.path
.join(dir2
, filename
)
53 # if get_ino(path1) == get_ino(path2):
54 # print "same inode for %s" % filename
56 # print "diff inode for %s" % path1
57 # print " and %s" % path2
59 # os.rename won't create parent dir for me
60 # os.renames will prune empty dir from src
61 # Let's be lazy to skip backuping...
66 if i
% (n_common_files
/ 10) == 0:
67 print '%s files linked...' % i