2 new revisions:

Revision: 63915f9e2075
Author:   Janne Härkönen <[email protected]>
Date:     Sun Jan 15 23:02:28 2012
Log:      tidy: creted class Tidy to encapsulate main logic
http://code.google.com/p/robotframework/source/detail?r=63915f9e2075

Revision: 46179d339fd9
Author:   Janne Härkönen <[email protected]>
Date:     Sun Jan 15 23:03:29 2012
Log:      tidytests: added regression tag
http://code.google.com/p/robotframework/source/detail?r=46179d339fd9

==============================================================================
Revision: 63915f9e2075
Author:   Janne Härkönen <[email protected]>
Date:     Sun Jan 15 23:02:28 2012
Log:      tidy: creted class Tidy to encapsulate main logic
http://code.google.com/p/robotframework/source/detail?r=63915f9e2075

Modified:
 /src/robot/tidy.py

=======================================
--- /src/robot/tidy.py  Fri Jan 13 05:47:36 2012
+++ /src/robot/tidy.py  Sun Jan 15 23:02:28 2012
@@ -32,53 +32,69 @@
 from robot.parsing import TestData, ResourceFile, TestDataDirectory
 from robot.parsing.populators import FromFilePopulator

-def _exit(message, status):
-    print message
-    if status:
-        print __doc__
-    sys.exit(status)
-
-def _parse_args():
-    parser = utils.ArgumentParser(__doc__)
-    try:
- return parser.parse_args(sys.argv[1:], help='help', check_args=True)
-    except DataError, err:
-        _exit(unicode(err), 1)
-
-def _create_datafile(source):
-    if os.path.splitext(os.path.basename(source))[0] == '__init__':
-        data = TestDataDirectory()
-        data.initfile = source
-        FromFilePopulator(data).populate(source)
-        return data
-    try:
-        return TestData(source=source)
-    except DataError, err:
+
+class Tidy(object):
+
+    def __init__(self, **options):
+        self._options = options
+
+    def files(self, files):
+        for f in files:
+            yield self._save_file(f)
+
+    def _save_file(self, path):
+        data = self._create_datafile(path)
+        output = StringIO()
+        data.save(output=output, **self._options)
+        return output.getvalue()
+
+    def directory(self, path):
+        self._save_recursively(self._create_datafile(path))
+
+    def _save_recursively(self, data):
+        init_file = getattr(data, 'initfile', None)
+        if init_file or not hasattr(data, 'initfile'):
+            data.save(**self._options)
+        if os.path.isfile(data.source):
+            os.remove(data.source)
+        if init_file:
+            os.remove(init_file)
+        for child in data.children:
+            self._save_recursively(child)
+
+    def _create_datafile(self, source):
+        if os.path.splitext(os.path.basename(source))[0] == '__init__':
+            data = TestDataDirectory()
+            data.initfile = source
+            FromFilePopulator(data).populate(source)
+            return data
         try:
-            return ResourceFile(source=source).populate()
+            return TestData(source=source)
         except DataError:
- _exit("Invalid data source '%s': %s" % (source, unicode(err)), 1)
-
-def _save_recursively(data, **options):
-    init_file = getattr(data, 'initfile', None)
-    if init_file or not hasattr(data, 'initfile'):
-        data.save(**options)
-    if os.path.isfile(data.source):
-        os.remove(data.source)
-    if init_file:
-        os.remove(init_file)
-    for child in data.children:
-        _save_recursively(child, **options)
-
-if __name__ == '__main__':
+            try:
+                return ResourceFile(source=source).populate()
+            except DataError:
+                raise DataError("Invalid data source '%s'" % source)
+
+
+def _parse_args():
+    parser = utils.ArgumentParser(__doc__)
+    return parser.parse_args(sys.argv[1:], help='help', check_args=True)
+
+def main():
     opts, args = _parse_args()
-    datafile = _create_datafile(args[0])
+    tidy = Tidy(format=opts['format'], pipe_separated=opts['use-pipes'])
     if not opts['inplace'] or not opts['recursive']:
-        output = StringIO()
-        datafile.save(output=output, format=opts['format'],
-                      pipe_separated=opts['use-pipes'])
-        print output.getvalue()
+        for output in tidy.files(args):
+            print output
     if opts['recursive']:
-        _save_recursively(datafile, format=opts['format'],
-                          pipe_separated=opts['use-pipes'])
-    _exit("", 0)
+        tidy.directory(args[0])
+
+
+if __name__ == '__main__':
+    try:
+        main()
+    except DataError, err:
+        print __doc__
+        sys.exit(unicode(err), 1)
+    sys.exit(0)

==============================================================================
Revision: 46179d339fd9
Author:   Janne Härkönen <[email protected]>
Date:     Sun Jan 15 23:03:29 2012
Log:      tidytests: added regression tag
http://code.google.com/p/robotframework/source/detail?r=46179d339fd9

Modified:
 /atest/robot/tidy/tidy.txt

=======================================
--- /atest/robot/tidy/tidy.txt  Fri Jan 13 05:47:36 2012
+++ /atest/robot/tidy/tidy.txt  Sun Jan 15 23:03:29 2012
@@ -1,5 +1,5 @@
 *** Settings ***
-Force Tags        pybot    jybot
+Force Tags        pybot    jybot   regression
 Library           TidyLib.py    ${INTERPRETER}
 Library           OperatingSystem
 Resource          atest_resource.txt

Reply via email to