Пример #1
0
    def _execute(self, options, args):
        """Import a Blogger blog from an export file into a Nikola site."""
        # Parse the data
        if feedparser is None:
            req_missing(['feedparser'], 'import Blogger dumps')
            return

        if not args:
            print(self.help())
            return

        options['filename'] = args[0]
        self.blogger_export_file = options['filename']
        self.output_folder = options['output_folder']
        self.import_into_existing_site = False
        self.exclude_drafts = options['exclude_drafts']
        self.url_map = {}
        channel = self.get_channel_from_file(self.blogger_export_file)
        self.context = self.populate_context(channel)
        conf_template = self.generate_base_site()
        self.context['REDIRECTIONS'] = self.configure_redirections(
            self.url_map)

        self.import_posts(channel)
        self.write_urlmap_csv(
            os.path.join(self.output_folder, 'url_map.csv'), self.url_map)

        conf_out_path = self.get_configuration_output_path()
        # if it tracebacks here, look a comment in
        # basic_import.Import_Mixin.generate_base_site
        conf_template_render = conf_template.render(**prepare_config(self.context))
        self.write_configuration(conf_out_path, conf_template_render)
Пример #2
0
    def _write_site(self):
        context = SAMPLE_CONF.copy()

        context['DEFAULT_LANG'] = 'en'
        context['BLOG_TITLE'] = self._jekyll_config.get('title', 'EXAMPLE')

        context['BLOG_DESCRIPTION'] = self._jekyll_config.get('description') or ''
        context['SITE_URL'] = self._jekyll_config.get('url', 'EXAMPLE')
        context['BLOG_EMAIL'] = self._jekyll_config.get('email') or ''
        context['BLOG_AUTHOR'] = self._jekyll_config.get('author') or ''

        context['POSTS'] = """(
            ("posts/*.md", "blog", "post.tmpl"),
            ("posts/*.rst", "blog", "post.tmpl"),
            ("posts/*.txt", "blog", "post.tmpl"),
            ("posts/*.html", "blog", "post.tmpl"),
            )"""

        if 'disqus_short_name' in self._jekyll_config:
            context['COMMENT_SYSTEM'] = 'disqus'
            context['COMMENT_SYSTEM_ID'] = self._jekyll_config[
                'disqus_short_name']

        if self._jekyll_config.get('', False):
            context['PRETTY_URLS'] = True
            context['INDEXES_PRETTY_PAGE_URL'] = True

        conf_template = self.generate_base_site()
        conf_out_path = self.get_configuration_output_path()

        conf_template_render = conf_template.render(**prepare_config(context))
        self.write_configuration(conf_out_path, conf_template_render)
Пример #3
0
    def _execute(self, options, args):
        '''
            Import Atom/RSS feed
        '''
        if feedparser is None:
            req_missing(['feedparser'], 'import feeds')
            return

        if not options['url']:
            print(self.help())
            return

        self.feed_url = options['url']
        self.output_folder = options['output_folder']
        self.import_into_existing_site = False
        self.url_map = {}
        channel = self.get_channel_from_file(self.feed_url)
        self.context = self.populate_context(channel)
        conf_template = self.generate_base_site()
        self.context['REDIRECTIONS'] = self.configure_redirections(
            self.url_map)

        self.import_posts(channel)

        self.write_configuration(self.get_configuration_output_path(
        ), conf_template.render(**prepare_config(self.context)))
Пример #4
0
    def _write_site(self):
        context = SAMPLE_CONF.copy()

        context["DEFAULT_LANG"] = "en"
        context["BLOG_TITLE"] = self._jekyll_config.get("title", "EXAMPLE")

        context["BLOG_DESCRIPTION"] = self._jekyll_config.get("description") or ""
        context["SITE_URL"] = self._jekyll_config.get("url", "EXAMPLE")
        context["BLOG_EMAIL"] = self._jekyll_config.get("email") or ""
        context["BLOG_AUTHOR"] = self._jekyll_config.get("author") or ""

        context[
            "POSTS"
        ] = """(
            ("posts/*.md", "blog", "post.tmpl"),
            ("posts/*.rst", "blog", "post.tmpl"),
            ("posts/*.txt", "blog", "post.tmpl"),
            ("posts/*.html", "blog", "post.tmpl"),
            )"""

        if "disqus_short_name" in self._jekyll_config:
            context["COMMENT_SYSTEM"] = "disqus"
            context["COMMENT_SYSTEM_ID"] = self._jekyll_config["disqus_short_name"]

        if self._jekyll_config.get("", False):
            context["PRETTY_URLS"] = True
            context["INDEXES_PRETTY_PAGE_URL"] = True

        conf_template = self.generate_base_site()
        conf_out_path = self.get_configuration_output_path()

        conf_template_render = conf_template.render(**prepare_config(context))
        self.write_configuration(conf_out_path, conf_template_render)
Пример #5
0
    def _execute(self, options={}, args=[]):
        """Import a Tumblr blog into a Nikola site."""
        if not args:
            print(self.help())
            return

        options['site'] = 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.tumblr_url = options['site']
        self.output_folder = options.get('output_folder', 'new_site')

        self.no_downloads = options.get('no_downloads', False)

        if pytumblr is None:
            req_missing(['pytumblr'], 'import a Tumblr site.')

        if requests is None:
            req_missing(['requests'], 'import a Tumblr site.')

        # Get site data via Tumblr API
        self.client = pytumblr.TumblrRestClient(
            'iEAu2WLA7GjLSZ81Ie5ZJ0h8Jochj5TzFurxRP8a54vwBOVDcC',
            'D9UkKOO9zq9VmqfNKEBZG61bwv9TMZjA4P07BkB6Y35GCfUCdJ',
            'QEOkjGsWtT2kUPUpoh6tHFGjwoycHSd7Ypz6G8Pgz31NbHjFEy',
            'wan0Pd7VzESpdLDN0FYqReFOE7U1GG2X0GknOuKT3kpNUHwkBK'
        )

        # Name of the site to import is the first part of the URL
        self.site_name = urlparse(self.tumblr_url).netloc.split('.')[0]
        self.site_info = self.client.blog_info(self.site_name)['blog']
        self.context = self.populate_context(self.site_info)
        self.context['SITE_URL'] = self.tumblr_url
        conf_template = self.generate_base_site()
        # Importing here because otherwise doit complains
        from nikola.plugins.compile.html import CompileHtml
        self.html_compiler = CompileHtml()
        self.import_posts()

        rendered_template = conf_template.render(**prepare_config(self.context))
        rendered_template = rendered_template.replace("# PRETTY_URLS = False", "PRETTY_URLS = True")
        self.write_configuration(self.get_configuration_output_path(),
                                 rendered_template)
Пример #6
0
    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)
Пример #7
0
    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")

        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["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)
Пример #8
0
    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))
Пример #9
0
    def _execute(self, options, args):
        '''
            Import Google+ dump
        '''

        if not args:
            print(self.help())
            return

        if micawber is None:
            req_missing(['micawber'], 'import from Google+')

        options['filename'] = args[0]
        self.export_file = options['filename']
        self.output_folder = options['output_folder']
        self.import_into_existing_site = False
        self.url_map = {}

        with ZipFile(self.export_file, 'r') as zipfile:
            gplus_names = [x for x in zipfile.namelist() if '/Google+ Stream/' in x]
            self.context = self.populate_context(zipfile, gplus_names)
            conf_template = self.generate_base_site()
            self.write_configuration(self.get_configuration_output_path(), conf_template.render(**prepare_config(self.context)))
            self.import_posts(zipfile, gplus_names)
Пример #10
0
    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)