-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwilFileDiff.py
executable file
·45 lines (32 loc) · 1.36 KB
/
wilFileDiff.py
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
#!/usr/bin/env python
from WillirPyUtils import runCommand;
from optparse import OptionParser;
import os;
import re;
parser = OptionParser("%prog [options] FIST_DIR SECOND_DIR",
description="Returns files list which exist in first direcory but no exist in second.");
parser.add_option("-r", "--recursive", action="store_true", dest="recursive",
help="Lookup all directory recursively?")
parser.add_option("-d", "--delimiter", type=str, default=" ", dest="delimiter",
help="Delimiter for output files list")
(options, args) = parser.parse_args();
recursive = options.recursive;
delimiter = options.delimiter;
if delimiter == '\\n':
delimiter = '\n';
firstDir = args[0];
secondDir = args[1];
if not os.path.isdir(firstDir):
print firstDir, "is not dir, or is absent";
exit(1);
if not os.path.isdir(secondDir):
print secondDir, "is not dir, or is absent";
exit(1);
cmd = "find ." if recursive else "ls"
(_, firstFileListS, _) = runCommand(cmd, cwd=firstDir, exception=True);
(_, secondFileListS, _) = runCommand(cmd, cwd=secondDir, exception=True);
removeStartPoint = lambda (x): re.sub(r"^\./+", "", x);
firstFileSet = set(map(removeStartPoint, firstFileListS.split()));
secondFileSet = set(map(removeStartPoint, secondFileListS.split()));
print delimiter.join(sorted(list(firstFileSet - secondFileSet)));
exit(0);