Beispiel #1
0
 def prepOutputDirectory(self):
     os.makedirs(self.base, exist_ok=True)
     shutil.copyfile(templatefile('apidocs.css'),
                     os.path.join(self.base, 'apidocs.css'))
     shutil.copyfile(templatefile('bootstrap.min.css'),
                     os.path.join(self.base, 'bootstrap.min.css'))
     shutil.copyfile(templatefile('pydoctor.js'),
                     os.path.join(self.base, 'pydoctor.js'))
Beispiel #2
0
 def prepOutputDirectory(self):
     if not os.path.exists(self.base):
         os.mkdir(self.base)
     shutil.copyfile(templatefile('apidocs.css'),
                     os.path.join(self.base, 'apidocs.css'))
     shutil.copyfile(templatefile('bootstrap.min.css'),
                     os.path.join(self.base, 'bootstrap.min.css'))
     shutil.copyfile(templatefile('pydoctor.js'),
                     os.path.join(self.base, 'pydoctor.js'))
Beispiel #3
0
 def prepOutputDirectory(self):
     if not os.path.exists(self.base):
         os.mkdir(self.base)
     shutil.copyfile(templatefile('apidocs.css'),
                     os.path.join(self.base, 'apidocs.css'))
     shutil.copyfile(templatefile('bootstrap.min.css'),
                     os.path.join(self.base, 'bootstrap.min.css'))
     shutil.copyfile(templatefile('pydoctor.js'),
                     os.path.join(self.base, 'pydoctor.js'))
Beispiel #4
0
 def prepOutputDirectory(self):
     if not os.path.exists(self.base):
         os.mkdir(self.base)
     shutil.copyfile(templatefile("apidocs.css"),
                     os.path.join(self.base, "apidocs.css"))
     shutil.copyfile(
         templatefile("bootstrap.min.css"),
         os.path.join(self.base, "bootstrap.min.css"),
     )
     shutil.copyfile(templatefile("pydoctor.js"),
                     os.path.join(self.base, "pydoctor.js"))
Beispiel #5
0
 def prepOutputDirectory(self):
     if not os.path.exists(self.base):
         os.mkdir(self.base)
     shutil.copyfile(templatefile('apidocs.css'),
                     os.path.join(self.base, 'apidocs.css'))
     if self.system.options.htmlusesorttable:
         shutil.copyfile(templatefile('sorttable.js'),
                         os.path.join(self.base, 'sorttable.js'))
     if self.system.options.htmlusesplitlinks or self.system.options.htmlshortenlists:
         shutil.copyfile(templatefile('pydoctor.js'),
                         os.path.join(self.base, 'pydoctor.js'))
Beispiel #6
0
 def prepOutputDirectory(self):
     if not os.path.exists(self.base):
         os.mkdir(self.base)
     shutil.copyfile(templatefile('apidocs.css'),
                     os.path.join(self.base, 'apidocs.css'))
     if self.system.options.htmlusesorttable:
         shutil.copyfile(templatefile('sorttable.js'),
                         os.path.join(self.base, 'sorttable.js'))
     if self.system.options.htmlusesplitlinks or self.system.options.htmlshortenlists:
         shutil.copyfile(templatefile('pydoctor.js'),
                         os.path.join(self.base, 'pydoctor.js'))
Beispiel #7
0
 def __init__(self, system):
     resource.Resource.__init__(self)
     self.system = system
     self.putChild('apidocs.css', File(util.templatefile('apidocs.css')))
     self.putChild('sorttable.js', File(util.templatefile('sorttable.js')))
     self.putChild('pydoctor.js', File(util.templatefile('pydoctor.js')))
     self.index = WrapperPage(self.indexPage())
     self.putChild('', self.index)
     self.putChild('index.html', self.index)
     self.putChild('moduleIndex.html',
                   WrapperPage(summary.ModuleIndexPage(self.system)))
     self.putChild('classIndex.html',
                   WrapperPage(summary.ClassIndexPage(self.system)))
     self.putChild('nameIndex.html',
                   WrapperPage(summary.NameIndexPage(self.system)))
Beispiel #8
0
class NameIndexPage(Element):
    filename = 'nameIndex.html'
    loader = XMLFile(templatefile('nameIndex.html'))

    def __init__(self, system):
        self.system = system
        self.initials = {}
        for ob in self.system.orderedallobjects:
            if ob.isVisible:
                self.initials.setdefault(ob.name[0].upper(), []).append(ob)

    @renderer
    def title(self, request, tag):
        return tag.clear()("Index Of Names")

    @renderer
    def heading(self, request, tag):
        return tag.clear()("Index Of Names")

    @renderer
    def index(self, request, tag):
        r = []
        for i in sorted(self.initials):
            r.append(LetterElement(TagLoader(tag), self.initials, i))
        return r
Beispiel #9
0
class DiffElement(Element):

    def __init__(self, root, ob, origob, editA, editB):
        self.root = root
        self.ob = ob
        self.origob = origob
        self.editA = editA
        self.editB = editB

    @renderer
    def title(self, request, tag):
        return tag("Viewing differences between revisions ",
                   str(self.editA.rev), " and ", str(self.editB.rev), " of ",
                   u"\N{LEFT DOUBLE QUOTATION MARK}" +
                   self.origob.fullName() +
                   u"\N{RIGHT DOUBLE QUOTATION MARK}")

    @renderer
    def diff(self, request, tag):
        fd = FileDiff(self.ob.parentMod)
        fd.apply_edit(self.root.editsbyob[self.ob][0], self.editA)
        fd.reset()
        fd.apply_edit(self.editA, self.editB)
        return tags.pre(fd.diff())

    loader = XMLFile(util.templatefile('diff.html'))
Beispiel #10
0
class ClassIndexPage(Element):
    filename = 'classIndex.html'
    loader = XMLFile(templatefile('summary.html'))

    def __init__(self, system):
        self.system = system

    @renderer
    def title(self, request, tag):
        return tag.clear()("Class Hierarchy")

    @renderer
    def stuff(self, request, tag):
        t = tag
        anchors = set()
        for b, o in findRootClasses(self.system):
            if isinstance(o, model.Class):
                t(subclassesFrom(self.system, o, anchors))
            else:
                item = tags.li(b)
                if o:
                    ul = tags.ul()
                    for sc in sorted(o, key=_lckey):
                        ul(subclassesFrom(self.system, sc, anchors))
                    item(ul)
                t(item)
        return t

    @renderer
    def heading(self, request, tag):
        return tag.clear()("Class Hierarchy")
Beispiel #11
0
class UndocumentedSummaryPage(Element):
    filename = 'undoccedSummary.html'
    loader = XMLFile(templatefile('summary.html'))

    def __init__(self, system):
        self.system = system

    @renderer
    def title(self, request, tag):
        return tag.clear()("Summary of Undocumented Objects")

    @renderer
    def heading(self, request, tag):
        return tag.clear()("Summary of Undocumented Objects")

    @renderer
    def stuff(self, request, tag):
        undoccedpublic = [
            o for o in self.system.orderedallobjects
            if o.isVisible and not hasdocstring(o)
        ]
        undoccedpublic.sort(key=lambda o: o.fullName())
        for o in undoccedpublic:
            tag(tags.li(o.kind, " - ", taglink(o)))
        return tag
Beispiel #12
0
class IndexPage(Element):
    filename = 'index.html'
    loader = XMLFile(templatefile('index.html'))

    def __init__(self, system):
        self.system = system

    @renderer
    def project_link(self, request, tag):
        if self.system.options.projecturl:
            return tags.a(href=self.system.options.projecturl)(
                self.system.projectname)
        else:
            return self.system.projectname

    @renderer
    def project(self, request, tag):
        return self.system.projectname

    @renderer
    def recentChanges(self, request, tag):
        return ()

    @renderer
    def problemObjects(self, request, tag):
        return ()

    @renderer
    def onlyIfOneRoot(self, request, tag):
        if len(self.system.rootobjects) != 1:
            return []
        else:
            root, = self.system.rootobjects
            return tag.clear()("Start at ", taglink(root), ", the root ",
                               root.kind.lower(), ".")

    @renderer
    def onlyIfMultipleRoots(self, request, tag):
        if len(self.system.rootobjects) == 1:
            return []
        else:
            return tag

    @renderer
    def roots(self, request, tag):
        r = []
        for o in self.system.rootobjects:
            r.append(tag.clone().fillSlots(root=taglink(o)))
        return r

    @renderer
    def rootkind(self, request, tag):
        rootkinds = {}
        for o in self.system.rootobjects:
            rootkinds[o.kind.lower() + 's'] = 1
        return tag.clear()('/'.join(sorted(rootkinds)))

    @renderer
    def buildtime(self, request, tag):
        return self.system.buildtime.strftime("%Y-%m-%d %H:%M:%S")
Beispiel #13
0
class AttributeChild(Element):

    loader = XMLFile(util.templatefile('attribute-child.html'))

    def __init__(self, docgetter, ob):
        self.docgetter = docgetter
        self.ob = ob

    @renderer
    def class_(self, request, tag):
        class_ = self.ob.css_class
        if self.ob.parent is not self.ob:
            class_ = 'base' + class_
        return class_

    @renderer
    def functionAnchor(self, request, tag):
        return self.ob.fullName()

    @renderer
    def shortFunctionAnchor(self, request, tag):
        return self.ob.name

    @renderer
    def attribute(self, request, tag):
        return self.ob.name

    @renderer
    def functionBody(self, request, tag):
        return self.docgetter.get(self.ob)
Beispiel #14
0
class FunctionChild(Element):

    loader = XMLFile(util.templatefile('function-child.html'))

    def __init__(self, docgetter, ob, functionExtras):
        self.docgetter = docgetter
        self.ob = ob
        self._functionExtras = functionExtras

    @renderer
    def functionAnchor(self, request, tag):
        return self.ob.fullName()

    @renderer
    def shortFunctionAnchor(self, request, tag):
        return self.ob.name

    @renderer
    def decorator(self, request, tag):
        if self.ob.decorators:
            decorators = [ast_pp.pp(dec) for dec in self.ob.decorators]
        else:
            decorators = []

        if self.ob.kind == "Class Method" \
               and 'classmethod' not in decorators:
            decorators.append('classmethod')
        elif self.ob.kind == "Static Method" \
                 and 'staticmethod' not in decorators:
            decorators.append('staticmethod')

        if decorators:
            decorator = [('@' + dec, tags.br()) for dec in decorators]
        else:
            decorator = ()

        return decorator

    @renderer
    def functionName(self, request, tag):
        return [self.ob.name, '(', signature(self.ob.argspec), '):']

    @renderer
    def sourceLink(self, request, tag):
        if self.ob.sourceHref:
            return tag.fillSlots(sourceHref=self.ob.sourceHref)
        else:
            return ()

    @renderer
    def functionExtras(self, request, tag):
        return self._functionExtras

    @renderer
    def functionBody(self, request, tag):
        return self.docgetter.get(self.ob)
Beispiel #15
0
class ProblemObjectsElement(Element):

    def __init__(self, system):
        self.system = system

    @renderer
    def problemObjects(self, request, tag):
        r = []
        for fn in sorted(self.system.epytextproblems):
            o = self.system.allobjects[fn]
            r.append(tag.clone().fillSlots(link=util.taglink(o)))
        return r

    loader = XMLFile(util.templatefile('problemObjects.html'))
Beispiel #16
0
class ModuleIndexPage(Element):
    filename = 'moduleIndex.html'
    loader = XMLFile(templatefile('summary.html'))

    def __init__(self, system):
        self.system = system

    @renderer
    def title(self, request, tag):
        return tag.clear()("Module Index")

    @renderer
    def stuff(self, request, tag):
        r = []
        for o in self.system.rootobjects:
            r.append(moduleSummary(o))
        return tag.clear()(r)

    @renderer
    def heading(self, request, tag):
        return tag().clear()("Module Index")
Beispiel #17
0
class ChildTable(Element):

    loader = XMLFile(util.templatefile('table.html'))

    last_id = 0

    def __init__(self, docgetter, ob, has_lineno_col, children):
        self.docgetter = docgetter
        self.system = ob.system
        self.has_lineno_col = has_lineno_col
        self.children = children
        ChildTable.last_id += 1
        self._id = ChildTable.last_id
        self.ob = ob

    @renderer
    def id(self, request, tag):
        return 'id' + str(self._id)

    @renderer
    def header(self, request, tag):
        if self.system.options.htmlusesorttable:
            return tag
        else:
            return ()

    @renderer
    def linenohead(self, request, tag):
        if self.has_lineno_col:
            return tag
        else:
            return ()

    @renderer
    def rows(self, request, tag):
        return [
            TableRow(TagLoader(tag), self.docgetter, self.has_lineno_col,
                     self.ob, child) for child in self.children
        ]
Beispiel #18
0
class ChildTable(Element):
    loader = XMLFile(util.templatefile('table.html'))
    last_id = 0

    def __init__(self, docgetter, ob, children):
        self.docgetter = docgetter
        self.system = ob.system
        self.children = children
        ChildTable.last_id += 1
        self._id = ChildTable.last_id
        self.ob = ob

    @renderer
    def id(self, request, tag):
        return 'id' + str(self._id)

    @renderer
    def rows(self, request, tag):
        return [
            TableRow(TagLoader(tag), self.docgetter, self.ob, child)
            for child in self.children
        ]
Beispiel #19
0
class BigDiffElement(Element):
    def __init__(self, system, root):
        self.system = system
        self.root = root

    @renderer
    def bigDiff(self, request, tag):
        mods = {}
        for m in self.root.editsbymod:
            l = [e for e in self.root.editsbymod[m]
                 if e is self.root.editsbyob[e.obj.doctarget][-1]]
            l.sort(key=lambda x:x.obj.linenumber, reverse=True)
            mods[m] = FileDiff(m)
            for e in l:
                edit0 = self.root.editsbyob[e.obj][0]
                mods[m].apply_edit(edit0, e)
        r = []
        for mod in sorted(mods, key=lambda x:x.filepath):
            r.append(tags.pre(mods[mod].diff()))
        return r

    loader = XMLFile(util.templatefile('bigDiff.html'))
Beispiel #20
0
 def loader(self):
     return XMLFile(util.templatefile('common.html'))
Beispiel #21
0
class CommonPage(Element):
    loader = XMLFile(templatefile('common.html'))

    def __init__(self, ob, docgetter=None):
        self.ob = ob
        if docgetter is None:
            docgetter = DocGetter()
        self.docgetter = docgetter
        self.usesorttable = ob.system.options.htmlusesorttable
        self.usesplitlinks = ob.system.options.htmlusesplitlinks
        self.shortenlists = ob.system.options.htmlshortenlists

    def title(self):
        return self.ob.fullName()

    def mediumName(self, obj):
        fn = obj.fullName()
        if '.' not in fn:
            return fn
        path, name = fn.rsplit('.', 1)

        def process(part):
            return obj.system.abbrevmapping.get(part, part[0])

        return '.'.join([process(p) for p in path.split('.')]) + '.' + name

    def heading(self):
        return tags.h1(class_=self.ob.css_class)(self.mediumName(self.ob),
                                                 " : ", self.ob.kind.lower(),
                                                 " documentation")

    def part(self):
        if self.ob.parent:
            parent = self.ob.parent
            if isinstance(parent, model.Module) and parent.name == '__init__':
                parent = parent.parent
            parts = []
            while parent.parent:
                parts.append(taglink(parent, parent.name))
                parts.append('.')
                parent = parent.parent
            parts.append(taglink(parent, parent.name))
            parts.reverse()
            return 'Part of ', parts
        else:
            return []

    def project(self):
        if self.ob.system.options.projecturl:
            return tags.a(href=self.ob.system.options.projecturl)(
                self.ob.system.projectname)
        else:
            return self.ob.system.projectname

    @renderer
    def source(self, request, tag):
        sourceHref = srclink(self.ob)
        if not sourceHref:
            return ()
        return tag(href=sourceHref)

    @renderer
    def inhierarchy(self, request, tag):
        return ()

    def extras(self):
        return []

    def docstring(self):
        return self.docgetter.get(self.ob)

    def children(self):
        return sorted([o for o in self.ob.orderedcontents if o.isVisible],
                      key=lambda o: -o.privacyClass)

    def packageInitTable(self):
        return ()

    @renderer
    def baseTables(self, request, tag):
        return ()

    @renderer
    def bigTable(self, request, tag):
        return ()

    def mainTable(self):
        children = self.children()
        if children:
            return ChildTable(self.docgetter, self.ob, self.has_lineno_col(),
                              children)
        else:
            return ()

    def has_lineno_col(self):
        if not self.usesorttable:
            return False
        return isinstance(self.ob, (model.Class, model.Module))

    @renderer
    def ifusesorttable(self, request, tag):
        if self.usesorttable:
            return tag
        else:
            return ()

    def methods(self):
        return [
            o for o in self.ob.orderedcontents
            if o.documentation_location == model.DocLocation.PARENT_PAGE
            and o.isVisible
        ]

    def childlist(self):
        from pydoctor.templatewriter.pages.attributechild import AttributeChild
        from pydoctor.templatewriter.pages.functionchild import FunctionChild
        r = []
        for c in self.methods():
            if isinstance(c, model.Function):
                r.append(
                    FunctionChild(self.docgetter, c, self.functionExtras(c)))
            else:
                r.append(AttributeChild(self.docgetter, c))
        return r

    def functionExtras(self, data):
        return []

    def functionBody(self, data):
        return self.docgetter.get(data)

    @renderer
    def splittingLinks(self, request, tag):
        return ()

    @renderer
    def pydoctorjs(self, request, tag):
        if self.usesplitlinks or self.shortenlists:
            return tag
        else:
            return ()

    @renderer
    def all(self, request, tag):
        return tag.fillSlots(
            title=self.title(),
            heading=self.heading(),
            part=self.part(),
            extras=self.extras(),
            docstring=self.docstring(),
            mainTable=self.mainTable(),
            packageInitTable=self.packageInitTable(),
            childlist=self.childlist(),
            project=self.project(),
            buildtime=self.ob.system.buildtime.strftime("%Y-%m-%d %H:%M:%S"))
Beispiel #22
0
 def loader(self):
     return XMLFile(util.templatefile('index.html'))
Beispiel #23
0
 def loader(self):
     return XMLFile(util.templatefile('summary.html'))
Beispiel #24
0
class EditElement(Element):
    def __init__(self, root, ob, docstring, isPreview, initialWhitespace):
        self.root = root
        self.ob = ob
        self.lines = open(
            self.ob.doctarget.parentMod.filepath, 'rU').readlines()
        self.docstring = docstring
        self.isPreview = isPreview
        self._initialWhitespace = initialWhitespace

    @renderer
    def title(self, request, tag):
        return tag.clear()(
            u"Editing docstring of \N{LEFT DOUBLE QUOTATION MARK}",
            self.ob.fullName(),
            u"\N{RIGHT DOUBLE QUOTATION MARK}")

    @renderer
    def preview(self, request, tag):
        docstring = parse_str(self.docstring)
        stan, errors = epydoc2stan.doc2stan(
            self.ob, docstring=docstring)
        if self.isPreview or errors:
            if errors:
                #print stan, errors
                #assert isinstance(stan, tags.pre)
                [text] = stan.children
                lines = text.replace('\r\n', '\n').split('\n')
                line2err = {}
                for err in errors:
                    if isinstance(err, str):
                        ln = None
                    else:
                        ln = err.linenum()
                    line2err.setdefault(ln, []).append(err)
                w = len(str(len(lines)))
                for i, line in enumerate(lines):
                    i += 1
                    cls = "preview"
                    if i in line2err:
                        cls += " error"
                    tag(tags.pre(class_=cls)("%*s"%(w, i), ' ', line))
                    for err in line2err.get(i, []):
                        tag(tags.p(class_="errormessage")(err.descr()))
                i += 1
                for err in line2err.get(i, []):
                    tag(tags.p(class_="errormessage")(err.descr()))
                items = []
                for err in line2err.get(None, []):
                    items.append(tags.li(str(err)))
                if items:
                    tag(tags.ul(items))
            else:
                tag = tag(stan)
            return tag(tags.h2("Edit"))
        else:
            return ()

    @renderer
    def fullName(self, request, tag):
        return self.ob.fullName()

    @renderer
    def initialWhitespace(self, request, tag):
        return self._initialWhitespace

    @renderer
    def before(self, request, tag):
        tob = self.ob.doctarget
        if tob.docstring:
            docstring_line_count = len(tob.docstring.orig.splitlines())
            lineno = tob.docstring.linenumber - docstring_line_count
        else:
            lineno = tob.linenumber
        firstlineno = max(0, lineno-6)
        lines = self.lines[firstlineno:lineno]
        if not lines:
            return ()
        if firstlineno > 0:
            lines.insert(0, '...\n')
        return tag(lines)

    @renderer
    def divIndent(self, request, tag):
        return 'margin-left: %dex;'%(indentationAmount(self.ob),)

    @renderer
    def rows(self, request, tag):
        return str(len(self.docstring.splitlines()) + 1)

    @renderer
    def textarea(self, request, tag):
        return tag.clear()(self.docstring)

    @renderer
    def after(self, request, tag):
        tob = self.ob.doctarget
        if tob.docstring:
            lineno = tob.docstring.linenumber
        else:
            lineno = tob.linenumber
        lastlineno = lineno + 6
        lines = self.lines[lineno:lastlineno]
        if not lines:
            return ()
        if lastlineno < len(self.lines):
            lines.append('...\n')
        return tag(lines)

    @renderer
    def url(self, request, tag):
        return 'edit?ob=' + self.ob.fullName()

    loader = XMLFile(util.templatefile("edit.html"))