-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectorydiff.py
More file actions
62 lines (43 loc) · 1.86 KB
/
directorydiff.py
File metadata and controls
62 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
import filecmp
import os
import sys
import glob
from colorama import init, Fore, Back, Style
init(autoreset=True)
from filecmp import dircmp
def print_diff_files(dcmp):
errStyle = Fore.RED + Style.BRIGHT
endLeft = Style.DIM + dcmp.left
endRight = Style.DIM + dcmp.right
# Files both a and b, whose contents differ
for name in dcmp.diff_files:
print errStyle + "Different " + Style.RESET_ALL + name + " found in " + \
endLeft + Style.RESET_ALL + " and " + endRight
# Names in both a and b, such that the type differs between the directories,
# or names for which os.stat() reports an error.
for name in dcmp.common_funny:
print errStyle + "Common funny " + Style.RESET_ALL + name + " found in " + \
endLeft + Style.RESET_ALL + " and " + endRight
# Files which are in both a and b, but could not be compared.
for name in dcmp.funny_files:
print errStyle + "Funny files " + Style.RESET_ALL + name + " found in " + \
endLeft + Style.RESET_ALL + " and " + endRight
# Checks for files and subdirectories not found in both a and b
ignoredExtra = 0
# for name in dcmp.right_only:
# if name == '.DS_Store':
# ignoredExtra += 1
# print str(ignoredExtra) + ' extra found in ' + endLeft
extraStyle = errStyle + "Extra" + Style.RESET_ALL + Style.DIM + " ... " + Style.RESET_ALL
for name in dcmp.left_only:
print extraStyle + name + " found in " + endLeft
for name in dcmp.right_only:
print extraStyle + name + " found in " + endRight
# Recurses down through all subdirectories
for sub_dcmp in dcmp.subdirs.values():
print_diff_files(sub_dcmp)
# Initialize dcmp with directories from terminal
# dircmp(directory1, dir2, ignore[], hidden[])
dcmp = dircmp(sys.argv[1], sys.argv[2])
print_diff_files(dcmp)