forked from agilialinux-archive/mkpkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkpkg_xml_parser.py
More file actions
executable file
·167 lines (143 loc) · 5.06 KB
/
mkpkg_xml_parser.py
File metadata and controls
executable file
·167 lines (143 loc) · 5.06 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python
# XML парсер читает метаданные из файла data.xml пакета и выводит их.
#
# -m Вывести имя сопровождающего и его email
# -d Вывести зависимости пакета
# -o Вывести опциональные зависимости пакета
# -p Вывести атрибуты пакета.
# -t Вывести теги пакета
# -P Пакет предоставляет
# -C пакет конфликтует
import xml.etree.ElementTree as ET
import sys
def help():
print("Usage: mkpkg_xml_parser data.xml [OPTION]")
print("")
print("-m package maintainer and his email address.")
print("-d package dependencies.")
print("-o optional package dependencies.")
print("-p package attributes.")
print("-t package tags.")
print("-P package provides.")
print("-С the package is in conflict.")
def errors():
print("Error: data.xml is missing or corrupted!")
sys.exit(2)
if len(sys.argv) <= 2:
help()
sys.exit(2)
tree = ET.parse(sys.argv[1])
data = tree.getroot()
def get_deps():
depstring = ""
try:
if data.find("dependencies") is not None:
for dependencies in data.iter("dependencies"):
for dep in dependencies.iter("dep"):
for name in dep.iter("name"):
depstring += name.text.strip()
if data.iter("version") is not None:
for condition in dep.iter("condition"):
if condition.text.strip() == "more":
depstring += ">"
elif condition.text.strip() == "less":
depstring += "<"
elif condition.text.strip() == "notequal":
depstring += "<"
elif condition.text.strip() == "equal":
depstring += "=="
elif condition.text.strip() == "atleast":
depstring += ">="
elif condition.text.strip() == "notmore":
depstring += "<="
for versions in dep.iter("version"):
depstring += versions.text.strip()
depstring += " "
print(depstring.strip())
except Exception as e:
errors()
def get_package_attrs():
pkgname = pkgver = pkgarch = pkgbuild = ""
try:
pkgname += data.find("name").text.strip()
pkgver += data.find("version").text.strip()
pkgarch += data.find("arch").text.strip()
pkgbuild += data.find("build").text.strip()
print(pkgname + " " + pkgver + " " + pkgarch + " " + pkgbuild)
except Exception as e:
errors()
def get_maintainer():
try:
if data.find("maintainer") is not None:
for maintainer in data.iter("maintainer"):
for name in maintainer.iter("name"):
print("Name: "+name.text.strip())
for email in maintainer.iter("email"):
print("Email: "+email.text.strip())
except Exception as e:
errors()
def get_tags():
taglist = ""
try:
if data.find("tags") is not None:
for tags in data.iter("tags"):
for tag in tags.iter("tag"):
taglist += (tag.text.strip() + " ")
print(taglist.strip())
except Exception as e:
errors()
def get_provides():
pkgprovides = ""
try:
if data.find("provides") is not None:
for provides in data.iter("provides"):
pkgprovides += provides.text
print(pkgprovides.strip())
except Exception as e:
errors()
def get_conflicts():
pkgconflicts = ""
try:
if data.find("conflicts") is not None:
for conflicts in data.iter("conflicts"):
pkgconflicts += conflicts.text
print(pkgconflicts.strip())
except Exception as e:
errors()
def get_optional():
depstring = ""
try:
if data.find("optional") is not None:
for optional in data.iter("optional"):
for dep in optional.iter("dep"):
for name in dep.iter("name"):
depstring += name.text.strip()
depstring += " "
print(depstring.strip())
except Exception as e:
errors()
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)
elif sys.argv[2] == "-o":
get_optional()
sys.exit(0)
else:
print("Unknown arg!")
help()
sys.exit(2)