summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorColin Walters <walters@src.gnome.org>2008-09-27 22:00:52 +0000
committerColin Walters <walters@src.gnome.org>2008-09-27 22:00:52 +0000
commita9f0931d65e8305a852c8de56ea6bae49f4bc896 (patch)
treec04d0248d0e084d47f3aef4f189a126bd3245111 /tools
parentc7405c288a25aa823b1a14b7b9ecc165b80c1bcc (diff)
downloadgobject-introspection-a9f0931d65e8305a852c8de56ea6bae49f4bc896.tar.gz
Add g-ir-scanner --inject
svn path=/trunk/; revision=631
Diffstat (limited to 'tools')
-rwxr-xr-xtools/g-ir-scanner27
1 files changed, 26 insertions, 1 deletions
diff --git a/tools/g-ir-scanner b/tools/g-ir-scanner
index 7d059fca..667a9acc 100755
--- a/tools/g-ir-scanner
+++ b/tools/g-ir-scanner
@@ -38,7 +38,7 @@ sys.path.insert(0, path)
from giscanner.glibtransformer import GLibTransformer
from giscanner.sourcescanner import SourceScanner
from giscanner.transformer import Transformer
-from giscanner.minixpath import xpath_assert
+from giscanner.minixpath import myxpath, xpath_assert
def _get_option_parser():
@@ -77,6 +77,9 @@ def _get_option_parser():
parser.add_option("", "--typelib-xml",
action="store_true", dest="typelib_xml",
help="Just convert GIR to typelib XML")
+ parser.add_option("", "--inject",
+ action="store_true", dest="inject",
+ help="Inject additional components into GIR XML")
parser.add_option("", "--xpath-assertions",
action="store", dest="xpath_assertions",
help="Use given file to create assertions on GIR content")
@@ -113,6 +116,23 @@ def typelib_xml_strip(path):
doc.write(sys.stdout)
return 0
+def inject(path, additions, outpath):
+ from xml.etree.cElementTree import parse
+ doc = parse(open(path))
+ root = doc.getroot()
+ injectDoc = parse(open(additions))
+ for node in injectDoc.getroot():
+ injectPath = node.attrib['path']
+ target = myxpath(root, injectPath)
+ if not target:
+ raise ValueError("Couldn't find path %r" % (injectPath, ))
+ for child in node:
+ target.append(child)
+ outf = open(outpath, 'w')
+ doc.write(outf)
+ outf.close()
+ return 0
+
def validate(assertions, path):
from xml.etree.cElementTree import parse
doc = parse(open(path))
@@ -138,6 +158,11 @@ def main(args):
if options.typelib_xml:
return typelib_xml_strip(args[1])
+ if options.inject:
+ if len(args) != 4:
+ _error('Need three filenames; e.g. g-ir-scanner --inject Source.gir Additions.xml SourceOut.gir')
+ return inject(*args[1:4])
+
if options.xpath_assertions:
return validate(options.xpath_assertions, args[1])