From e097175a77d94d41d8979c3fb4718b44c0e067b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:14:38 +0100 Subject: [PATCH 1/5] Import not used of BeautifulSoup --- tools/pelican_import.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index b883f7fc..c0d8bf1c 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -38,7 +38,7 @@ def wp2fields(xml): def dc2fields(file): """Opens a Dotclear export file, and yield pelican fields""" - from BeautifulSoup import BeautifulStoneSoup, BeautifulSoup + from BeautifulSoup import BeautifulStoneSoup in_cat = False in_post = False From c4f96b108f54a1968334767c93eb9d59dcb7f5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:16:11 +0100 Subject: [PATCH 2/5] Don't set unused fields of Dotclear post --- tools/pelican_import.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index c0d8bf1c..14f06138 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -85,10 +85,10 @@ def dc2fields(file): post_creadt = fields[6] # post_upddt = fields[7] # post_password = fields[8] - post_type = fields[9] + # post_type = fields[9] post_format = fields[10] - post_url = fields[11] - post_lang = fields[12] + # post_url = fields[11] + # post_lang = fields[12] post_title = fields[13] post_excerpt = fields[14] post_excerpt_xhtml = fields[15] From fec605b5775f0f9dba6e78a99f99dddcf09b8b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:17:06 +0100 Subject: [PATCH 3/5] Fix way to handle OSError (error doesn't exist) A better way would to use sys.stderr.write or PY3 print(file=sys.stderr) --- tools/pelican_import.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index 14f06138..12c3597f 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -2,6 +2,7 @@ import argparse import os +import sys import time from codecs import open @@ -259,14 +260,14 @@ def main(): elif args.feed: input_type = 'feed' else: - print("you must provide either --wpfile, --dotclear or --feed options") + print("You must provide either --wpfile, --dotclear or --feed options") exit() if not os.path.exists(args.output): try: os.mkdir(args.output) except OSError: - error("Couldn't create the output folder: " + args.output) + print("Unable to create the output folder: " + args.output) exit() # TODO: refactor this long assignment From d7f0b1637e1f6ed4c0ea54f3e314981c72581292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 02:20:33 +0100 Subject: [PATCH 4/5] Cleanup awful line with TODO in pelican-import --- tools/pelican_import.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index 12c3597f..8a425776 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -270,14 +270,11 @@ def main(): print("Unable to create the output folder: " + args.output) exit() - # TODO: refactor this long assignment - input_type, input, out_markup, output_path, dircat=False = input_type, args.input, args.markup, args.output, args.dircat - if input_type == 'wordpress': - fields = wp2fields(input) + fields = wp2fields(args.input) elif input_type == 'dotclear': - fields = dc2fields(input) + fields = dc2fields(args.input) elif input_type == 'feed': - fields = feed2fields(input) + fields = feed2fields(args.input) - fields2pelican(fields, out_markup, output_path, dircat=dircat) + fields2pelican(fields, args.markup, args.output, dircat=args.dircat or False) From 2f79d5f0526bb2fa6efd4755349d2673298ba608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Raimbault?= Date: Tue, 13 Mar 2012 16:52:28 +0100 Subject: [PATCH 5/5] Improve error handling when pandoc is missing --- tools/pelican_import.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/pelican_import.py b/tools/pelican_import.py index 8a425776..b89740df 100755 --- a/tools/pelican_import.py +++ b/tools/pelican_import.py @@ -2,6 +2,7 @@ import argparse import os +import subprocess import sys import time @@ -217,7 +218,20 @@ def fields2pelican(fields, out_markup, output_path, dircat=False): content = content.replace("\n", "
\n") fp.write(content) - os.system('pandoc --normalize --reference-links --from=html --to=%s -o "%s" "%s"' % (out_markup, out_filename, html_filename)) + cmd = 'pandoc --normalize --reference-links --from=html --to={0} -o "{1}" "{2}"'.format( + out_markup, out_filename, html_filename) + + try: + rc = subprocess.call(cmd, shell=True) + if rc < 0: + print("Child was terminated by signal %d" % -rc) + exit() + elif rc > 0: + print("Please, check your Pandoc installation.") + exit() + except OSError, e: + print("Pandoc execution failed: %s" % e) + exit() os.remove(html_filename)