diff options
| author | 2021-02-03 19:17:50 -0500 | |
|---|---|---|
| committer | 2021-02-03 19:17:50 -0500 | |
| commit | 475d074fd74425efbe783fad08f97f2df0c4909f (patch) | |
| tree | 2acdae53999b3c74b716efa4edb5b40311fa356a /nikola/plugins/basic_import.py | |
| parent | cd502d52787f666fff3254d7d7e7578930c813c2 (diff) | |
| parent | 3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (diff) | |
Update upstream source from tag 'upstream/8.1.2'
Update to upstream version '8.1.2'
with Debian dir e5e966a9e6010ef70618dc9a61558fa4db35aceb
Diffstat (limited to 'nikola/plugins/basic_import.py')
| -rw-r--r-- | nikola/plugins/basic_import.py | 27 |
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(): |
