modified: myjupyterlab.sh
[GalaxyCodeBases.git] / etc / Mac / OfficeThinner / office-thinner.py
blob2e8fe6dfc256a2e116245919abefcd81d3e263e0
1 #! /usr/bin/python
2 # -*- coding: utf-8 -*-
4 import os
5 import filecmp
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)
14 return []
15 else:
16 rs = []
17 rs0 = filecmp.cmpfiles(dcmp.left, dcmp.right, dcmp.same_files, False)
18 for name in rs0[0]:
19 rs.append(os.path.join(base_dir, name))
20 # for name in rs0[1]:
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)
27 return rs
30 def get_common_files(dir1, dir2):
31 return get_common_files_helper("", filecmp.dircmp(dir1, dir2))
34 def get_ino(path):
35 return os.stat(path).st_ino
37 common_files = []
38 try:
39 print "calculating common files..."
40 common_files += get_common_files(dir1, dir2)
42 except OSError as ex:
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
49 i = 0
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
55 # else:
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...
62 os.remove(path2)
63 os.link(path1, path2)
65 i += 1
66 if i % (n_common_files / 10) == 0:
67 print '%s files linked...' % i
69 print "done"