-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfind-duplicate-pkgs
executable file
·79 lines (64 loc) · 2.24 KB
/
find-duplicate-pkgs
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Prints duplicate packages that exist in both binary repositories.
#
#
#
# http://paketler.pardus.org.tr/pardus-2009/pisi-index.xml.bz2
# http://paketler.pardus.org.tr/contrib-2009/pisi-index.xml.bz2
import os
import sys
import piksemel
import bz2
import urllib2
def loadUrlData(_url):
try:
downloaded_data = urllib2.urlopen(_url).read()
except urllib2.URLError:
print "could not download %s" % _url
sys.exit(1)
print "Remote file %s has been downloaded." % _url
if _url.endswith(".bz2"):
rawData = bz2.decompress(downloaded_data)
return piksemel.parseString(rawData)
else:
return piksemel.parseString(downloaded_data)
def getXmlData(_file):
if os.path.exists(_file):
return piksemel.parse(_file)
elif os.path.exists("%s.bz2" % _file):
indexdata = bz2.decompress(file("%s.bz2" % _file).read())
return piksemel.parseString(indexdata)
else:
print "please give the index file as a parameter or go to that folder."
print " Can it be a remote file?"
sys.exit(1)
def parseXmlData(_index):
pkglist = []
for pkg in _index.tags("Package"):
pkglist.append(pkg.getTagData("Name"))
return pkglist
if __name__ == "__main__":
if len(sys.argv) == 3:
first_index_file = sys.argv[1]
second_index_file = sys.argv[2]
else:
print "Usage: %s first_index_file second_index_file" % sys.argv[0]
sys.exit(1)
try:
first_xmldata = getXmlData(first_index_file)
except:
first_xmldata = loadUrlData(first_index_file)
first_packagesIndex= parseXmlData(first_xmldata)
try:
second_xmldata = getXmlData(second_index_file)
except:
second_xmldata = loadUrlData(second_index_file)
second_packagesIndex= parseXmlData(second_xmldata)
duplicate_pkgs = list(set(first_packagesIndex) & set(second_packagesIndex))
print "-----------------------------------------------------------------------"
print "Duplicate Packages between \n%s\n\t\t\tand \n%s are:" % (sys.argv[1], sys.argv[2])
print "-----------------------------------------------------------------------"
for i in duplicate_pkgs:
print i