Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
Export the cache in html

        def exportToHTML(cache, outpath):
    """
    Export the cache in html
    """

    # Checking that the directory exists and is writable
    if not os.path.exists(outpath):
        os.makedirs(outpath)
    outpath = os.path.abspath(outpath) + '/'

    index = open(outpath + "index.html", 'w')
    index.write("
    ") for entry in cache: # Adding a link in the index if entry.keyLength > 100: name = entry.keyToStr()[:100] + "..." else: name = entry.keyToStr() index.write('
  • %s
  • '%(entry.hash, name)) # Creating the entry page page = open(outpath + "%08x"%entry.hash, 'w') page.write(""" """) # Details of the entry page.write("Hash: 0x%08x
    "%entry.hash) page.write("Usage Counter: %d
    "%entry.usageCounter) page.write("Reuse Counter: %d
    "%entry.reuseCounter) page.write("Creation Time: %s
    "%entry.creationTime) page.write("Key: %s
    "%entry.keyToStr()) page.write("State: %s
    "%CacheEntry.STATE[entry.state]) page.write("
    ") if len(entry.data) == 0: page.write("No data associated with this entry :-(") for i in range(len(entry.data)): if entry.data[i].type == CacheData.UNKNOWN: # Extracting data into a file name = outpath + hex(entry.hash) + "_" + str(i) entry.data[i].save(name) if entry.httpHeader != None and \ entry.httpHeader.headers.has_key('content-encoding') and\ entry.httpHeader.headers['content-encoding'] == "gzip": # XXX Highly inefficient !!!!! try: input = gzip.open(name, 'rb') output = open(name + "u", 'w') output.write(input.read()) input.close() output.close() page.write('%s'%(name , entry.keyToStr().split('/')[-1])) except IOError: page.write("Something wrong happened while unzipping") else: page.write('%s'%(name , entry.keyToStr().split('/')[-1])) # If it is a picture, display it if entry.httpHeader != None: if entry.httpHeader.headers.has_key('content-type') and\ "image" in entry.httpHeader.headers['content-type']: page.write('
    '%(name)) # HTTP Header else: page.write("HTTP Header
    ") for key, value in entry.data[i].headers.items(): page.write("%s: %s
    "%(key, value)) page.write("
    ") page.write("") page.close() index.write("
") index.close()


src/c/h/Chromagnon-HEAD/chromagnonCache.py   Chromagnon(Download)
                print "-"*80
    else:
        chromagnon.cacheParse.exportToHTML(cache, args.o)
 
if __name__ == "__main__":