Пример #1
0
    def _should_skip(self, filename):
        """Determine if the file type should be skipped."""
        if filename.endswith(self.SKIP_EXTENSION):
            logger.debug(
                _('Skipping {filename} with skipped file type ...').format(
                    filename=filename))
            return True

        if filename.endswith(self.SKIP_FILES):
            logger.debug(_('Skipping special file {filename} ...').format(
                filename=filename))
            return True

        return False
Пример #2
0
    def _should_skip(self, filename):
        """Determine if the file type should be skipped."""
        if filename.endswith(self.SKIP_EXTENSION):
            logger.debug(
                _('Skipping {filename} with skipped file type ...').format(
                    filename=filename))
            return True

        if filename.endswith(self.SKIP_FILES):
            logger.debug(
                _('Skipping special file {filename} ...').format(
                    filename=filename))
            return True

        return False
Пример #3
0
    def compose(self, catalog, source_file, out_dir):
        root, ext = os.path.splitext(os.path.basename(source_file))
        filename = root + self.output_extension
        output_file = os.path.join(out_dir, filename)
        if self._needs_update(source_file, output_file):
            logger.info(_('Generating Atom XML for {source_file} ...').format(
                source_file=source_file))
            feed = self._parse_feed(source_file)

            with open(output_file, 'wb') as out:
                out.write(feed.to_string().encode('utf-8'))
                out.write(b'<!-- handrolled for excellence -->\n')
        else:
            logger.debug(_('Skipping {filename} ... It is up to date.').format(
                filename=filename))
Пример #4
0
 def compose(self, catalog, source_file, out_dir):
     filename = os.path.basename(source_file.rstrip('.j2'))
     output_file = os.path.join(out_dir, filename)
     if self._needs_update(source_file, output_file):
         logger.info(_('Generating from template {source_file} ...').format(
             source_file=source_file))
         data, source = self.get_data(source_file)
         data['config'] = self._config
         template = jinja2.Template(source)
         with open(output_file, 'wb') as out:
             out.write(template.render(data).encode('utf-8'))
             # Frontmatter loading seems to munch the final line separator.
             out.write(os.linesep.encode('utf-8'))
     else:
         logger.debug(_('Skipping {filename} ... It is up to date.').format(
             filename=filename))
Пример #5
0
    def compose(self, catalog, source_file, out_dir):
        root, ext = os.path.splitext(os.path.basename(source_file))
        filename = root + self.output_extension
        output_file = os.path.join(out_dir, filename)
        if self._needs_update(source_file, output_file):
            logger.info(
                _("Generating Atom XML for {source_file} ...").format(
                    source_file=source_file))
            feed = self._parse_feed(source_file)

            with open(output_file, "wb") as out:
                out.write(feed.to_string().encode("utf-8"))
                out.write(b"<!-- handrolled for excellence -->\n")
        else:
            logger.debug(
                _("Skipping {filename} ... It is up to date.").format(
                    filename=filename))
Пример #6
0
 def compose(self, catalog, source_file, out_dir):
     filename = os.path.basename(source_file.rstrip('.j2'))
     output_file = os.path.join(out_dir, filename)
     if self._needs_update(source_file, output_file):
         logger.info(
             _('Generating from template {source_file} ...').format(
                 source_file=source_file))
         data, source = self.get_data(source_file)
         data['config'] = self._config
         template = jinja2.Template(source)
         with open(output_file, 'wb') as out:
             out.write(template.render(data).encode('utf-8'))
             # Frontmatter loading seems to munch the final line separator.
             out.write(os.linesep.encode('utf-8'))
     else:
         logger.debug(
             _('Skipping {filename} ... It is up to date.').format(
                 filename=filename))
Пример #7
0
    def compose(self, catalog, source_file, out_dir):
        root, ext = os.path.splitext(os.path.basename(source_file))
        filename = root + self.output_extension
        output_file = os.path.join(out_dir, filename)

        logger.info(_('Generating CSS for {source_file} ...').format(
            source_file=source_file))

        command = self.build_command(source_file, output_file)
        process = subprocess.Popen(
            command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        (out, err) = process.communicate()

        if out:
            logger.debug(_('Received output from sass:\n{0}'.format(out)))

        if process.returncode != 0:
            raise AbortError(_('Sass failed to generate CSS:\n{0}').format(
                err))
Пример #8
0
    def compose(self, catalog, source_file, out_dir):
        """Compose an HTML document by generating HTML from the source
        file, merging it with a template, and write the result to output
        directory."""
        data, source = self.get_data(source_file)

        template = self.select_template(catalog, data)

        # Determine the output filename.
        root, ext = os.path.splitext(os.path.basename(source_file))
        filename = root + self.output_extension
        output_file = os.path.join(out_dir, filename)

        if self._needs_update(template, source_file, output_file):
            logger.info(_('Generating HTML for {source_file} ...').format(
                source_file=source_file))
            data['content'] = self._generate_content(source)
            self._render_to_output(template, data, output_file)
        else:
            logger.debug(_('Skipping {filename} ... It is up to date.').format(
                filename=filename))
Пример #9
0
    def compose(self, catalog, source_file, out_dir):
        root, ext = os.path.splitext(os.path.basename(source_file))
        filename = root + self.output_extension
        output_file = os.path.join(out_dir, filename)

        logger.info(
            _('Generating CSS for {source_file} ...').format(
                source_file=source_file))

        command = self.build_command(source_file, output_file)
        process = subprocess.Popen(command,
                                   stdin=subprocess.PIPE,
                                   stdout=subprocess.PIPE)
        (out, err) = process.communicate()

        if out:
            logger.debug(_('Received output from sass:\n{0}'.format(out)))

        if process.returncode != 0:
            raise AbortError(
                _('Sass failed to generate CSS:\n{0}').format(err))
Пример #10
0
    def compose(self, catalog, source_file, out_dir):
        """Copy a file to the destination if the file does not exist or was
        modified."""
        filename = os.path.basename(source_file)
        # Do not copy files that are already there unless different.
        destination = os.path.join(out_dir, filename)
        if os.path.exists(destination):
            if filecmp.cmp(source_file, destination):
                # Files are equal. Do nothing.
                logger.debug(_('Skipping {filename} ... It is the same as '
                               '{destination}.').format(
                    filename=filename, destination=destination))
                return
            else:
                logger.info(
                    _('{filename} differs from {destination} ...').format(
                        filename=filename, destination=destination))

        logger.info(_('Copying {filename} to {out_dir} ...').format(
            filename=filename, out_dir=out_dir))
        shutil.copy(source_file, out_dir)
Пример #11
0
    def compose(self, catalog, source_file, out_dir):
        """Compose an HTML document by generating HTML from the source
        file, merging it with a template, and write the result to output
        directory."""
        data, source = self.get_data(source_file)

        template = self.select_template(catalog, data)

        # Determine the output filename.
        root, ext = os.path.splitext(os.path.basename(source_file))
        filename = root + self.output_extension
        output_file = os.path.join(out_dir, filename)

        if self._needs_update(template, source_file, output_file):
            logger.info(
                _('Generating HTML for {source_file} ...').format(
                    source_file=source_file))
            data['content'] = self._generate_content(source)
            self._render_to_output(template, data, output_file)
        else:
            logger.debug(
                _('Skipping {filename} ... It is up to date.').format(
                    filename=filename))
Пример #12
0
    def compose(self, catalog, source_file, out_dir):
        """Copy a file to the destination if the file does not exist or was
        modified."""
        filename = os.path.basename(source_file)
        # Do not copy files that are already there unless different.
        destination = os.path.join(out_dir, filename)
        if os.path.exists(destination):
            if (
                not self._config.force and
                filecmp.cmp(source_file, destination)
            ):
                # Files are equal. Do nothing.
                logger.debug(_('Skipping {filename} ... It is the same as '
                               '{destination}.').format(
                    filename=filename, destination=destination))
                return
            else:
                logger.info(
                    _('{filename} differs from {destination} ...').format(
                        filename=filename, destination=destination))

        logger.info(_('Copying {filename} to {out_dir} ...').format(
            filename=filename, out_dir=out_dir))
        shutil.copy(source_file, out_dir)