aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Le Cuirot <chewi@aura-online.co.uk>2008-06-06 10:30:26 +0000
committerJames Le Cuirot <chewi@aura-online.co.uk>2008-06-06 10:30:26 +0000
commit5621f1ce5af26be025b7276ed6b79a0cd7f0420c (patch)
tree0e0683243e45861f684529bf71eaa848f98f64f3
parentAdd encoding for javadoc and reorganize logic. (diff)
downloadjavatoolkit-5621f1ce5af26be025b7276ed6b79a0cd7f0420c.tar.gz
javatoolkit-5621f1ce5af26be025b7276ed6b79a0cd7f0420c.tar.bz2
javatoolkit-5621f1ce5af26be025b7276ed6b79a0cd7f0420c.zip
In-place editing for buildparser.
svn path=/projects/javatoolkit/trunk/; revision=6280
-rw-r--r--src/buildparser/buildparser14
-rw-r--r--src/javatoolkit/parser/buildproperties.py4
-rw-r--r--src/javatoolkit/parser/manifest.py4
-rw-r--r--src/javatoolkit/parser/parser.py2
-rw-r--r--src/javatoolkit/parser/tree.py12
5 files changed, 23 insertions, 13 deletions
diff --git a/src/buildparser/buildparser b/src/buildparser/buildparser
index 0cff6d3..19c1fe0 100644
--- a/src/buildparser/buildparser
+++ b/src/buildparser/buildparser
@@ -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) 2005, Karl Trygve Kalleberg <karltk@gentoo.org>
#
# Licensed under the GNU General Public License, v2
@@ -38,6 +38,9 @@ def parse_args():
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')
opt, args = parser.parse_args()
@@ -78,6 +81,7 @@ def main():
sys.exit(__productname__ + ": error: Unknown file type. Specify using the -t option.")
t = p.parse(f)
+ f.close()
except ParseError:
sys.exit(__productname__ + ": error: Unable to parse file.")
@@ -87,8 +91,14 @@ def main():
if n != None:
n.value = args[1]
+
+ if n != None and opt.in_place:
+ f = open(args[-1], "w+")
+ p.output(f, t)
+ f.close()
- p.output(t)
+ else:
+ p.output(sys.stdout, t)
elif len(args) > 1:
n = t.find_node(args[0])
diff --git a/src/javatoolkit/parser/buildproperties.py b/src/javatoolkit/parser/buildproperties.py
index 0c2ee53..1d5a6af 100644
--- a/src/javatoolkit/parser/buildproperties.py
+++ b/src/javatoolkit/parser/buildproperties.py
@@ -76,8 +76,8 @@ class BuildPropertiesParser(parser.Parser):
return root
- def output(self, tree):
- tree.output("", " = ", "")
+ def output(self, ous, tree):
+ tree.output(ous, "", " = ", "")
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 810914a..c4469ab 100644
--- a/src/javatoolkit/parser/manifest.py
+++ b/src/javatoolkit/parser/manifest.py
@@ -54,8 +54,8 @@ class ManifestParser(parser.Parser):
return root
- def output(self, tree):
- tree.output("", ": ", "", ",", " ");
+ def output(self, ous, tree):
+ tree.output(ous, "", ": ", "", ",", " ");
if __name__ == "__main__":
print "This is not an executable module"
diff --git a/src/javatoolkit/parser/parser.py b/src/javatoolkit/parser/parser.py
index e99a7a1..75f3290 100644
--- a/src/javatoolkit/parser/parser.py
+++ b/src/javatoolkit/parser/parser.py
@@ -9,7 +9,7 @@
class Parser:
def parse(self, ins):
raise NotImplementedError
- def output(self, tree):
+ def output(self, ous, tree):
raise NotImplementedError
if __name__ == "__main__":
diff --git a/src/javatoolkit/parser/tree.py b/src/javatoolkit/parser/tree.py
index eb51874..5af010f 100644
--- a/src/javatoolkit/parser/tree.py
+++ b/src/javatoolkit/parser/tree.py
@@ -40,23 +40,23 @@ class Node:
self._kids.append(kid)
- def _dump_kids(self, indent, ous):
+ def _dump_kids(self, ous, indent):
for x in self._kids:
- x.dump(indent + 1)
+ x.dump(ous, indent + 1)
"""
Dump self as text to stream.
"""
- def dump(self, indent = 0, ous = sys.stdout):
+ def dump(self, ous, indent = 0):
if self.name:
ous.write((" " * indent) + self.name + " = " + self.value + "\n")
- self._dump_kids(indent, ous)
+ self._dump_kids(ous, indent)
"""
Output self as text to stream using the given format.
"""
- def output(self, before, between, after, wrap = None, indent = "", ous = sys.stdout):
+ def output(self, ous, before, between, after, wrap = None, indent = ""):
if self.name:
outval = self.value
@@ -66,7 +66,7 @@ class Node:
ous.write(before + self.name + between + outval + after + "\n")
for x in self._kids:
- x.output(before, between, after, wrap, indent, ous)
+ x.output(ous, before, between, after, wrap, indent)
"""
Returns a lists of all the node names.