##// END OF EJS Templates
Fix exception handler syntax for Python 3 compatibility....
Daniel B. Vasquez -
Show More
@@ -38,7 +38,7 b' class PandocMissing(ConversionException):'
38 "Please check that pandoc is installed:\n" +
38 "Please check that pandoc is installed:\n" +
39 "http://johnmacfarlane.net/pandoc/installing.html" )
39 "http://johnmacfarlane.net/pandoc/installing.html" )
40
40
41 def pandoc_available(failmode="return", warn=False):
41 def pandoc_available(failmode="return", warn=False, alt=None):
42 """Is pandoc available. Only tries to call Pandoc
42 """Is pandoc available. Only tries to call Pandoc
43 and inform you that it succeeded or failed.
43 and inform you that it succeeded or failed.
44
44
@@ -50,6 +50,8 b' def pandoc_available(failmode="return", warn=False):'
50 the exception returned by subprocess.check_call.
50 the exception returned by subprocess.check_call.
51 - warn : bool
51 - warn : bool
52 issue a user warning if pandoc is not available.
52 issue a user warning if pandoc is not available.
53 - alt: list of strings
54 command to print in the error (not used as actual call)
53
55
54 Return
56 Return
55 ------
57 ------
@@ -63,10 +65,10 b' def pandoc_available(failmode="return", warn=False):'
63 try:
65 try:
64 out = subprocess.check_output(cmd, universal_newlines=True)
66 out = subprocess.check_output(cmd, universal_newlines=True)
65 return True, None
67 return True, None
66 except OSError, e:
68 except OSError as e:
67 if warn:
69 if warn:
68 warnings.warn(
70 warnings.warn(
69 "Pandoc cannot be found (call %s failed).\n" % " ".join(cmd) +
71 "Pandoc cannot be found (calling %s failed).\n" % " ".join(alt or cmd) +
70 "Please check that pandoc is installed:\n" +
72 "Please check that pandoc is installed:\n" +
71 "http://johnmacfarlane.net/pandoc/installing.html"
73 "http://johnmacfarlane.net/pandoc/installing.html"
72 )
74 )
@@ -74,7 +76,7 b' def pandoc_available(failmode="return", warn=False):'
74 if failmode == "return":
76 if failmode == "return":
75 return False, e
77 return False, e
76 else:
78 else:
77 raise PandocMissing(cmd, e)
79 raise PandocMissing(alt or cmd, e)
78
80
79
81
80 #-----------------------------------------------------------------------------
82 #-----------------------------------------------------------------------------
@@ -109,7 +111,7 b" def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):"
109 cmd.extend(extra_args)
111 cmd.extend(extra_args)
110
112
111 # if pandoc is missing let the exception bubble us out of here
113 # if pandoc is missing let the exception bubble us out of here
112 pandoc_available(failmode="raise")
114 pandoc_available(failmode="raise", alt=cmd)
113
115
114 # we can safely continue
116 # we can safely continue
115 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
117 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
General Comments 0
You need to be logged in to leave comments. Login now