1 |
lack 10/04/01 16:56:13 |
2 |
|
3 |
Added: 0distutils-r2 |
4 |
Log: |
5 |
Update to better deal with python3 and multiple python ABIs |
6 |
(Portage version: 2.1.8.3/cvs/Linux i686) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 rox-base/zeroinstall-injector/files/0distutils-r2 |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/zeroinstall-injector/files/0distutils-r2?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/zeroinstall-injector/files/0distutils-r2?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: 0distutils-r2 |
15 |
=================================================================== |
16 |
#!/usr/bin/python2 |
17 |
|
18 |
import os |
19 |
from xml.dom import minidom |
20 |
import xml.dom |
21 |
|
22 |
ns0compile = "http://zero-install.sourceforge.net/2006/namespaces/0compile" |
23 |
|
24 |
def escape(uri): |
25 |
import zeroinstall.injector.model |
26 |
return zeroinstall.injector.model._pretty_escape(uri) |
27 |
|
28 |
def cacheescape(uri): |
29 |
import zeroinstall.injector.model |
30 |
return zeroinstall.injector.model.escape(uri) |
31 |
|
32 |
def strip(node): |
33 |
torm = [] |
34 |
for c in node.childNodes: |
35 |
if c.nodeType == xml.dom.Node.TEXT_NODE and \ |
36 |
c.nodeValue.strip() == "": |
37 |
torm.append(c) |
38 |
elif c.hasChildNodes(): |
39 |
strip(c) |
40 |
for c in torm: |
41 |
node.removeChild(c) |
42 |
c.unlink() |
43 |
|
44 |
class LocalFeed(object): |
45 |
def __init__(self, xmlfile): |
46 |
self.xml = minidom.parse(xmlfile) |
47 |
if self.xml.documentElement.nodeName != "interface": |
48 |
raise TypeError("Not an interface") |
49 |
strip(self.xml.documentElement) |
50 |
|
51 |
def getUri(self): |
52 |
for element in self.xml.documentElement.getElementsByTagName("feed-for"): |
53 |
if element.hasAttribute("interface"): |
54 |
return element.getAttribute("interface") |
55 |
return None |
56 |
|
57 |
def edit(self, id=".", main="AppRun", stability="packaged"): |
58 |
for attribute in ("main", "uri"): |
59 |
if self.xml.documentElement.hasAttribute(attribute): |
60 |
self.xml.documentElement.removeAttribute(attribute) |
61 |
for group in self.xml.documentElement.getElementsByTagName("group"): |
62 |
group.setAttribute("main", "AppRun") |
63 |
if group.hasAttribute("arch") and group.getAttribute("arch") == "*-src": |
64 |
uname = os.uname() |
65 |
group.setAttribute("arch", "%s-%s" % (uname[0], uname[-1])) |
66 |
attr0comp = [] |
67 |
for aidx in range(0, group.attributes.length): |
68 |
attr = group.attributes.item(aidx) |
69 |
if attr.namespaceURI == ns0compile: |
70 |
attr0comp.append(attr) |
71 |
for attr in attr0comp: |
72 |
group.removeAttributeNode(attr) |
73 |
reqlist = group.getElementsByTagName("requires") |
74 |
for req in reqlist: |
75 |
group.removeChild(req) |
76 |
req.unlink() |
77 |
for imp in group.getElementsByTagName("implementation"): |
78 |
imp.setAttribute("stability",stability) |
79 |
imp.setAttribute("id",id) |
80 |
|
81 |
def dump(self): |
82 |
print self.xml.toprettyxml() |
83 |
|
84 |
def main(xmlfile, mode="edit"): |
85 |
try: |
86 |
feed = LocalFeed(xmlfile) |
87 |
if mode == "uri": |
88 |
print feed.getUri() |
89 |
elif mode == "escape": |
90 |
print escape(feed.getUri()) |
91 |
elif mode == "cache": |
92 |
print cacheescape(feed.getUri()) |
93 |
else: |
94 |
feed.edit() |
95 |
feed.dump() |
96 |
except Exception, e: |
97 |
import sys |
98 |
print "Fatal:", e |
99 |
sys.exit(2) |
100 |
|
101 |
def usage(program): |
102 |
import os.path |
103 |
progname = os.path.basename(program) |
104 |
print "Usage:", progname, "[-u|-e] <xmlfile>" |
105 |
print "Options:" |
106 |
print "\t-u --uri: Finds the URI from the feed" |
107 |
print "\t-e --escape: Escapes the URI from the feed" |
108 |
|
109 |
if __name__ == "__main__": |
110 |
from optparse import OptionParser |
111 |
import sys |
112 |
parser = OptionParser(usage="usage: %prog [options] feed.xml", |
113 |
description="By default, edits the given feed and prints the result on stdout.") |
114 |
parser.add_option("-e", "--escape", action="store_const", |
115 |
const="escape", dest="mode", |
116 |
help="Return the cache-escaped URI from the feed on stdout.") |
117 |
parser.add_option("-c", "--cache", action="store_const", |
118 |
const="cache", dest="mode", |
119 |
help="Return the file-escaped URI from the feed on stdout.") |
120 |
parser.add_option("-u", "--uri", action="store_const", |
121 |
const="uri", dest="mode", |
122 |
help="Return the original URI from the feed on stdout.") |
123 |
(options, args) = parser.parse_args() |
124 |
if len(args) == 0: |
125 |
parser.print_help() |
126 |
else: |
127 |
if len(args) > 1: |
128 |
parser.error("requires exactly one .xml file") |
129 |
main(args[0], options.mode) |
130 |
|
131 |
# vim: nosta noet sw=4 ts=4 |