Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/nikola
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a3d435cc018b
Choose a base ref
...
head repository: getnikola/nikola
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0a4b06e39341
Choose a head ref
  • 4 commits
  • 2 files changed
  • 1 contributor

Commits on Jul 11, 2015

  1. Improved code.

    felixfontein committed Jul 11, 2015

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    59eddfd View commit details
  2. Copy the full SHA
    6782c79 View commit details
  3. Added option which automatically installs the WordPress page compiler…

    … either locally (when transforming posts right away) or into the new site.
    felixfontein committed Jul 11, 2015
    Copy the full SHA
    720baac View commit details
  4. Copy the full SHA
    0a4b06e View commit details
Showing with 56 additions and 18 deletions.
  1. +47 −13 nikola/plugins/command/import_wordpress.py
  2. +9 −5 nikola/plugins/command/plugin.py
60 changes: 47 additions & 13 deletions nikola/plugins/command/import_wordpress.py
Original file line number Diff line number Diff line change
@@ -52,10 +52,25 @@
from nikola.plugins.basic_import import ImportMixin, links
from nikola.nikola import DEFAULT_TRANSLATIONS_PATTERN
from nikola.plugins.command.init import SAMPLE_CONF, prepare_config, format_default_translations_config
from nikola.plugins.command import plugin

LOGGER = utils.get_logger('import_wordpress', utils.STDERR_HANDLER)


def install_plugin(site, plugin_name, output_dir=None):
plugin_installer = plugin.CommandPlugin()
plugin_installer.set_site(site)
options = {}
for option in plugin_installer.cmd_options:
options[option['name']] = option['default']
options['install'] = plugin_name
options['output_dir'] = output_dir
if not plugin_installer.execute(options=options):
return False
site.plugin_manager.collectPlugins()
return True


class CommandImportWordpress(Command, ImportMixin):
"""Import a WordPress dump."""

@@ -152,9 +167,25 @@ class CommandImportWordpress(Command, ImportMixin):
'type': bool,
'help': "Instead of converting posts to markdown, leave them as is and use the WordPress page compiler",
},
{
'name': 'install_wordpress_compiler',
'long': 'install-wordpress-compiler',
'default': False,
'type': bool,
'help': "Automatically installs the WordPress page compiler (either locally or in the new site) if required by other options.\nWarning: the compiler is GPL software!",
},
]
all_tags = set([])

def _find_wordpress_compiler(self):
for plugin_info in self.site.plugin_manager.getPluginsOfCategory('PageCompiler'):
if plugin_info.name == 'wordpress':
if not plugin_info.is_activated:
self.site.plugin_manager.activatePluginByName(plugin_info.name)
plugin_info.plugin_object.set_site(self.site)
self.wordpress_page_compiler = plugin_info.plugin_object
break

def _read_options(self, options, args):
options['filename'] = args.pop(0)

@@ -185,6 +216,8 @@ def _read_options(self, options, args):

self.transform_to_html = options.get('transform_to_html', False)
self.use_wordpress_compiler = options.get('use_wordpress_compiler', False)
self.install_wordpress_compiler = options.get('install_wordpress_compiler', False)
self.wordpress_page_compiler = None

self.auth = None
if options.get('download_auth') is not None:
@@ -200,26 +233,27 @@ def _read_options(self, options, args):
if self.transform_to_html and self.use_wordpress_compiler:
LOGGER.warn("It does not make sense to combine --transform-to-html with --use-wordpress-compiler, as the first converts all posts to HTML and the latter option affects zero posts.")

if self.use_wordpress_compiler:
LOGGER.warn("Make sure to install the WordPress page compiler via")
LOGGER.warn(" nikola plugin -i wordpress_compiler")
LOGGER.warn("in your imported blog's folder ({0}), if you haven't installed it system-wide or user-wide. Otherwise, your newly imported blog won't compile.".format(options['output_folder']))

if self.transform_to_html:
self.wordpress_page_compiler = None
for plugin_info in self.site.plugin_manager.getPluginsOfCategory('PageCompiler'):
if plugin_info.name == 'wordpress':
if not plugin_info.is_activated:
self.site.plugin_manager.activatePluginByName(plugin_info.name)
plugin_info.plugin_object.set_site(self.site)
self.wordpress_page_compiler = plugin_info.plugin_object
break
self._find_wordpress_compiler()
if not self.wordpress_page_compiler and self.install_wordpress_compiler:
if not install_plugin(self.site, 'wordpress_compiler', output_dir='plugins'): # local install
return False
self._find_wordpress_compiler()
if not self.wordpress_page_compiler:
LOGGER.error("To compile WordPress posts to HTML, the WordPress post compiler is needed. You can install it via:")
LOGGER.error(" nikola plugin -i wordpress_compiler")
LOGGER.error("Please note that the WordPress post compiler is licensed under the GPL v2.")
return False

if self.use_wordpress_compiler:
if self.install_wordpress_compiler:
if not install_plugin(self.site, 'wordpress_compiler', output_dir=os.path.join(self.output_folder, 'plugins')):
return False
else:
LOGGER.warn("Make sure to install the WordPress page compiler via")
LOGGER.warn(" nikola plugin -i wordpress_compiler")
LOGGER.warn("in your imported blog's folder ({0}), if you haven't installed it system-wide or user-wide. Otherwise, your newly imported blog won't compile.".format(self.output_folder))

return True

def _prepare(self, channel):
14 changes: 9 additions & 5 deletions nikola/plugins/command/plugin.py
Original file line number Diff line number Diff line change
@@ -137,17 +137,19 @@ def _execute(self, options, args):
self.output_dir = os.path.expanduser('~/.nikola/plugins')
else:
self.output_dir = 'plugins'
if options.get('output_dir') is not None:
self.output_dir = options.get('output_dir')

if list_available:
self.list_available(url)
return self.list_available(url)
elif list_installed:
self.list_installed()
return self.list_installed()
elif upgrade:
self.do_upgrade(url)
return self.do_upgrade(url)
elif uninstall:
self.do_uninstall(uninstall)
return self.do_uninstall(uninstall)
elif install:
self.do_install(url, install)
return self.do_install(url, install)

def list_available(self, url):
data = self.get_json(url)
@@ -170,6 +172,7 @@ def list_installed(self):
plugins.sort()
for name, path in plugins:
print('{0} at {1}'.format(name, path))
return True

def do_upgrade(self, url):
LOGGER.warning('This is not very smart, it just reinstalls some plugins and hopes for the best')
@@ -198,6 +201,7 @@ def do_upgrade(self, url):
else:
path = tail
self.do_install(url, name)
return True

def do_install(self, url, name):
data = self.get_json(url)