pandoc is optional

This commit is contained in:
Alexis Metaireau 2012-06-10 13:27:36 +02:00
commit 7c48937ea2
2 changed files with 16 additions and 15 deletions

View file

@ -247,14 +247,15 @@ def fields2pelican(fields, out_markup, output_path, dircat=False, strip_raw=Fals
try: try:
rc = subprocess.call(cmd, shell=True) rc = subprocess.call(cmd, shell=True)
if rc < 0: if rc < 0:
print("Child was terminated by signal %d" % -rc) error = "Child was terminated by signal %d" % -rc
exit() exit(error)
elif rc > 0: elif rc > 0:
print("Please, check your Pandoc installation.") error = "Please, check your Pandoc installation."
exit() exit(error)
except OSError, e: except OSError, e:
print("Pandoc execution failed: %s" % e) error = "Pandoc execution failed: %s" % e
exit() exit(error)
os.remove(html_filename) os.remove(html_filename)
@ -302,15 +303,15 @@ def main():
elif args.feed: elif args.feed:
input_type = 'feed' input_type = 'feed'
else: else:
print("You must provide either --wpfile, --dotclear or --feed options") error = "You must provide either --wpfile, --dotclear or --feed options"
exit() exit(error)
if not os.path.exists(args.output): if not os.path.exists(args.output):
try: try:
os.mkdir(args.output) os.mkdir(args.output)
except OSError: except OSError:
print("Unable to create the output folder: " + args.output) error = "Unable to create the output folder: " + args.output
exit() exit(error)
if input_type == 'wordpress': if input_type == 'wordpress':
fields = wp2fields(args.input) fields = wp2fields(args.input)

View file

@ -11,11 +11,9 @@ WORDPRESS_XML_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpressexport.xml')
class TestWordpressXmlImporter(unittest.TestCase): class TestWordpressXmlImporter(unittest.TestCase):
def setUp(self): def setUp(self):
self.posts = wp2fields(WORDPRESS_XML_SAMPLE) self.posts = wp2fields(WORDPRESS_XML_SAMPLE)
def test_ignore_empty_posts(self): def test_ignore_empty_posts(self):
posts = list(self.posts) posts = list(self.posts)
@ -23,7 +21,7 @@ class TestWordpressXmlImporter(unittest.TestCase):
for title, content, fname, date, author, categ, tags, format in posts: for title, content, fname, date, author, categ, tags, format in posts:
self.assertTrue(title.strip()) self.assertTrue(title.strip())
@unittest.skipUnless(os.system('pandoc --version') == 0, 'pandoc is not installed')
def test_can_toggle_raw_html_code_parsing(self): def test_can_toggle_raw_html_code_parsing(self):
posts = list(self.posts) posts = list(self.posts)
@ -34,10 +32,12 @@ class TestWordpressXmlImporter(unittest.TestCase):
rst_files = (r(f) for f in silent_f2p(posts, 'markdown', temp)) rst_files = (r(f) for f in silent_f2p(posts, 'markdown', temp))
self.assertTrue(any('<iframe' in rst for rst in rst_files)) self.assertTrue(any('<iframe' in rst for rst in rst_files))
rst_files = (r(f) for f in silent_f2p(posts, 'markdown', temp, strip_raw=True)) rst_files = (r(f) for f in silent_f2p(posts, 'markdown', temp,
strip_raw=True))
self.assertFalse(any('<iframe' in rst for rst in rst_files)) self.assertFalse(any('<iframe' in rst for rst in rst_files))
# no effect in rst # no effect in rst
rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp)) rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp))
self.assertFalse(any('<iframe' in rst for rst in rst_files)) self.assertFalse(any('<iframe' in rst for rst in rst_files))
rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp, strip_raw=True)) rst_files = (r(f) for f in silent_f2p(posts, 'rst', temp,
strip_raw=True))
self.assertFalse(any('<iframe' in rst for rst in rst_files)) self.assertFalse(any('<iframe' in rst for rst in rst_files))