def test_configure_translations_with_2_additional_languages(self): """ Testing the configuration of the translation when no additional language has been found. """ translations_cfg = format_default_translations_config( set(["es", "en"])) self.assertEqual("""{ DEFAULT_LANG: "", "en": "./en", "es": "./es", }""", translations_cfg)
def _execute(self, options={}, args=[]): """Import a WordPress blog from an export file into a Nikola site.""" if not args: print(self.help()) return options['filename'] = args.pop(0) if args and ('output_folder' not in args or options['output_folder'] == 'new_site'): options['output_folder'] = args.pop(0) if args: LOGGER.warn( 'You specified additional arguments ({0}). Please consider ' 'putting these arguments before the filename if you ' 'are running into problems.'.format(args)) self.import_into_existing_site = False self.url_map = {} self.timezone = None self.wordpress_export_file = options['filename'] self.squash_newlines = options.get('squash_newlines', False) self.output_folder = options.get('output_folder', 'new_site') self.exclude_drafts = options.get('exclude_drafts', False) self.no_downloads = options.get('no_downloads', False) self.separate_qtranslate_content = options.get( 'separate_qtranslate_content') self.translations_pattern = options.get('translations_pattern') # A place holder where extra language (if detected) will be stored self.extra_languages = set() if not self.no_downloads: def show_info_about_mising_module(modulename): LOGGER.error( 'To use the "{commandname}" command, you have to install ' 'the "{package}" package or supply the "--no-downloads" ' 'option.'.format(commandname=self.name, package=modulename)) if requests is None and phpserialize is None: req_missing(['requests', 'phpserialize'], 'import WordPress dumps without --no-downloads') elif requests is None: req_missing(['requests'], 'import WordPress dumps without --no-downloads') elif phpserialize is None: req_missing(['phpserialize'], 'import WordPress dumps without --no-downloads') channel = self.get_channel_from_file(self.wordpress_export_file) self.context = self.populate_context(channel) self.base_dir = urlparse(self.context['BASE_URL']).path conf_template = self.generate_base_site() # If user has specified a custom pattern for translation files we # need to fix the config if self.translations_pattern: self.context['TRANSLATIONS_PATTERN'] = self.translations_pattern self.import_posts(channel) self.context['TRANSLATIONS'] = format_default_translations_config( self.extra_languages) self.context['REDIRECTIONS'] = self.configure_redirections( self.url_map) self.write_urlmap_csv(os.path.join(self.output_folder, 'url_map.csv'), self.url_map) rendered_template = conf_template.render( **prepare_config(self.context)) rendered_template = re.sub('# REDIRECTIONS = ', 'REDIRECTIONS = ', rendered_template) if self.timezone: rendered_template = re.sub('# TIMEZONE = \'UTC\'', 'TIMEZONE = \'' + self.timezone + '\'', rendered_template) self.write_configuration(self.get_configuration_output_path(), rendered_template)
def test_configure_translations_without_additional_languages(self): """ Testing the configuration of the translation when no additional language has been found. """ translations_cfg = format_default_translations_config(set()) self.assertEqual(SAMPLE_CONF["TRANSLATIONS"], translations_cfg)
def _execute(self, options={}, args=[]): """Import a WordPress blog from an export file into a Nikola site.""" if not args: print(self.help()) return options['filename'] = args.pop(0) if args and ('output_folder' not in args or options['output_folder'] == 'new_site'): options['output_folder'] = args.pop(0) if args: LOGGER.warn('You specified additional arguments ({0}). Please consider ' 'putting these arguments before the filename if you ' 'are running into problems.'.format(args)) self.import_into_existing_site = False self.url_map = {} self.timezone = None self.wordpress_export_file = options['filename'] self.squash_newlines = options.get('squash_newlines', False) self.output_folder = options.get('output_folder', 'new_site') self.exclude_drafts = options.get('exclude_drafts', False) self.no_downloads = options.get('no_downloads', False) self.separate_qtranslate_content = options.get('separate_qtranslate_content') self.translations_pattern = options.get('translations_pattern') # A place holder where extra language (if detected) will be stored self.extra_languages = set() if not self.no_downloads: def show_info_about_mising_module(modulename): LOGGER.error( 'To use the "{commandname}" command, you have to install ' 'the "{package}" package or supply the "--no-downloads" ' 'option.'.format( commandname=self.name, package=modulename) ) if requests is None and phpserialize is None: req_missing(['requests', 'phpserialize'], 'import WordPress dumps without --no-downloads') elif requests is None: req_missing(['requests'], 'import WordPress dumps without --no-downloads') elif phpserialize is None: req_missing(['phpserialize'], 'import WordPress dumps without --no-downloads') channel = self.get_channel_from_file(self.wordpress_export_file) self.context = self.populate_context(channel) conf_template = self.generate_base_site() # If user has specified a custom pattern for translation files we # need to fix the config if self.translations_pattern: self.context['TRANSLATIONS_PATTERN'] = self.translations_pattern self.import_posts(channel) self.context['TRANSLATIONS'] = format_default_translations_config( self.extra_languages) self.context['REDIRECTIONS'] = self.configure_redirections( self.url_map) self.write_urlmap_csv( os.path.join(self.output_folder, 'url_map.csv'), self.url_map) rendered_template = conf_template.render(**prepare_config(self.context)) rendered_template = re.sub('# REDIRECTIONS = ', 'REDIRECTIONS = ', rendered_template) if self.timezone: rendered_template = re.sub('# TIMEZONE = \'UTC\'', 'TIMEZONE = \'' + self.timezone + '\'', rendered_template) self.write_configuration(self.get_configuration_output_path(), rendered_template)
def _execute(self, options={}, args=[]): """Import a WordPress blog from an export file into a Nikola site.""" if not args: print(self.help()) return False if not self._read_options(options, args): return False # A place holder where extra language (if detected) will be stored self.extra_languages = set() if not self.no_downloads: def show_info_about_mising_module(modulename): LOGGER.error( 'To use the "{commandname}" command, you have to install ' 'the "{package}" package or supply the "--no-downloads" ' 'option.'.format( commandname=self.name, package=modulename) ) if phpserialize is None: req_missing(['phpserialize'], 'import WordPress dumps without --no-downloads') channel = self.get_channel_from_file(self.wordpress_export_file) self._prepare(channel) conf_template = self.generate_base_site() # If user has specified a custom pattern for translation files we # need to fix the config if self.translations_pattern: self.context['TRANSLATIONS_PATTERN'] = self.translations_pattern self.import_posts(channel) self.context['TRANSLATIONS'] = format_default_translations_config( self.extra_languages) self.context['REDIRECTIONS'] = self.configure_redirections( self.url_map) if self.timezone: self.context['TIMEZONE'] = self.timezone if self.export_categories_as_categories: self.context['CATEGORY_ALLOW_HIERARCHIES'] = True self.context['CATEGORY_OUTPUT_FLAT_HIERARCHY'] = True # Add tag redirects for tag in self.all_tags: try: tag_str = tag.decode('utf8') except AttributeError: tag_str = tag tag = utils.slugify(tag_str) src_url = '{}tag/{}'.format(self.context['SITE_URL'], tag) dst_url = self.site.link('tag', tag) if src_url != dst_url: self.url_map[src_url] = dst_url self.write_urlmap_csv( os.path.join(self.output_folder, 'url_map.csv'), self.url_map) rendered_template = conf_template.render(**prepare_config(self.context)) self.write_configuration(self.get_configuration_output_path(), rendered_template) 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))
def test_configure_translations_with_2_additional_languages(): """ Testing the configuration of the translation when two additional languages are given. """ translations_cfg = format_default_translations_config(set(["es", "en"])) assert translations_cfg == """{
def _execute(self, options={}, args=[]): """Import a WordPress blog from an export file into a Nikola site.""" if not args: print(self.help()) return options["filename"] = args.pop(0) if args and ("output_folder" not in args or options["output_folder"] == "new_site"): options["output_folder"] = args.pop(0) if args: LOGGER.warn( "You specified additional arguments ({0}). Please consider " "putting these arguments before the filename if you " "are running into problems.".format(args) ) self.import_into_existing_site = False self.url_map = {} self.timezone = None self.wordpress_export_file = options["filename"] self.squash_newlines = options.get("squash_newlines", False) self.output_folder = options.get("output_folder", "new_site") self.exclude_drafts = options.get("exclude_drafts", False) self.no_downloads = options.get("no_downloads", False) self.separate_qtranslate_content = options.get("separate_qtranslate_content") self.translations_pattern = options.get("translations_pattern") # A place holder where extra language (if detected) will be stored self.extra_languages = set() if not self.no_downloads: def show_info_about_mising_module(modulename): LOGGER.error( 'To use the "{commandname}" command, you have to install ' 'the "{package}" package or supply the "--no-downloads" ' "option.".format(commandname=self.name, package=modulename) ) if requests is None and phpserialize is None: req_missing(["requests", "phpserialize"], "import WordPress dumps without --no-downloads") elif requests is None: req_missing(["requests"], "import WordPress dumps without --no-downloads") elif phpserialize is None: req_missing(["phpserialize"], "import WordPress dumps without --no-downloads") channel = self.get_channel_from_file(self.wordpress_export_file) self.context = self.populate_context(channel) self.base_dir = urlparse(self.context["BASE_URL"]).path conf_template = self.generate_base_site() # If user has specified a custom pattern for translation files we # need to fix the config if self.translations_pattern: self.context["TRANSLATIONS_PATTERN"] = self.translations_pattern self.import_posts(channel) self.context["TRANSLATIONS"] = format_default_translations_config(self.extra_languages) self.context["REDIRECTIONS"] = self.configure_redirections(self.url_map) self.write_urlmap_csv(os.path.join(self.output_folder, "url_map.csv"), self.url_map) rendered_template = conf_template.render(**prepare_config(self.context)) rendered_template = re.sub("# REDIRECTIONS = ", "REDIRECTIONS = ", rendered_template) if self.timezone: rendered_template = re.sub("# TIMEZONE = 'UTC'", "TIMEZONE = '" + self.timezone + "'", rendered_template) self.write_configuration(self.get_configuration_output_path(), rendered_template)
def _execute(self, options={}, args=[]): """Import a WordPress blog from an export file into a Nikola site.""" if not args: print(self.help()) return options['filename'] = args.pop(0) if args and ('output_folder' not in args or options['output_folder'] == 'new_site'): options['output_folder'] = args.pop(0) if args: LOGGER.warn('You specified additional arguments ({0}). Please consider ' 'putting these arguments before the filename if you ' 'are running into problems.'.format(args)) self.import_into_existing_site = False self.url_map = {} self.timezone = None self.wordpress_export_file = options['filename'] self.squash_newlines = options.get('squash_newlines', False) self.output_folder = options.get('output_folder', 'new_site') self.exclude_drafts = options.get('exclude_drafts', False) self.no_downloads = options.get('no_downloads', False) self.auth = None if options.get('download_auth') is not None: username_password = options.get('download_auth') self.auth = tuple(username_password.split(':', 1)) if len(self.auth) < 2: print("Please specify HTTP authentication credentials in the form username:password.") return False self.separate_qtranslate_content = options.get('separate_qtranslate_content') self.translations_pattern = options.get('translations_pattern') # A place holder where extra language (if detected) will be stored self.extra_languages = set() if not self.no_downloads: def show_info_about_mising_module(modulename): LOGGER.error( 'To use the "{commandname}" command, you have to install ' 'the "{package}" package or supply the "--no-downloads" ' 'option.'.format( commandname=self.name, package=modulename) ) if phpserialize is None: req_missing(['phpserialize'], 'import WordPress dumps without --no-downloads') channel = self.get_channel_from_file(self.wordpress_export_file) self.context = self.populate_context(channel) self.base_dir = urlparse(self.context['BASE_URL']).path conf_template = self.generate_base_site() # If user has specified a custom pattern for translation files we # need to fix the config if self.translations_pattern: self.context['TRANSLATIONS_PATTERN'] = self.translations_pattern self.import_posts(channel) self.context['TRANSLATIONS'] = format_default_translations_config( self.extra_languages) self.context['REDIRECTIONS'] = self.configure_redirections( self.url_map) # Add tag redirects for tag in self.all_tags: try: tag_str = tag.decode('utf8') except AttributeError: tag_str = tag tag = utils.slugify(tag_str) src_url = '{}tag/{}'.format(self.context['SITE_URL'], tag) dst_url = self.site.link('tag', tag) if src_url != dst_url: self.url_map[src_url] = dst_url self.write_urlmap_csv( os.path.join(self.output_folder, 'url_map.csv'), self.url_map) rendered_template = conf_template.render(**prepare_config(self.context)) rendered_template = re.sub('# REDIRECTIONS = ', 'REDIRECTIONS = ', rendered_template) if self.timezone: rendered_template = re.sub('# TIMEZONE = \'UTC\'', 'TIMEZONE = \'' + self.timezone + '\'', rendered_template) self.write_configuration(self.get_configuration_output_path(), rendered_template)