summaryrefslogtreecommitdiff
blob: 78bf4478ecd78f5464d1cd3d2917e095e65cabcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# HG changeset patch
# User Tim Hatch <tim@timhatch.com>
# Date 1445007300 25200
# Node ID 0036ab1c99e256298094505e5e92fdacdfc5b0a8
# Parent  c0c0d4049a7c325cd69b764c6ceb7747d319212d
Avoid the shell entirely when finding fonts.

Manually tested on OS X.

diff --git a/pygments/formatters/img.py b/pygments/formatters/img.py
--- a/pygments/formatters/img.py
+++ b/pygments/formatters/img.py
@@ -10,12 +10,13 @@
 """
 
 import sys
-import shlex
 
 from pygments.formatter import Formatter
 from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
     get_choice_opt, xrange
 
+import subprocess
+
 # Import this carefully
 try:
     from PIL import Image, ImageDraw, ImageFont
@@ -76,14 +77,11 @@
             self._create_nix()
 
     def _get_nix_font_path(self, name, style):
-        try:
-            from commands import getstatusoutput
-        except ImportError:
-            from subprocess import getstatusoutput
-        exit, out = getstatusoutput('fc-list %s file' % 
-                                    shlex.quote("%s:style=%s" % (name, style)))
-        if not exit:
-            lines = out.splitlines()
+        proc = subprocess.Popen(['fc-list', "%s:style=%s" % (name, style), 'file'],
+                                stdout=subprocess.PIPE, stderr=None)
+        stdout, _ = proc.communicate()
+        if proc.returncode == 0:
+            lines = stdout.splitlines()
             if lines:
                 path = lines[0].strip().strip(':')
                 return path
@@ -198,7 +196,7 @@
         bold and italic fonts will be generated.  This really should be a
         monospace font to look sane.
 
-        Default: "Bitstream Vera Sans Mono"
+        Default: "Bitstream Vera Sans Mono" on Windows, Courier New on *nix
 
     `font_size`
         The font size in points to be used.