Source

trac-ticketlinks / contrib / workflow / workflow_parser.py

Diff from to

File contrib/workflow/workflow_parser.py

 
 import sys
 import getopt
+import locale
 
 import pkg_resources
 pkg_resources.require('Trac')
     digraph_lines.append('}')
     return digraph_lines
 
-def main(filename, show_ops=False, show_perms=False):
+def main(filename, output, show_ops=False, show_perms=False):
     # Read in the config
     rawactions = readconfig(filename)
 
     digraph_lines = actions2graphviz(actions, show_ops, show_perms)
 
     # And output
-    sys.stdout.write('\n'.join(digraph_lines))
+    output.write(unicode.encode('\n'.join(digraph_lines), locale.getpreferredencoding()))
 
 def usage(output):
-    output.write('workflow_parser [options] configfile.ini\n'
+    output.write('workflow_parser [options] configfile.ini [output.dot]\n'
                  '-h --help shows this message\n'
                  '-o --operations include operations in the graph\n'
                  '-p --permissions include permissions in the graph\n'
         usage(sys.stderr)
         sys.stderr.flush()
         sys.exit(1)
-    main(args[0], show_ops, show_perms)
+    ini_filename = args[0]
+    if len(args) > 1:
+        output = open(args[1], 'w')
+    else:
+        output = sys.stdout
+
+    main(ini_filename, output, show_ops, show_perms)