aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/basic_import.py
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/basic_import.py')
-rw-r--r--nikola/plugins/basic_import.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/nikola/plugins/basic_import.py b/nikola/plugins/basic_import.py
index cf98ebc..3e6e21e 100644
--- a/nikola/plugins/basic_import.py
+++ b/nikola/plugins/basic_import.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright © 2012-2016 Roberto Alsina and others.
+# Copyright © 2012-2020 Roberto Alsina and others.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
@@ -26,21 +26,15 @@
"""Mixin for importer plugins."""
-from __future__ import unicode_literals, print_function
import io
import csv
import datetime
import os
-import sys
-from pkg_resources import resource_filename
-
-try:
- from urlparse import urlparse
-except ImportError:
- from urllib.parse import urlparse # NOQA
+from urllib.parse import urlparse
from lxml import etree, html
from mako.template import Template
+from pkg_resources import resource_filename
from nikola import utils
@@ -90,7 +84,7 @@ class ImportMixin(object):
src = (urlparse(k).path + 'index.html')[1:]
dst = (urlparse(v).path)
if src == index:
- utils.LOGGER.warn("Can't do a redirect for: {0!r}".format(k))
+ utils.LOGGER.warning("Can't do a redirect for: {0!r}".format(k))
else:
redirections.append((src, dst))
return redirections
@@ -101,8 +95,8 @@ class ImportMixin(object):
os.system('nikola init -q ' + self.output_folder)
else:
self.import_into_existing_site = True
- utils.LOGGER.notice('The folder {0} already exists - assuming that this is a '
- 'already existing Nikola site.'.format(self.output_folder))
+ utils.LOGGER.warning('The folder {0} already exists - assuming that this is a '
+ 'already existing Nikola site.'.format(self.output_folder))
filename = resource_filename('nikola', 'conf.py.in')
# The 'strict_undefined=True' will give the missing symbol name if any,
@@ -150,7 +144,7 @@ class ImportMixin(object):
content = html.tostring(doc, encoding='utf8')
except etree.ParserError:
pass
- if isinstance(content, utils.bytes_str):
+ if isinstance(content, bytes):
content = content.decode('utf-8')
compiler.create_post(
filename,
@@ -158,8 +152,7 @@ class ImportMixin(object):
onefile=True,
**headers)
- @staticmethod
- def write_metadata(filename, title, slug, post_date, description, tags, **kwargs):
+ def write_metadata(self, filename, title, slug, post_date, description, tags, **kwargs):
"""Write metadata to meta file."""
if not description:
description = ""
@@ -168,13 +161,13 @@ class ImportMixin(object):
with io.open(filename, "w+", encoding="utf8") as fd:
data = {'title': title, 'slug': slug, 'date': post_date, 'tags': ','.join(tags), 'description': description}
data.update(kwargs)
- fd.write(utils.write_metadata(data))
+ fd.write(utils.write_metadata(data, site=self.site, comment_wrap=False))
@staticmethod
def write_urlmap_csv(output_file, url_map):
"""Write urlmap to csv file."""
utils.makedirs(os.path.dirname(output_file))
- fmode = 'wb+' if sys.version_info[0] == 2 else 'w+'
+ fmode = 'w+'
with io.open(output_file, fmode) as fd:
csv_writer = csv.writer(fd)
for item in url_map.items():