Ejemplo n.º 1
0
    def html(self):
        bullets = set([bullet for bullet, _ in self.contents])
        n_bullets = len(bullets)

        if not n_bullets:
            return ""
        elif n_bullets == 1 and len(list(bullets)[0]) < 2:
            ul_tpl = load_template('ul')
            li_tpl = load_template('li')

            out = [
                li_tpl.substitute(content=items.html())
                for _, items in self.contents
            ]

            return ul_tpl.substitute(content=''.join(out))
            # UL
        else:
            dtdd_tpl = load_template('dtdd')
            dl_tpl = load_template('dl')

            out = []
            for bullet, items in self.contents:
                out.append(
                    dtdd_tpl.substitute(bullet=bullet, content=items.html()))

            return dl_tpl.substitute(content=''.join(out))
Ejemplo n.º 2
0
    def html(self):
        content = super(Manpage, self).html()

        if self.url and self.package:
            twitter_headers = load_template('twitter-card').substitute(
                title="%s (%s) manual" % (
                    self.name,
                    self.section,
                ),
                description=self.title,
                image_url=self.image_url,
            )

            og_headers = load_template('og-card').substitute(
                title="%s (%s) manual" % (
                    self.name,
                    self.section,
                ),
                description=self.title,
                url=self.url,
                image_url=self.image_url,
            )

            extraheaders = twitter_headers + og_headers
        else:
            extraheaders = ""

        return load_template('base').substitute(
            breadcrumb=self.breadcrumbs,
            title=self.descriptive_title,
            extraheaders=extraheaders,
            metadescription=self.title,
            header=self.page_header,
            content=content + self.pager_contents,
        )
Ejemplo n.º 3
0
    def generate_manpage_sitemap_index(self, urls):
        sitemap_index_url_tpl = load_template('sitemap-index-url')
        urls = [sitemap_index_url_tpl.substitute(url=url) for url in urls]
        content = load_template('sitemap-index').substitute(
            sitemaps=''.join(urls))

        f = open(pjoin(self.manpages_dir, "sitemap.xml"), 'w')
        f.write(content)
        f.close()
Ejemplo n.º 4
0
    def html(self):
        dtdd_tpl = load_template('dtdd')
        dl_tpl = load_template('dl')

        out = [
            dtdd_tpl.substitute(bullet=bullets.html(), content=items.html())
            for bullets, items in self.contents
        ]
        return dl_tpl.substitute(content=''.join(out))
Ejemplo n.º 5
0
    def generate_manpage_sitemaps(self):
        query = """SELECT name,
                          section,
                          count(package) as amount,
                          group_concat(package) as packages,
                          file
                   FROM manpages
                   GROUP by name, section
                   ORDER by section ASC, name ASC"""

        pages_in_section = defaultdict(set)
        for name, section, amount, packages, file in self.conn.execute(query):
            if amount > 1:
                packages = packages.split(',')
                for package in packages:
                    page = "%s-%s.%s.html" % (
                        package,
                        name,
                        section,
                    )
                    pages_in_section["man%s" % section[0]].add(page)
            else:
                page = "%s.%s.html" % (
                    name,
                    section,
                )
                pages_in_section["man%s" % section[0]].add(page)

        sm_item_tpl = load_template('sitemap-url-nolastmod')

        sitemap_urls = []
        for section in SECTIONS:
            urls = [
                sm_item_tpl.substitute(url="%s/%s/%s" %
                                       (self.manpages_url, section, page))
                for page in pages_in_section[section]
            ]
            urls.append(
                sm_item_tpl.substitute(url="%s/%s/" % (
                    self.manpages_url,
                    section,
                )))
            sitemap = load_template('sitemap').substitute(
                urlset="\n".join(urls))
            rel_sitemap_path = pjoin(section, "sitemap.xml")

            f = open(pjoin(self.manpages_dir, rel_sitemap_path), 'w')
            f.write(sitemap)
            f.close()

            sitemap_urls.append("%s/%s" %
                                (self.manpages_url, rel_sitemap_path))

        return sitemap_urls
Ejemplo n.º 6
0
    def generate_sitemap_indexes(sm_urls):
        # Generate sitemap indexes
        sitemap_index_url_tpl = load_template('sitemap-index-url')
        sitemap_index_content = ""
        for sitemap_url in sm_urls:
            sitemap_index_content += sitemap_index_url_tpl.substitute(
                url=sitemap_url)

        sitemap_index_tpl = load_template('sitemap-index')
        sitemap_index_content = sitemap_index_tpl.substitute(
            sitemaps=sitemap_index_content)

        f = open(pjoin(base_manpage_dir, "sitemap.xml"), 'w')
        f.write(sitemap_index_content)
        f.close()
Ejemplo n.º 7
0
    def html(self):
        p_tpl = load_template('p')
        out = []
        strings = []
        for item in self.contents:
            if isinstance(item, str):
                if not item:
                    if strings:
                        content = linkify(' '.join(strings))
                        strings = []
                        out.append(p_tpl.substitute(content=content))
                else:
                    strings.append(item)
            else:
                if strings:
                    content = linkify(' '.join(strings))
                    strings = []
                    out.append(p_tpl.substitute(content=content))

                out.append(item.html())
        else:
            if strings:
                content = linkify(' '.join(strings))
                strings = []
                out.append(p_tpl.substitute(content=content))

        return ''.join(out)
Ejemplo n.º 8
0
    def check_solution(self, q_URL, code):
        working_dir = "/home/filip/image" + q_URL
        solution_template = load_template(working_dir +
                                          "solutio_template.java")
        user_solution = template.render(code=code)

        # JShell's /open either fails silently or omits
        # important errors. The class_name is needed to
        # further test the user's code for errors.
        class_name = user_solution.split()[2]

        snippet_URL = "snippets/" + self.snippet_key
        with open(snippet_URL, "w") as user_solution_file:
            user_solution_file.write(user_solution)

        error = None
        try:
            load_snippet(snippet_URL, class_name)
            error = run_test_cases(working_dir + "test_cases.json")
        except LoadingFailure:
            error = get_compiler_error(snippet_URL)

        jshell.reset()

        if error:
            return error.json()
        else:
            return "correct"
Ejemplo n.º 9
0
    def generate_base_index(self):
        # Generate base index
        base_tpl = load_template('base')
        index_tpl = load_template('index-contents')

        index = base_tpl.substitute(
            metadescription="Carta.tech: The home for open documentation",
            title="Carta.tech: The home for open documentation",
            canonical="",
            extraheaders="",
            header="",
            breadcrumb="",
            content=index_tpl.substitute(),
        )

        f = open(pjoin(self.root_html, "index.html"), 'w')
        f.write(index)
        f.close()
Ejemplo n.º 10
0
    def generate_manpage_index(self):
        # Generate man-pages index
        base_tpl = load_template('base')
        index_tpl = load_template('index-manpage')

        index = base_tpl.substitute(
            metadescription="Linux Man Pages",
            title="Linux Man Pages",
            canonical="",
            extraheaders="",
            header="",
            breadcrumb="",
            content=index_tpl.substitute(),
        )

        f = open(pjoin(self.manpages_dir, "index.html"), 'w')
        f.write(index)
        f.close()
class Fortunes(object):
    _template = load_template()

    @session(serializable=False)
    def on_get(self, request, response):
        fortunes = [FortuneTuple(id=f.id, message=f.message) for f in Fortune.select()]
        fortunes.append(FortuneTuple(id=0, message="Additional fortune added at request time."))
        fortunes.sort(key=attrgetter("message"))
        content = self._template.render(fortunes=fortunes)
        response.content_type = falcon.MEDIA_HTML
        response.text = content
Ejemplo n.º 12
0
class Section(BaseContainer):
    """docstring for Section"""
    tpl = load_template('section')

    def __init__(self):
        super(Section, self).__init__()
        self.title = None

    def html(self):
        out = super(Section, self).html()

        return self.tpl.substitute(title=linkify(self.title), content=out)
class Fortunes(object):
    _template = load_template()

    @session(serializable=False)
    def on_get(self, request, response):
        fortunes = [FortuneTuple(id=f.id, message=f.message) for f in Fortune.select()]
        fortunes.append(FortuneTuple(id=0, message="Additional fortune added at request time."))
        fortunes.sort(key=attrgetter("message"))
        content = self._template.render(fortunes=fortunes)
        response.set_header('Date', formatdate(timeval=None, localtime=False, usegmt=True))
        response.set_header('Server', server_info)
        response.content_type = falcon.MEDIA_HTML
        response.text = content
Ejemplo n.º 14
0
 def page_header(self):
     return load_template('header').substitute(
         section=self.section,
         title=self.name,
         subtitle=self.title,
     )
Ejemplo n.º 15
0
    def generate_package_indexes(self):
        item_tpl = load_template('package-index-item')
        package_index_tpl = load_template('package-index')
        package_index_section_tpl = load_template('package-index-section')
        package_index_contents_tpl = load_template('package-index-contents')
        package_list_item_tpl = load_template('package-list-item')
        sm_item_tpl = load_template('sitemap-url-nolastmod')

        query = """SELECT name,
                          section,
                          count(package) as amount,
                          group_concat(package) as packages
                   FROM manpages
                   GROUP by name, section
                   ORDER by package ASC, section ASC, name ASC"""

        package_container = defaultdict(lambda: defaultdict(list))

        for name, section, amount, packages in self.conn.execute(query):
            if amount > 1:
                for package in packages.split(','):
                    subtitle = self.subtitles[(package, name, section)]
                    package_container[package][section].append(
                        ("%s.%s" % (name, section), subtitle, True))

            else:
                subtitle = self.subtitles[(packages, name, section)]
                package_container[packages][section].append(
                    ("%s.%s" % (name, section), subtitle, False))

        package_list_items = []
        sitemap_urls = []
        for package, sections in package_container.items():
            package_directory = pjoin(self.packages_dir, package)
            self.makedirs(package_directory)

            package_index = []
            for section, pages in sorted(sections.items()):
                full_section = "man%s" % (section[0], )
                section_description = SECTIONS[full_section]
                section_directory = pjoin(package_directory, full_section)
                section_relative_url = pjoin(self.manpages_dir_name,
                                             full_section)
                section_url = self.manpages_url + "/" + full_section + "/"

                self.makedirs(section_directory)
                items = []
                for name, subtitle, aliased in pages:
                    filename = "%s.html" % (name, )
                    if aliased:
                        filename = "%s-%s" % (
                            package,
                            filename,
                        )

                    relative_url = "/" + pjoin(section_relative_url, filename)

                    items.append(
                        item_tpl.substitute(name=name,
                                            description=subtitle,
                                            link=relative_url))

                package_index.append(
                    package_index_section_tpl.substitute(
                        amount=len(pages),
                        numeric_section=section,
                        section=section_description,
                        section_url=section_url,
                        content=package_index_tpl.substitute(
                            items='\n'.join(items))))

            contents = package_index_contents_tpl.substitute(
                contents="\n".join(package_index))

            breadcrumb = [
                ("/packages/", "Packages"),
                ("/packages/%s/" % package, package),
            ]

            out = load_template('base').substitute(
                title="Man Pages in %s" % package,
                canonical="",
                extraheaders="",
                header=load_template('header-package').substitute(
                    title=package),
                breadcrumb=get_breadcrumb(breadcrumb),
                content=contents,
                metadescription="Man Pages in %s" % package,
            )

            f = open(pjoin(package_directory, "index.html"), 'w')
            f.write(out)
            f.close()

            package_list_items.append(
                package_list_item_tpl.substitute(url="%s/" % (package, ),
                                                 package=package))

            sitemap_urls.append(
                sm_item_tpl.substitute(url="%s/%s/" %
                                       (self.packages_url, package)))

        f = open(pjoin(self.packages_dir, "sitemap.xml"), 'w')
        f.write(
            load_template('sitemap').substitute(
                urlset="\n".join(sitemap_urls)))
        f.close()

        # Generate package index
        breadcrumb = [
            ("/packages/", "Packages"),
        ]

        index = load_template('ul').substitute(
            content="\n".join(package_list_items))
        index_path = pjoin(self.packages_dir, "index.html")

        out = load_template('base').substitute(
            title="Packages with man pages",
            canonical="",
            extraheaders="",
            header=load_template('header-package-index').substitute(
                title="Packages with man pages"),
            breadcrumb=get_breadcrumb(breadcrumb),
            content=index,
            metadescription="List of packages with man pages",
        )

        f = open(index_path, 'w')
        f.write(out)
        f.close()
Ejemplo n.º 16
0
 def html(self):
     out = [linkify(item) for item in self.contents]
     return load_template('pre').substitute(content='\n'.join(out))
Ejemplo n.º 17
0
    def generate_manpage_indexes(self):
        query = """SELECT name,
                          section,
                          count(package) as amount,
                          group_concat(package) as packages
                   FROM manpages
                   GROUP by name, section
                   ORDER by section ASC, name ASC"""

        section_item_tpl = load_template('section-index-item')
        section_item_manpage_tpl = load_template('section-index-item-manpage')
        items = defaultdict(list)
        for name, section, amount, packages in self.conn.execute(query):
            page = "%s.%s" % (name, section)
            if amount > 1:
                for package in packages.split(','):
                    subtitle = self.subtitles[(package, name, section)]

                    if package == "man-pages":
                        items[section].append(
                            section_item_manpage_tpl.substitute(
                                link=page,
                                name=name,
                                section=section,
                                description=subtitle,
                                package=package))
                    else:
                        items[section].append(
                            section_item_tpl.substitute(link=page,
                                                        name=name,
                                                        section=section,
                                                        description=subtitle,
                                                        package=package))

            else:
                subtitle = self.subtitles[(packages, name, section)]

                if packages == "man-pages":
                    items[section].append(
                        section_item_manpage_tpl.substitute(
                            link=page,
                            name=name,
                            section=section,
                            description=subtitle,
                            package=packages))
                else:
                    items[section].append(
                        section_item_tpl.substitute(link=page,
                                                    name=name,
                                                    section=section,
                                                    description=subtitle,
                                                    package=packages))

        for section in items:
            section_content = load_template('section-index').substitute(
                items=''.join(items[section[0]]))

            section_description = SECTIONS["man%s" % section[0]]

            breadcrumb = [
                ("/man-pages/", "Man Pages"),
                ("/man-pages/man%s/" % section[0], section_description),
            ]

            out = load_template('base').substitute(
                title="Linux Man Pages - %s" % section_description,
                canonical="",
                extraheaders="",
                header=load_template('header').substitute(
                    title=section_description, section=section, subtitle=""),
                breadcrumb=get_breadcrumb(breadcrumb),
                content=section_content,
                metadescription=section_description.replace("\"", "\'"),
            )

            f = open(
                pjoin(self.manpages_dir, "man%s" % section[0], 'index.html'),
                'w')
            f.write(out)
            f.close()
Ejemplo n.º 18
0
class SubSection(Section):
    tpl = load_template('subsection')