This commit is contained in:
Dominique Plante 2013-08-16 20:07:00 -07:00
commit ae826297c1
3 changed files with 153 additions and 3 deletions

File diff suppressed because one or more lines are too long

View file

@ -4,12 +4,17 @@ from __future__ import unicode_literals, print_function
import os
import re
from pelican.tools.pelican_import import wp2fields, fields2pelican, decode_wp_content
from pelican.tools.pelican_import import dc2fields, wp2fields, fields2pelican, decode_wp_content
from pelican.tests.support import (unittest, temporary_folder, mute,
skipIfNoExecutable)
CUR_DIR = os.path.dirname(__file__)
WORDPRESS_XML_SAMPLE = os.path.join(CUR_DIR, 'content', 'wordpressexport.xml')
# based on http://themes.dotaddict.org/files/public/downloads/lorem-backup.txt
# suggested by http://docs.getpelican.com/en/2.8/importer.html
DOTCLEAR_SAMPLE = os.path.join(CUR_DIR, 'content', 'lorem_backup_dotclear-2.1.5.txt')
WORDPRESS_ENCODED_CONTENT_SAMPLE = os.path.join(CUR_DIR,
'content',
'wordpress_content_encoded')
@ -22,6 +27,17 @@ try:
except ImportError:
BeautifulSoup = False # NOQA
@unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module')
class DotClearImporter(unittest.TestCase):
def test_dotclear(self):
# Act
self.posts = list(dc2fields(DOTCLEAR_SAMPLE))
# Assert
self.assertEqual(26, len(self.posts))
self.assertEqual(u'Mon premier billet', self.posts[0][0])
#x = self.posts
@skipIfNoExecutable(['pandoc', '--version'])
@unittest.skipUnless(BeautifulSoup, 'Needs BeautifulSoup module')

View file

@ -152,18 +152,21 @@ def dc2fields(file):
'"BeautifulSoup4" and "lxml" required to import Dotclear files.')
sys.exit(error)
in_cat = False
in_post = False
category_list = {}
posts = []
with open(file, 'r', encoding='utf-8') as f:
for line in f:
# remove final \n
line = line[:-1]
# When there is a line break, interpret this as a section break
if line == '\r':
in_cat = False
in_post = False
if line.startswith('[category'):
in_cat = True
elif line.startswith('[post'):