Exemplo n.º 1
0
 def crawl(node, destinations_so_far, root=True):
     if node.post_source is not None:
         try:
             post = Post(
                 node.post_source,
                 self.site.config,
                 '',
                 False,
                 self.site.MESSAGES,
                 template_name,
                 self.site.get_compiler(node.post_source),
                 destination_base=utils.TranslatableSetting('destinations', destinations_so_far, self.site.config['TRANSLATIONS']),
                 metadata_extractors_by=self.site.metadata_extractors_by
             )
             timeline.append(post)
         except Exception as err:
             LOGGER.error('Error reading post {}'.format(base_path))
             raise err
         # Compute slugs
         slugs = {}
         for lang in self.site.config['TRANSLATIONS']:
             slug = post.meta('slug', lang=lang)
             if slug:
                 slugs[lang] = slug
         if not slugs:
             slugs[self.site.config['DEFAULT_LANG']] = node.name
         node.slugs = _spread(slugs, self.site.config['TRANSLATIONS'], self.site.config['DEFAULT_LANG'])
     # Update destinations_so_far
     if not root:
         if node.slugs is not None:
             destinations_so_far = {lang: os.path.join(dest, node.slugs[lang]) for lang, dest in destinations_so_far.items()}
         else:
             destinations_so_far = {lang: os.path.join(dest, node.name) for lang, dest in destinations_so_far.items()}
     for p, n in node.children.items():
         crawl(n, destinations_so_far, root=False)
 def crawl(node, destinations_so_far, root=True):
     if node.post_source is not None:
         try:
             post = Post(node.post_source,
                         self.site.config,
                         '',
                         False,
                         self.site.MESSAGES,
                         template_name,
                         self.site.get_compiler(node.post_source),
                         destination_base=utils.TranslatableSetting(
                             'destinations', destinations_so_far,
                             self.site.config['TRANSLATIONS']),
                         metadata_extractors_by=self.site.
                         metadata_extractors_by)
             timeline.append(post)
         except Exception as err:
             LOGGER.error('Error reading post {}'.format(base_path))
             raise err
         # Compute slugs
         slugs = {}
         for lang in self.site.config['TRANSLATIONS']:
             slug = post.meta('slug', lang=lang)
             if slug:
                 slugs[lang] = slug
         if not slugs:
             slugs[self.site.config['DEFAULT_LANG']] = node.name
         node.slugs = _spread(slugs,
                              self.site.config['TRANSLATIONS'],
                              self.site.config['DEFAULT_LANG'])
     # Update destinations_so_far
     if not root:
         if node.slugs is not None:
             destinations_so_far = {
                 lang: os.path.join(dest, node.slugs[lang])
                 for lang, dest in destinations_so_far.items()
             }
         else:
             destinations_so_far = {
                 lang: os.path.join(dest, node.name)
                 for lang, dest in destinations_so_far.items()
             }
     for p, n in node.children.items():
         crawl(n, destinations_so_far, root=False)
Exemplo n.º 3
0
    def scan(self):
        """Scan posts in a package index."""
        if 'PKGINDEX_CONFIG' not in self.site.config:
            return []
        config = self.site.config['PKGINDEX_CONFIG']
        compiler = self.site.get_compiler('sample' + config['extension'])
        if not self.site.quiet:
            print("Scanning package index posts...", end='', file=sys.stderr)
        timeline = []
        self.site.pkgindex_entries = {}
        self.site.pkgindex_by_name = {}
        self.site.pkgindex_multiver = {}
        for topdir, dirsettings in self.site.config['PKGINDEX_DIRS'].items():
            destination, template_name = dirsettings
            self.site.pkgindex_entries[topdir] = []
            for pkgdir in glob.glob(topdir + "/*"):
                if not os.path.isdir(pkgdir):
                    # Ignore non-directories
                    continue
                post = Post(os.path.join(pkgdir, 'README.md'),
                            self.site.config, destination, False,
                            self.site.MESSAGES, template_name, compiler)
                post.is_two_file = True
                for d in post.meta.values():
                    d['is_special_entry'] = False
                timeline.append(post)
                self.site.pkgindex_entries[topdir].append(post)
                self._update_name_multiver(post)

        if 'special_entries' in config:
            for source_path, destination, template_name, topdir in config[
                    'special_entries']:
                post = Post(source_path, self.site.config, destination, False,
                            self.site.MESSAGES, template_name, compiler)
                post.is_two_file = True
                for d in post.meta.values():
                    d['is_special_entry'] = True
                timeline.append(post)
                self.site.pkgindex_entries[topdir].append(post)
                self._update_name_multiver(post)

        # But wait, we need to change tags on multiver stuff!
        # This is kinda... hacky...
        maxver = config['versions_supported'][-1]
        for versions in self.site.pkgindex_multiver.values():
            versions = sorted(versions, key=lambda post: post.meta('dirver'))
            v2p = {}
            for post in versions:
                dirver = post.meta('dirver')
                for v in range(dirver, maxver + 1):
                    v2p[v] = post

            p2v = {}
            for v, p in v2p.items():
                if p in p2v:
                    p2v[p].append(v)
                else:
                    p2v[p] = [v]

            for post, versions in p2v.items():
                # And finally, update tags.
                tags = post._tags[self.site.default_lang]
                tags = [
                    i for i in tags
                    if not (i.startswith('v') and i[1:].isdigit())
                ]
                tags += ['v{0}'.format(i) for i in versions]
                tags.append('multiver')
                post._tags[self.site.default_lang] = tags
                post.meta['en']['tags'] = tags
                post.meta['en']['multiver'] = True
                post.meta['en']['allver'] = versions
                if not post.meta['en']['maxver'] and versions[-1] != maxver:
                    post.meta['en']['maxver'] = versions[-1]

        # And generate self.site.pkgindex_by_version
        self.site.pkgindex_by_version = {
            i: []
            for i in config['versions_supported']
        }
        for l in self.site.pkgindex_entries.values():
            for post in l:
                for version in post.meta['en']['allver']:
                    self.site.pkgindex_by_version[version] = post

        return timeline
Exemplo n.º 4
0
    def scan(self):
        """Scan posts in a package index."""
        if 'PKGINDEX_CONFIG' not in self.site.config:
            return []
        config = self.site.config['PKGINDEX_CONFIG']
        compiler = self.site.get_compiler('sample' + config['extension'])
        if not self.site.quiet:
            print("Scanning package index posts...", end='', file=sys.stderr)
        timeline = []
        self.site.pkgindex_entries = {}
        self.site.pkgindex_by_name = {}
        self.site.pkgindex_multiver = {}
        for topdir, dirsettings in self.site.config['PKGINDEX_DIRS'].items():
            destination, template_name = dirsettings
            self.site.pkgindex_entries[topdir] = []
            for pkgdir in glob.glob(topdir + "/*"):
                if not os.path.isdir(pkgdir):
                    # Ignore non-directories
                    continue
                post = Post(
                    os.path.join(pkgdir, 'README.md'),
                    self.site.config,
                    destination,
                    False,
                    self.site.MESSAGES,
                    template_name,
                    compiler
                )
                post.is_two_file = True
                for d in post.meta.values():
                    d['is_special_entry'] = False
                timeline.append(post)
                self.site.pkgindex_entries[topdir].append(post)
                self._update_name_multiver(post)

        if 'special_entries' in config:
            for source_path, destination, template_name, topdir in config['special_entries']:
                post = Post(
                    source_path,
                    self.site.config,
                    destination,
                    False,
                    self.site.MESSAGES,
                    template_name,
                    compiler
                )
                post.is_two_file = True
                for d in post.meta.values():
                    d['is_special_entry'] = True
                timeline.append(post)
                self.site.pkgindex_entries[topdir].append(post)
                self._update_name_multiver(post)

        # But wait, we need to change tags on multiver stuff!
        # This is kinda... hacky...
        maxver = config['versions_supported'][-1]
        for versions in self.site.pkgindex_multiver.values():
            versions = sorted(versions, key=lambda post: post.meta('dirver'))
            v2p = {}
            for post in versions:
                dirver = post.meta('dirver')
                for v in range(dirver, maxver + 1):
                    v2p[v] = post

            p2v = {}
            for v, p in v2p.items():
                if p in p2v:
                    p2v[p].append(v)
                else:
                    p2v[p] = [v]

            for post, versions in p2v.items():
                # And finally, update tags.
                tags = post._tags[self.site.default_lang]
                tags = [i for i in tags if not (i.startswith('v') and i[1:].isdigit())]
                tags += ['v{0}'.format(i) for i in versions]
                tags.append('multiver')
                post._tags[self.site.default_lang] = tags
                post.meta['en']['tags'] = tags
                post.meta['en']['multiver'] = True
                post.meta['en']['allver'] = versions
                if not post.meta['en']['maxver'] and versions[-1] != maxver:
                    post.meta['en']['maxver'] = versions[-1]

        # And generate self.site.pkgindex_by_version
        self.site.pkgindex_by_version = {i: [] for i in config['versions_supported']}
        for l in self.site.pkgindex_entries.values():
            for post in l:
                for version in post.meta['en']['allver']:
                    self.site.pkgindex_by_version[version] = post

        return timeline