/
conflict-detector
executable file
·128 lines (101 loc) · 3.7 KB
/
conflict-detector
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Detects conflict between files shipped within pisi packages
import os
import sys
import pisi
import optparse
mail_template = """\
From: %(distribution)s %(release)s %(arch)s Buildfarm <%(mailFrom)s>
To: %(mail_to)s
Subject: [%(subjectID)s] Package Conflict Status
Content-Type: text/plain;
charset="utf-8"
Dear Pardus contributors,
You are probably receiving this e-mail because some of your packages ships
files that conflicts with other packages. Below is the list of those packages
along with the list of conflicting files:
%(conflicts)s
Please fix these conflicts as soon as possible to keep Pardus repositories
as consistent as possible.
Thanks
Pardus Buildfarm
"""
"""
def send_mail(msg):
import smtplib
try:
session = smtplib.SMTP(smtp_server)
except:
print "*** Failed opening session on SMTP server %s. Aborting.."
return
try:
session.login(smtp_user, smtp_password)
except smtplib.SMTPAuthenticationError:
print "*** Authentication failed. Check your credentials."
return
#result = session.sendmail(mail_from, recipient, mail)
session.quit()
"""
def dump_results(conflicts, no_color=False, send_mail=False):
def colorize(msg, color, nocolor=False):
"""Colorizes the given message."""
if nocolor:
return msg
else:
colors = {'green' : '\x1b[32;01m%s\x1b[0m',
'red' : '\x1b[31;01m%s\x1b[0m',
'yellow' : '\x1b[33;01m%s\x1b[0m',
'bold' : '\x1b[1;01m%s\x1b[0m',
'none' : '\x1b[0m%s\x1b[0m',
}
return colors[color if sys.stdout.isatty() else 'none'] % msg
# conflicts now contains conflicting files as key
# and conflicting packages as list elements
for packages, files in conflicts.items():
files.sort()
for package in packages.split(","):
print colorize(package, 'green', no_color)
print "-----------"
for _file in files:
print colorize(" * %s" % _file, 'red', no_color)
print
if __name__ == "__main__":
parser = optparse.OptionParser(usage="Usage: %prog [options]",
version="%prog 0.1",
prog="conflict-detector")
parser.add_option("-m", "--send-mail",
action="store_true",
dest="sendmail",
default=False,
help="Send an e-mail to the buildfarm list and the packagers")
parser.add_option("-n", "--no-color",
action="store_true",
dest="nocolor",
default=False,
help="Do not colorize output")
(options, arguments) = parser.parse_args()
files = {}
conflicts = {}
rconflicts = {}
installdb = pisi.db.installdb.InstallDB()
for package in sorted(installdb.list_installed()):
package_file_list = ['/%s' % _f.path for _f in \
installdb.get_files(package).list]
for f in package_file_list:
if not files.has_key(f):
files[f] = package
elif os.path.isfile(f):
value = [package, files[f]]
try:
conflicts[f].extend(value)
except KeyError:
conflicts[f] = value
# Convert conflicts into rconflicts
for k,v in conflicts.items():
key = ",".join(v)
try:
rconflicts[key].append(k)
except KeyError:
rconflicts[key] = [k]
dump_results(rconflicts, options.nocolor, options.sendmail)