-
Notifications
You must be signed in to change notification settings - Fork 7
/
find-unused-packages
executable file
·65 lines (47 loc) · 1.45 KB
/
find-unused-packages
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Pisi repository unused files checker
#
# Gets lists of pisi files from filesystem and index and prints the diff
#
import os
import sys
import piksemel
import bz2
indexfile = "pisi-index.xml"
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 parameter or go to that folder"
sys.exit(1)
def parseXmlData(_index):
pkglist = []
for pkg in _index.tags("Package"):
pkglist.append(pkg.getTagData("PackageURI"))
parent = pkg.getTag("DeltaPackages")
if parent:
for node in parent.tags("Delta"):
pkglist.append(node.getTagData("PackageURI"))
return pkglist
def getFolderPackages(_path):
pkglist = []
for i in os.listdir(_path):
if i.endswith(".pisi"):
pkglist.append(i)
return pkglist
if __name__ == "__main__":
if len(sys.argv) > 1:
indexfile = sys.argv[1]
xmldata = getXmlData(indexfile)
packagesIndex = parseXmlData(xmldata)
indexpath = os.path.dirname(indexfile)
packagesFolder = getFolderPackages(indexpath)
unusedPackages = list(set(packagesFolder) - set(packagesIndex))
unusedPackages.sort()
for i in unusedPackages:
print i