Panda3D
|
def build(self, path, lTOC): """Create an archive file of name 'path'. More...
Public Member Functions | |
def | __init__ |
def | extract |
Core method - Override as needed #########. | |
Static Public Attributes | |
int | HDRLEN = 12 |
int | LEVEL = 9 |
string | MAGIC = 'PYZ\0' |
int | TOCPOS = 8 |
dictionary | TOCTMPLT = {} |
int | TRLLEN = 0 |
def build(self, path, lTOC): """Create an archive file of name 'path'.
lTOC is a 'logical TOC' - a list of (name, path, ...) where name is the internal name, eg 'a' and path is a file to get the object from, eg './a.pyc'. """ self.path = path self.lib = open(path, 'wb') #reserve space for the header if self.HDRLEN: self.lib.write('\0'*self.HDRLEN)
#create an empty toc
if type(self.TOCTMPLT) == type({}): self.toc = {} else: # assume callable self.toc = self.TOCTMPLT()
for tocentry in lTOC: self.add(tocentry) # the guts of the archive
tocpos = self.lib.tell() self.save_toc(tocpos) if self.TRLLEN: self.save_trailer(tocpos) if self.HDRLEN: self.update_headers(tocpos) self.lib.close()
####### manages keeping the internal TOC and the guts in sync ####### def add(self, entry): """Override this to influence the mechanics of the Archive. Assumes entry is a seq beginning with (nm, pth, ...) where nm is the key by which we'll be asked for the object. pth is the name of where we find the object. Overrides of get_obj_from can make use of further elements in entry. """ if self.os is None: import os self.os = os nm = entry[0] pth = entry[1] ispkg = self.os.path.splitext(self.os.path.basename(pth))[0] == '__init__' self.toc[nm] = (ispkg, self.lib.tell()) f = open(entry[1], 'rb') f.seek(8) #skip magic and timestamp self.lib.write(f.read())
def save_toc(self, tocpos): """Default - toc is a dict Gets marshaled to self.lib """ marshal.dump(self.toc, self.lib)
def save_trailer(self, tocpos): """Default - not used""" pass
def update_headers(self, tocpos): """Default - MAGIC + Python's magic + tocpos""" self.lib.seek(self.start) self.lib.write(self.MAGIC) self.lib.write(self.pymagic) self.lib.write(struct.pack('=i', tocpos))
ZlibArchive - an archive with compressed entries
def __init__ | ( | self, | |
path = None , |
|||
offset = 0 |
|||
) |
Reimplemented from Archive.
def extract | ( | self, | |
name | |||
) |
Core method - Override as needed #########.
Get the object corresponding to name, or None. For use with imputil ArchiveImporter, object is a python code object. 'name' is the name as specified in an 'import name'. 'import a.b' will become: extract('a') (return None because 'a' is not a code object) extract('a.__init__') (return a code object) extract('a.b') (return a code object) Default implementation: self.toc is a dict self.toc[name] is pos self.lib has the code object marshal-ed at pos
Reimplemented from Archive.
int LEVEL = 9 [static] |