-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_file_conflicts.py
executable file
·67 lines (43 loc) · 1.99 KB
/
check_file_conflicts.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
from modulefinder import packagePathMap
import sys
from tools.leafPackage import lfpkg
from tools.find_in import *
from tools.extract_packages import *
from tools.leafPackage.leafPackage import LeafPackage
if (len(sys.argv) != 3):
print("This script needs two arguments: <source directory> <cache directory>")
exit(-1)
srcDir = str(sys.argv[1])
cacheDir = str(sys.argv[2])
tar_packages = find_in_ext(srcDir, "lfpkg")
package_names = extract_packages(tar_packages, cacheDir)
print("Done extracting")
packages = []
for pkg_name in package_names:
print("Parsing package", pkg_name + "...")
packages.append(LeafPackage(cacheDir + "/" + pkg_name, lfpkg.parse(cacheDir + "/" + pkg_name + "/leaf.pkg")))
for package in packages:
package.index()
total_conflicts = 0
file_report = open("report_check_file_conflicts.txt", "w")
packages_with_conflicts = []
for src_package in packages:
print("Checking for file conflicts with", src_package._name)
for check_package in packages:
if (src_package._name != check_package._name):
conflicts = src_package.checkConflicts(check_package)
if (len(conflicts) > 0):
print("Found {} conflicts between {} and {}".format(len(conflicts), src_package._name, check_package._name))
total_conflicts += len(conflicts)
if (packages_with_conflicts.count(src_package) == 0):
packages_with_conflicts.append(src_package)
file_report.write("\n{} <=> {} ==> {} conflicts:\n".format(src_package._name, check_package._name, len(conflicts)))
for file in conflicts:
file_report.write("\t{}\n".format(file))
file_report.write("\n=> Packages with conflicts:\n")
for package in packages_with_conflicts:
file_report.write("\t==> {}\n".format(package._name))
file_report.write("\nTotal conflicts: {}\n".format(total_conflicts))
file_report.close()
print("Total conflicts found: {}".format(total_conflicts))