This repository has been archived by the owner on Jan 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
mkpkg_xml_parser.py
154 lines (141 loc) · 4.71 KB
/
mkpkg_xml_parser.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/python
#reads data.xml and prints depends
#by Eugene Mikhailov
#this is free software :)
import xml.dom.minidom
import string
import sys
from xml.dom.minidom import Node
if len (sys.argv) <= 2:
print "Insufficient agumetns"
sys.exit(2)
doc=xml.dom.minidom.parse (sys.argv[1])
def get_deps():
global doc
depstring=""
try:
for node in doc.getElementsByTagName ("dep"):
skip=False
for depp in node.childNodes:
for detail in depp.childNodes:
if detail.parentNode.nodeName=="name":
tmp_name=string.strip (detail.nodeValue)
if tmp_name.startswith ("aaa"):
skip=True
else:
depstring+=tmp_name
if not skip and detail.parentNode.nodeName=="condition":
nv=string.strip(detail.nodeValue)
if nv=="more":
depstring+=">"
elif nv=="less":
depstring+="<"
elif nv=="notequal":
depstring+="!="
elif nv=="equal":
depstring+="=="
elif nv=="atleast":
depstring+=">="
elif nv=="notmore":
depstring+="<="
if not skip and detail.parentNode.nodeName=="version":
if not detail.nodeValue:
depstring+=" "
else:
depstring+=string.strip (detail.nodeValue)+" "
print string.strip (depstring)
except:
print "Oh shi~... No data.xml or it is very ugly."
sys.exit (2)
def get_package_attrs():
global doc
pkgname=pkgver=pkgbuild=pkgarch=""
try:
node=doc.firstChild
for p in node.childNodes:
for ptag in p.childNodes:
if ptag.parentNode.nodeName=="name":
pkgname=ptag.nodeValue.strip()
elif ptag.parentNode.nodeName=="version":
pkgver=ptag.nodeValue.strip()
elif ptag.parentNode.nodeName=="arch":
pkgarch=ptag.nodeValue.strip()
elif ptag.parentNode.nodeName=="build":
pkgbuild=ptag.nodeValue.strip()
print pkgname+" "+pkgver+" "+pkgarch+" "+pkgbuild
except:
print "Oh shi~... No data.xml or it is very ugly."
sys.exit (2)
def get_maintainer():
global doc
try:
for node in doc.getElementsByTagName ("maintainer"):
for mtag in node.childNodes:
for me in mtag.childNodes:
if me.parentNode.nodeName=="name":
print "Name: "+me.nodeValue.strip()
elif me.parentNode.nodeName=="email":
print "Email: "+me.nodeValue.strip()
except:
print "Oh shi~... No data.xml or it is very ugly."
sys.exit (2)
def get_tags():
taglist=""
global doc
try:
for node in doc.getElementsByTagName ("tags"):
for tags in node.childNodes:
for tag in tags.childNodes:
if tag.parentNode.nodeName=="tag":
taglist+=(tag.nodeValue.strip()+" ")
print taglist.strip()
except:
print "Oh shi~... No data.xml or it is very ugly."
sys.exit (2)
def get_provides():
global doc
pkgprovides=""
try:
node=doc.firstChild
for p in node.childNodes:
for ptag in p.childNodes:
if ptag.parentNode.nodeName=="provides":
pkgprovides=ptag.nodeValue.strip()
print pkgprovides
except:
print "Oh shi~... No data.xml or it is very ugly."
sys.exit (2)
def get_conflicts():
global doc
pkgconflicts=""
try:
node=doc.firstChild
for p in node.childNodes:
for ptag in p.childNodes:
if ptag.parentNode.nodeName=="conflicts":
pkgconflicts=ptag.nodeValue.strip()
print pkgconflicts
except:
print "Oh shi~... No data.xml or it is very ugly."
sys.exit (2)
if sys.argv[2]=="-m":
get_maintainer()
# sys.exit(0)
elif sys.argv [2]=="-d":
get_deps()
# sys.exit(0)
elif sys.argv[2]=="-p":
get_package_attrs()
sys.exit (0)
elif sys.argv[2]=="-t":
get_tags()
sys.exit(0)
elif sys.argv[2]=="-P":
get_provides()
sys.exit(0)
elif sys.argv[2]=="-C":
get_conflicts()
sys.exit(0)
else:
print "Unknown arg."
sys.exit(2)