def setPrevUpNextLinks(self, prev=None, up=None, next=None): """Sets Prev link to point to the LogEntry object "prev". Set that object's Next link to point to us. Sets the "up" link to the URL 'up' (if up != None.) Sets the Next link to the entry 'next' (if next != None), or to nothing if next == ''.""" if prev is not None: if prev: self._prev_link = quote_url(prev._relIndexLink()) prev._next_link = quote_url(self._relIndexLink()) else: self._prev_link = None if up is not None: self._up_link = up and quote_url(up) if next is not None: self._next_link = next and quote_url(next._relIndexLink())
def _renderSingleImage(self, image, thumb, relpath): if image is None: return "" # else no thumbnail: make "image" link elif thumb is None: fname = relpath + image return """<A HREF="%s">image</A>""" % quote_url(fname) # else return thumbnail linking to full image else: tname = relpath + thumb fname = relpath + image return """<A HREF="%s"><IMG SRC="%s" ALT="%s"></A>""" % (quote_url(fname), quote_url(tname), quote_url(os.path.basename(image)))
def renderThumbnail (self,relpath=""): """renderThumbnail() is called to render a thumbnail of the DP (e.g. in Data Product tables)."""; # no thumbnail -- return empty string if self.thumbnail is None: return ""; # else thumbnail is same as full image (because image was small enough), insert directly elif self.thumbnail is self.fullimage: fname = relpath+self.fullimage; return """<IMG SRC="%s" ALT="%s"></IMG>"""%(quote_url(fname),quote_url(os.path.basename(self.filename))); # else return thumbnail linking to full image else: tname = relpath+self.thumbnail; fname = relpath+self.fullimage; return """<A HREF="%s"><IMG SRC="%s" ALT="%s"></A>"""%(quote_url(fname),quote_url(tname),quote_url(os.path.basename(self.filename)));
def renderThumbnail(self, relpath=""): """renderThumbnail() is called to render a thumbnail of the DP (e.g. in Data Product tables).""" # no thumbnail -- return empty string if self.thumbnail is None: return "" # else thumbnail is same as full image (because image was small enough), insert directly elif self.thumbnail is self.fullimage: fname = relpath + self.fullimage return """<IMG SRC="%s" ALT="%s"></IMG>""" % (quote_url(fname), quote_url(os.path.basename(self.filename))) # else return thumbnail linking to full image else: tname = relpath + self.thumbnail fname = relpath + self.fullimage return """<A HREF="%s"><IMG SRC="%s" ALT="%s"></A>""" % ( quote_url(fname), quote_url(tname), quote_url(os.path.basename(self.filename)))
def writeLogIndex(logdir, title, timestamp, entries, refresh=0): logdir = os.path.normpath(os.path.abspath(logdir)) fullindex = os.path.join(logdir, FULLINDEX) tocindex = os.path.join(logdir, INDEX) # if 5 entries or less, do an index only, and remove the fullindex if len(entries) <= 5: if os.path.exists(fullindex): try: os.remove(fullindex) except: print("Error removing %s:" % fullindex) traceback.print_exc() fullindex = tocindex tocindex = None # generate TOC index, if asked to if tocindex: fobj = open(tocindex, "wt") # write index.html fobj.write("""<HTML><BODY>\n <TITLE>%s</TITLE> <H1><A CLASS="TITLE" TIMESTAMP=%.6f>%s</A></H1> """ % (title, timestamp, title)) fobj.write( """<DIV ALIGN=right><P><A HREF=%s>Printable version (single HTML page).</A></P></DIV>\n\n""" % FULLINDEX) # write entries for i, entry in enumerate(entries): path = os.path.normpath(os.path.abspath(entry.index_file)) if path.startswith(logdir + '/'): path = path[(len(logdir) + 1):] fobj.write("""<P><A HREF="%s">%d. %s</A></P>\n\n""" % (quote_url(path), i + 1, entry.title)) # write footer fobj.write("<HR>\n\n") fobj.write("""<DIV ALIGN=right>%s <I><SMALL>This log was generated by PURR version %s.</SMALL></I></DIV>\n""" % (renderIcon(16), Purr.Version)) fobj.write("</BODY></HTML>\n") fobj = None # generate full index, if asked to if fullindex: fobj = open(fullindex, "wt") # write index.html fobj.write("""<HTML><BODY>\n <TITLE>%s</TITLE> <H1><A CLASS="TITLE" TIMESTAMP=%.6f>%s</A></H1> """ % (title, timestamp, title)) # write entries for entry in entries: fobj.write(entry.renderIndex(os.path.join(os.path.basename(entry.pathname), ""), refresh=refresh)) # write footer fobj.write("<HR>\n") fobj.write("""<DIV ALIGN=right>%s <I><SMALL>This log was generated by PURR version %s.</SMALL></I></DIV>\n""" % (renderIcon(16), Purr.Version)) fobj.write("</BODY></HTML>\n") fobj = None
def renderLink(self, relpath=""): """renderLink() is called to render a link to the DP """ # return from cache if available cachekey, html = self.checkCache('Link', relpath) if html is not None: return html # else regenerate html = CachingRenderer.renderLink(self, relpath) if self.headerfile is not None: html += """ (<A HREF="%s">header</A>)""" % quote_url(relpath + self.headerfile) # save to cache return self.writeCache(cachekey, html)
def renderIcon(size, path=None): filename = PURR_ICONS[size] if path: filename = os.path.join(path, filename) return """<IMG SRC="%s"></IMG>""" % quote_url(filename)
def writeLogIndex(logdir, title, timestamp, entries, refresh=0): logdir = os.path.normpath(os.path.abspath(logdir)) fullindex = os.path.join(logdir, FULLINDEX) tocindex = os.path.join(logdir, INDEX) # if 5 entries or less, do an index only, and remove the fullindex if len(entries) <= 5: if os.path.exists(fullindex): try: os.remove(fullindex) except: print("Error removing %s:" % fullindex) traceback.print_exc() fullindex = tocindex tocindex = None # generate TOC index, if asked to if tocindex: fobj = open(tocindex, "wt") # write index.html fobj.write("""<HTML><BODY>\n <TITLE>%s</TITLE> <H1><A CLASS="TITLE" TIMESTAMP=%.6f>%s</A></H1> """ % (title, timestamp, title)) fobj.write( """<DIV ALIGN=right><P><A HREF=%s>Printable version (single HTML page).</A></P></DIV>\n\n""" % FULLINDEX) # write entries for i, entry in enumerate(entries): path = os.path.normpath(os.path.abspath(entry.index_file)) if path.startswith(logdir + '/'): path = path[(len(logdir) + 1):] fobj.write("""<P><A HREF="%s">%d. %s</A></P>\n\n""" % (quote_url(path), i + 1, entry.title)) # write footer fobj.write("<HR>\n\n") fobj.write("""<DIV ALIGN=right>%s <I><SMALL>This log was generated by PURR version %s.</SMALL></I></DIV>\n""" % (renderIcon(16), Purr.Version)) fobj.write("</BODY></HTML>\n") fobj = None # generate full index, if asked to if fullindex: fobj = open(fullindex, "wt") # write index.html fobj.write("""<HTML><BODY>\n <TITLE>%s</TITLE> <H1><A CLASS="TITLE" TIMESTAMP=%.6f>%s</A></H1> """ % (title, timestamp, title)) # write entries for entry in entries: fobj.write( entry.renderIndex(os.path.join( os.path.basename(entry.pathname), ""), refresh=refresh)) # write footer fobj.write("<HR>\n") fobj.write("""<DIV ALIGN=right>%s <I><SMALL>This log was generated by PURR version %s.</SMALL></I></DIV>\n""" % (renderIcon(16), Purr.Version)) fobj.write("</BODY></HTML>\n") fobj = None