aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@aura-online.co.uk>2008-06-08 16:18:08 +0000
committerJames Le Cuirot <chewi@aura-online.co.uk>2008-06-08 16:18:08 +0000
commitc217bba24bf982971910581ad3e9a82611f3757a (patch)
tree89fa00a5006b3f19a7728a484fa33313f61f8a07
parentDon't wrap inside quotes. (diff)
downloadjavatoolkit-c217bba24bf982971910581ad3e9a82611f3757a.tar.gz
javatoolkit-c217bba24bf982971910581ad3e9a82611f3757a.tar.bz2
javatoolkit-c217bba24bf982971910581ad3e9a82611f3757a.zip
Option to wrap when returning singular values.
svn path=/projects/javatoolkit/trunk/; revision=6293
-rw-r--r--src/buildparser/buildparser9
-rw-r--r--src/javatoolkit/parser/buildproperties.py5
-rw-r--r--src/javatoolkit/parser/manifest.py7
-rw-r--r--src/javatoolkit/parser/tree.py20
4 files changed, 29 insertions, 12 deletions
diff --git a/src/buildparser/buildparser b/src/buildparser/buildparser
index 3c6952a..f85781f 100644
--- a/src/buildparser/buildparser
+++ b/src/buildparser/buildparser
@@ -35,12 +35,16 @@ def parse_args():
about += "\n " + x
parser = OptionParser(usage, version=about)
+
parser.add_option('-t', '--type', action='store', type='choice',
dest='type', choices=['manifest', 'buildprops'],
help='Type of file to parse: manifest or buildprops')
parser.add_option('-i', '--in-place', action='store_true', dest='in_place',
help='Edit file in place when replacing')
+
+ parser.add_option('-w', '--wrap', action='store_true', dest='wrap',
+ help='Wrap when returning singular values')
opt, args = parser.parse_args()
@@ -106,7 +110,10 @@ def main():
n = t.find_node(args[0])
if n != None:
- print n.value
+ if opt.wrap:
+ print p.wrapped_value(n)
+ else:
+ print n.value
else:
for x in t.node_names():
diff --git a/src/javatoolkit/parser/buildproperties.py b/src/javatoolkit/parser/buildproperties.py
index 1d5a6af..0bb4043 100644
--- a/src/javatoolkit/parser/buildproperties.py
+++ b/src/javatoolkit/parser/buildproperties.py
@@ -1,6 +1,6 @@
#! /usr/bin/python
#
-# Copyright(c) 2006, James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright(c) 2004, Gentoo Foundation
#
@@ -78,6 +78,9 @@ class BuildPropertiesParser(parser.Parser):
def output(self, ous, tree):
tree.output(ous, "", " = ", "")
+
+ def wrapped_value(self, node):
+ return node.output_value()
if __name__ == "__main__":
print "This is not an executable module"
diff --git a/src/javatoolkit/parser/manifest.py b/src/javatoolkit/parser/manifest.py
index c4469ab..3fe45b7 100644
--- a/src/javatoolkit/parser/manifest.py
+++ b/src/javatoolkit/parser/manifest.py
@@ -1,6 +1,6 @@
#! /usr/bin/python
#
-# Copyright(c) 2006, James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
#
# Licensed under the GNU General Public License, v2
#
@@ -55,7 +55,10 @@ class ManifestParser(parser.Parser):
return root
def output(self, ous, tree):
- tree.output(ous, "", ": ", "", ",", " ");
+ tree.output(ous, "", ": ", "", ",", " ")
+
+ def wrapped_value(self, node):
+ return node.output_value(",")
if __name__ == "__main__":
print "This is not an executable module"
diff --git a/src/javatoolkit/parser/tree.py b/src/javatoolkit/parser/tree.py
index 3b48a9e..6d09e03 100644
--- a/src/javatoolkit/parser/tree.py
+++ b/src/javatoolkit/parser/tree.py
@@ -1,6 +1,6 @@
#! /usr/bin/python
#
-# Copyright(c) 2008, 2006, James Le Cuirot <chewi@aura-online.co.uk>
+# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright(c) 2004, Gentoo Foundation
#
@@ -57,18 +57,22 @@ class Node:
Output self as text to stream using the given format.
"""
def output(self, ous, before, between, after, wrap = None, indent = ""):
- if self.name:
- outval = self.value
-
- if wrap != None:
- outval = self.__wrap_outside_quotes(outval, wrap, indent)
-
- ous.write(before + self.name + between + outval + after + "\n")
+ if self.name:
+ ous.write(before + self.name + between + self.output_value(wrap, indent) + after + "\n")
for x in self._kids:
x.output(ous, before, between, after, wrap, indent)
"""
+ Return node value as string using the given format.
+ """
+ def output_value(self, wrap = None, indent = ""):
+ if wrap == None:
+ return self.value
+ else:
+ return self.__wrap_outside_quotes(self.value, wrap, indent)
+
+ """
Returns a lists of all the node names.
"""
def node_names(self):