Пример #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 _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)
Пример #5
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)
Пример #6
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)))
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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))
Пример #13
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)
Пример #14
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)
Пример #15
0
    def _execute(self, options, args):
        '''
            Import Google+ dump
        '''

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

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

        # Google Takeout folder structure, adapt to your language settings

        # Takeout/
        # ├── +1/
        # ├── Google+ stream/
        # |   ├── Posts/
        # |   ├── Photos/
        # |   |   ├── Photos of posts/
        # |   |   └── Photos of polls/
        # |   ├── Activities/
        # |   ├── Collections/
        # |   └── Events/
        # ├── Google+ Communities/
        # └── index.html

        gto_root = "Takeout"
        gto_plus1 = "+1"
        gto_stream = "Stream in Google+"
        gto_posts = "Beiträge"
        gto_photos = "Fotos"
        gto_photos_posts = "Fotos von Beiträgen"
        gto_photos_polls = "Umfragefotos"
        gto_activity = "Aktivitätsprotokoll"
        gto_collections = "Sammlungen"
        gto_events = "Veranstaltungen"
        gto_communities = "Google+ Communities"

        # path to HTML formatted post files
        post_path = os.path.join(self.export_folder, gto_root, gto_stream,
                                 gto_posts)

        # collect all files
        files = [
            f for f in os.listdir(os.path.join(post_path))
            if os.path.isfile(os.path.join(post_path, f))
        ]

        # filter relevant HTML files
        html_files = [f for f in files if f.endswith(".html")]
        LOGGER.info("{} posts ready for import".format(len(html_files)))

        # init new Nikola site "new_site", edit conf.py to your needs
        # change to this folder for the for build process
        self.context = self.populate_context(self.export_folder, html_files,
                                             post_path)
        conf_template = self.generate_base_site()
        self.write_configuration(
            self.get_configuration_output_path(),
            conf_template.render(**prepare_config(self.context)))
        self.import_posts(self.export_folder, html_files, post_path)

        # In the Takeout archive photos are linked to the main working
        # directory although they do not necessarily exist there (Hello
        # deadlinks!). The image files are spread to several folders.

        # All archive photos will be copied to the "images" folder.
        try:
            os.makedirs(os.path.join(self.output_folder, "images"))
            LOGGER.info("Image folder ceated.")
        except:
            pass

        for root, dirs, files in os.walk(
                os.path.join(self.export_folder, gto_root)):
            for f in files:
                if f.lower().endswith(".jpg") or f.lower().endswith(
                        ".jpeg") or f.lower().endswith(".png"):
                    if not os.path.isfile(
                            os.path.join(self.output_folder, "images", f)):
                        shutil.copy2(
                            os.path.join(root, f),
                            os.path.join(self.output_folder, "images"))
                        LOGGER.info(
                            "{} copied to Nikola image folder.".format(f))
Пример #16
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)
Пример #17
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)
        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)
Пример #18
0
    def _execute(self, options, args):
        """
            Import Google+ dump
        """

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

        options["foldername"] = args[0]
        self.export_folder = os.path.join(options["foldername"], "Takeout")
        self.output_folder = options["output_folder"]
        self.import_into_existing_site = False
        self.url_map = {}

        with open(os.path.join("plugins", "import_gplus_html",
                               "config.yaml")) as f:
            self.config = yaml.load(f)

        # path to post files
        post_path = os.path.join(
            self.export_folder,
            self.config["gto"]["stream"],
            self.config["gto"]["posts"],
        )

        # collect all files
        files = [
            f for f in os.listdir(os.path.join(post_path))
            if os.path.isfile(os.path.join(post_path, f))
        ]

        src_files = [f for f in files if f.endswith(".html")]
        if len(src_files) == 0:
            LOGGER.warning("""No HTML files found. Possible reasons:
    1) you pointed to the wrong folder
    2) you selected the wrong file format
    3) there may be (spelling) errors in the configuration file""")
            sys.exit(1)
        else:
            LOGGER.info("{} HTML formatted posts ready for import".format(
                len(src_files)))

        if options["show_statuses"]:
            self.analyze_share(post_path, src_files)
            sys.exit(0)

        # init new site
        conf_template = self.generate_base_site()
        # image handling, preparations for build process
        # copy all images to the Nikola 'images' folder
        self.prepare_media(self.export_folder)
        # mark images with a horizontal text line
        if self.config["image"]["watermark"]:
            if self.config["image"]["watermark_text"] == None or \
                        self.config["image"]["watermark_text"] == "":
                LOGGER.warning("The watermark text must not be empty.")
            else:
                self.watermark_media(
                    self.output_folder,
                    self.config["image"]["watermark_text"],
                )

        self.context = self.populate_context(
            src_files,
            post_path,
            self.config,
        )
        self.write_configuration(
            self.get_configuration_output_path(),
            conf_template.render(**prepare_config(self.context)))
        self.import_posts(
            src_files,
            post_path,
            self.config,
        )