コード例 #1
0
ファイル: resource.py プロジェクト: sancitu/incremental
def makeresource(name, xtrapath=None):
    """Factory function that returns a resource subclass.

       NAME is the logical or physical name of a resource.
       XTRAPTH is a path or list of paths to search first.
       return one of the resource subclasses.
       Warning - logical names can conflict; archive might return a directory,
       when the module archive.py was desired."""
    typ, nm, fullname = finder.identify(name, xtrapath)
    fullname = os.path.normpath(fullname)
    if fullname in _cache:
        return _cache[fullname]
    elif typ in (finder.SCRIPT, finder.GSCRIPT):
        rsrc = scriptresource(nm, fullname)
    elif typ == finder.MODULE:
        rsrc = moduleresource(nm, fullname)
    elif typ == finder.PACKAGE:
        rsrc = pkgresource(nm, fullname)
    elif typ in (finder.PBINARY, finder.BINARY):
        rsrc = binaryresource(nm, fullname)
    elif typ == finder.ZLIB:
        rsrc = zlibresource(nm, fullname)
    elif typ == finder.DIRECTORY:
        rsrc = dirresource(nm, fullname)
    else:
        try:
            carchive.CArchive(fullname)
        except:
            rsrc = dataresource(nm, fullname)
        else:
            rsrc = archiveresource(nm, fullname)
    _cache[fullname] = rsrc
    return rsrc
コード例 #2
0
ファイル: ArchiveViewer.py プロジェクト: tillwf/artub
def getArchive(nm):
    if not stack:
        if string.lower(nm[-4:]) == '.pyz':
            return ZlibArchive(nm)
        return carchive.CArchive(nm)
    parent = stack[-1][1]
    try:
        return parent.openEmbedded(nm)
    except KeyError, e:
        return None
コード例 #3
0
 def assemble(self, pkgnm=None):
     if pkgnm is None:
         pkgnm = self.name
     arch = carchive.CArchive()
     toc = []
     pytoc = []
     for nm, path, typ in self.toc.toList():
         compress = self._cdict[typ]
         if typ == 'b' or (self.usefullname and typ in 'ms'):
             nm = os.path.basename(path)
         if typ == 'm':
             pytoc.append((nm, path, compress, typ))
         else:
             toc.append((nm, path, compress, typ))
     toc = toc + archivebuilder.GetCompiled(pytoc)
     arch.build(pkgnm, toc)
     return arch
コード例 #4
0
ファイル: Build.py プロジェクト: myselfhimself/multitunneler
 def assemble(self):
     print "building PKG", os.path.basename(self.name)
     trash = []
     mytoc = []
     toc = TOC()
     for item in self.toc:
         inm, fnm, typ = item
         if typ == 'EXTENSION':
             binext = os.path.splitext(fnm)[1]
             if not os.path.splitext(inm)[1] == binext:
                 inm = inm + binext
         toc.append((inm, fnm, typ))
     seen = {}
     for inm, fnm, typ in toc:
         if typ in ('BINARY', 'EXTENSION'):
             if self.exclude_binaries:
                 self.dependencies.append((inm, fnm, typ))
             else:
                 fnm = checkCache(
                     fnm, self.strip_binaries, self.upx_binaries
                     and (iswin or cygwin) and config['hasUPX'])
                 # Avoid importing the same binary extension twice. This might
                 # happen if they come from different sources (eg. once from
                 # binary dependence, and once from direct import).
                 if typ == 'BINARY' and seen.has_key(fnm):
                     continue
                 seen[fnm] = 1
                 mytoc.append((inm, fnm, self.cdict.get(typ, 0),
                               self.xformdict.get(typ, 'b')))
         elif typ == 'OPTION':
             mytoc.append((inm, '', 0, 'o'))
         else:
             mytoc.append((inm, fnm, self.cdict.get(typ, 0),
                           self.xformdict.get(typ, 'b')))
     archive = carchive.CArchive()
     archive.build(self.name, mytoc)
     outf = open(self.out, 'w')
     pprint.pprint((self.name, self.cdict, self.toc, self.exclude_binaries,
                    self.strip_binaries, self.upx_binaries), outf)
     outf.close()
     for item in trash:
         os.remove(item)
     return 1
コード例 #5
0
 def assemble(self):
     print "building PKG", os.path.basename(self.name)
     trash = []
     mytoc = []
     toc = TOC()
     for item in self.toc:
         inm, fnm, typ = item
         if typ == 'EXTENSION':
             inm = fixextension(inm, fnm)
         toc.append((inm, fnm, typ))
     for inm, fnm, typ in toc:
         if typ in ('BINARY', 'EXTENSION', 'LINK'):
             if self.exclude_binaries:
                 self.dependencies.append((inm, fnm, typ))
             elif typ == 'LINK':
                 mytoc.append((fnm + ':' + inm, '', 0, 'l'))
             else:
                 fnm = checkCache(
                     fnm, self.strip_binaries, self.upx_binaries
                     and (iswin or cygwin) and config['hasUPX'])
                 mytoc.append((inm, fnm, self.cdict.get(typ, 0),
                               self.xformdict.get(typ, 'b')))
         elif typ == 'OPTION':
             mytoc.append((inm, '', 0, 'o'))
         else:
             mytoc.append((inm, fnm, self.cdict.get(typ, 0),
                           self.xformdict.get(typ, 'b')))
     archive = carchive.CArchive()
     archive.build(self.name, mytoc)
     outf = open(self.out, 'w')
     pprint.pprint((self.name, self.cdict, self.toc, self.exclude_binaries,
                    self.strip_binaries, self.upx_binaries), outf)
     outf.close()
     for item in trash:
         os.remove(item)
     return 1
コード例 #6
0
ファイル: ArchiveViewer.py プロジェクト: tillwf/artub
    parent = stack[-1][1]
    try:
        return parent.openEmbedded(nm)
    except KeyError, e:
        return None
    except (ValueError, RuntimeError):
        ndx = parent.toc.find(nm)
        dpos, dlen, ulen, flag, typcd, nm = parent.toc[ndx]
        x, data = parent.extract(ndx)
        tfnm = tempfile.mktemp()
        cleanup.append(tfnm)
        open(tfnm, 'wb').write(data)
        if typcd == 'z':
            return ZlibArchive(tfnm)
        else:
            return carchive.CArchive(tfnm)


def getData(nm, arch):
    if type(arch.toc) is type({}):
        (ispkg, pos, lngth) = arch.toc.get(nm, (0, None, 0))
        if pos is None:
            return None
        arch.lib.seek(arch.start + pos)
        return zlib.decompress(arch.lib.read(lngth))
    ndx = arch.toc.find(nm)
    dpos, dlen, ulen, flag, typcd, nm = arch.toc[ndx]
    x, data = arch.extract(ndx)
    if flag == 1:
        return zlib.decompress(data)
    return data
コード例 #7
0
import carchive
import sys
import os

this = carchive.CArchive(sys.executable)
tk = this.openEmbedded('tk.pkg')
targetdir = os.environ['_MEIPASS2']
for fnm in tk.contents():
    stuff = tk.extract(fnm)[1]
    outnm = os.path.join(targetdir, fnm)
    dirnm = os.path.dirname(outnm)
    if not os.path.exists(dirnm):
        os.makedirs(dirnm)
    open(outnm, 'wb').write(stuff)
tk = None