Revision: 2483
Author: janne.t.harkonen
Date: Fri Feb 19 01:49:25 2010
Log: Usage, cleanup
http://code.google.com/p/robotframework/source/detail?r=2483
Modified:
/trunk/tools/fixml/fixml.py
=======================================
--- /trunk/tools/fixml/fixml.py Thu Feb 18 22:13:17 2010
+++ /trunk/tools/fixml/fixml.py Fri Feb 19 01:49:25 2010
@@ -1,15 +1,45 @@
#!/usr/bin/env python
+# Copyright 2008-2009 Nokia Siemens Networks Oyj
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+"""fixml.py -- A tool to fix broken Robot Framework output files
+
+Usage: fixml.py inpath [outpath]
+
+This tool can fix Robot Framework output files that are not properly
finished
+or are missing elements from the middle. It should be possible to generate
+reports and logs from the fixed output afterwards with rebot.
+
+The tool uses BeautifulSoup module which must be installed separately. See
+http://www.crummy.com/software/BeautifulSoup/ for more information. The
tool
+is only compatible with Robot Framework 2.1.3 or newer.
+
+If `outpath` is not given, the file is fixed in-place.
+"""
+
import sys
+import os
try:
from BeautifulSoup import BeautifulStoneSoup
except ImportError:
- raise ImportError('fixml.py requires BeautifulSoup (%s) to be
installed.'
- % 'http://www.crummy.com/software/BeautifulSoup/')
+ raise ImportError('fixml.py requires BeautifulSoup to be installed: '
+ 'http://www.crummy.com/software/BeautifulSoup/')
-class Fixml(BeautifulStoneSoup):
- close_on_open = None
+class Fixxxer(BeautifulStoneSoup):
NESTABLE_TAGS = {
'suite': ['robot','suite', 'statistics'],
'doc': ['suite', 'test', 'kw'],
@@ -26,25 +56,38 @@
'statistics': ['robot'],
'errors': ['robot'],
}
-
- def unknown_starttag(self, name, *args):
- if self.close_on_open:
- self._popToTag(self.close_on_open)
- self.close_on_open = None
- BeautifulStoneSoup.unknown_starttag(self, name, *args)
+ __close_on_open = None
+
+ def unknown_starttag(self, name, attrs, selfClosing=0):
+ if name == 'robot':
+ attrs = [ (name, name == 'generator' and 'fixml.py' or value)
+ for name, value in attrs ]
+ if self.__close_on_open:
+ self._popToTag(self.__close_on_open)
+ self.__close_on_open = None
+ BeautifulStoneSoup.unknown_starttag(self, name, attrs, selfClosing)
def unknown_endtag(self, name):
BeautifulStoneSoup.unknown_endtag(self, name)
if name == 'status':
- self.close_on_open = self.tagStack[-1].name
+ self.__close_on_open = self.tagStack[-1].name
else:
- self.close_on_open = None
+ self.__close_on_open = None
+
+
+def main(inpath, outpath=None):
+ if not outpath:
+ outpath = inpath
+ outfile = open(outpath, 'w')
+ outfile.write(str(Fixxxer(open(inpath))))
+ outfile.close()
+ return outpath
+
if __name__ == '__main__':
- args = sys.argv[1:]
- if len(args) != 2:
+ try:
+ outpath = main(*sys.argv[1:])
+ except TypeError:
print __doc__
- sys.exit(1)
- outfile = open(args[1], 'w')
- outfile.write(str(Fixml(open(args[0]))))
- outfile.close()
+ else:
+ print os.path.abspath(outpath)