Commits

Anonymous committed cb14bf7

0.12-stable: Ticket #6930: use preferred encoding, and try more than kpdf for viewers

  • Participants
  • Parent commits bfdde2d
  • Branches 0.12-stable

Comments (0)

Files changed (2)

File contrib/workflow/showworkflow

 pdf=`echo "$config" | sed 's/\.ini$/.pdf/g'`
 png=`echo "$config" | sed 's/\.ini$/.png/g'`
 
-$basedir/workflow_parser.py $options "$config" > "$dot"
+$basedir/workflow_parser.py $options "$config" "$dot"
 if [ $? -ne 0 ]; then
     echo "Failed to parse \"$config\", exiting." >&2
     exit 1
     dot -T png -o "$png" "$dot"
     cmd /c start $png
 else
-    dot -T ps -o "$ps" "$dot" && ps2pdf "$ps" "$pdf" || exit 1
-    kpdf "$pdf"
+    dot -T ps -o "$ps" "$dot"
+    dot -T pdf -o "$pdf" "$dot"
+    # attempt to find a Linux pdf viewer
+    for viewer in kpdf okular evince; do
+        if which $viewer >/dev/null 2>&1; then
+            break
+        fi
+    done
+    $viewer "$pdf"
 fi

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)