コード例 #1
0
 def getmod(self, nm, newmod=imp.new_module):
     rslt = self.pyz.extract(nm)
     if rslt is None:
         return None
     ispkg, co = rslt
     mod = newmod(nm)
     try:
         mod.__file__ = co.co_filename
     except AttributeError:
         raise ImportError, "PYZ entry '%s' (%s) is not a valid code object" % (nm, repr(co))
     if ispkg:
         if _environ.has_key("_MEIPASS2"):
             localpath = _environ["_MEIPASS2"][:-1]
         else:
             localpath = iu._os_path_dirname(self.path)
         mod.__path__ = [self.path, localpath, iu._os_path_dirname(mod.__file__)]
         # print "PYZOwner setting %s's __path__: %s" % (nm, mod.__path__)
         importer = iu.PathImportDirector(
             mod.__path__,
             {self.path: PkgInPYZImporter(nm, self), localpath: ExtInPkgImporter(localpath, nm)},
             [iu.DirOwner],
         )
         mod.__importsub__ = importer.getmod
     mod.__co__ = co
     return mod
コード例 #2
0
 def getmod(self, nm, newmod=imp.new_module):
     rslt = self.pyz.extract(nm)
     if rslt is None:
         return None
     ispkg, co = rslt
     mod = newmod(nm)
     try:
         mod.__file__ = co.co_filename
     except AttributeError:
         raise ImportError, "PYZ entry '%s' (%s) is not a valid code object" % (
             nm, repr(co))
     if ispkg:
         if _environ.has_key('_MEIPASS2'):
             localpath = _environ['_MEIPASS2'][:-1]
         else:
             localpath = iu._os_path_dirname(self.path)
         mod.__path__ = [
             self.path, localpath,
             iu._os_path_dirname(mod.__file__)
         ]
         #print "PYZOwner setting %s's __path__: %s" % (nm, mod.__path__)
         importer = iu.PathImportDirector(
             mod.__path__, {
                 self.path: PkgInPYZImporter(nm, self),
                 localpath: ExtInPkgImporter(localpath, nm)
             }, [iu.DirOwner])
         mod.__importsub__ = importer.getmod
     mod.__co__ = co
     return mod
コード例 #3
0
    def getmod(self, nm, newmod=imp.new_module):
        rslt = self.pyz.extract(nm)
        if rslt is None:
            return None
        ispkg, bytecode = rslt
        mod = newmod(nm)

        # Replace bytecode.co_filename by something more meaningful:
        # e.g. /absolute/path/frozen_executable?12345/os/path.pyc
        # Paths from developer machine are masked.
        try:
            # Python packages points to files  __init__.pyc.
            if ispkg:
                mod.__file__ = iu._os_path_join(
                    iu._os_path_join(self.path, nm.replace('.', iu._os_sep)),
                    '__init__.pyc')
            else:
                mod.__file__ = iu._os_path_join(
                    self.path,
                    nm.replace('.', iu._os_sep) + '.pyc')
        except AttributeError:
            raise ImportError(
                "PYZ entry '%s' (%s) is not a valid code object" %
                (nm, repr(bytecode)))

        # Python has modules and packages. A Python package is container
        # for several modules or packages.
        if ispkg:

            if '_MEIPASS2' in _environ:
                localpath = _environ['_MEIPASS2'][:-1]
            else:
                localpath = iu._os_path_dirname(self.path)

            # A python packages has to have __path__ attribute.
            mod.__path__ = [
                iu._os_path_dirname(mod.__file__),
                self.path,
                localpath,
            ]

            debug("PYZOwner setting %s's __path__: %s" % (nm, mod.__path__))

            importer = iu.PathImportDirector(
                mod.__path__, {
                    self.path: PkgInPYZImporter(nm, self),
                    localpath: ExtInPkgImporter(localpath, nm)
                }, [iu.DirOwner])
            mod.__importsub__ = importer.getmod

        mod.__co__ = bytecode
        return mod
コード例 #4
0
ファイル: archive.py プロジェクト: CNCBASHER/LasaurApp
    def getmod(self, nm, newmod=imp.new_module):
        rslt = self.pyz.extract(nm)
        if rslt is None:
            return None
        ispkg, bytecode = rslt
        mod = newmod(nm)

        # Replace bytecode.co_filename by something more meaningful:
        # e.g. /absolute/path/frozen_executable?12345/os/path.pyc
        # Paths from developer machine are masked.
        try:
            # Python packages points to files  __init__.pyc.
            if ispkg:
                mod.__file__ = iu._os_path_join(iu._os_path_join(self.path,
                    nm.replace('.', iu._os_sep)), '__init__.pyc')
            else:
                mod.__file__ = iu._os_path_join(self.path,
                    nm.replace('.', iu._os_sep) + '.pyc')
        except AttributeError:
            raise ImportError("PYZ entry '%s' (%s) is not a valid code object"
                % (nm, repr(bytecode)))

        # Python has modules and packages. A Python package is container
        # for several modules or packages.
        if ispkg:

            if '_MEIPASS2' in _environ:
                localpath = _environ['_MEIPASS2'][:-1]
            else:
                localpath = iu._os_path_dirname(self.path)

            # A python packages has to have __path__ attribute.
            mod.__path__ = [iu._os_path_dirname(mod.__file__), self.path, localpath,
                ]

            debug("PYZOwner setting %s's __path__: %s" % (nm, mod.__path__))

            importer = iu.PathImportDirector(mod.__path__,
                {self.path: PkgInPYZImporter(nm, self),
                localpath: ExtInPkgImporter(localpath, nm)},
                [iu.DirOwner])
            mod.__importsub__ = importer.getmod

        mod.__co__ = bytecode
        return mod
コード例 #5
0
ファイル: archive.py プロジェクト: jgold1920/softChord
    def getmod(self, nm, newmod=imp.new_module):
        rslt = self.pyz.extract(nm)
        if rslt is None:
            return None
        ispkg, bytecode = rslt
        mod = newmod(nm)

        # Replace bytecode.co_filename by something more meaningful:
        # e.g. /absolute/path/frozen_executable?12345/os/path.pyc
        # Paths from developer machine are masked.
        try:
            # Python packages points to files  __init__.pyc.
            if ispkg:
                mod.__file__ = iu._os_path_join(iu._os_path_join(self.path,
                    nm.replace('.', iu._os_sep)), '__init__.pyc')
            else:
                mod.__file__ = iu._os_path_join(self.path,
                    nm.replace('.', iu._os_sep) + '.pyc')
        except AttributeError:
            raise ImportError("PYZ entry '%s' (%s) is not a valid code object"
                % (nm, repr(bytecode)))

        # Python has modules and packages. A Python package is container
        # for several modules or packages.
        if ispkg:
            # Since PYTHONHOME is set in bootloader, 'sys.prefix' points to the
            # correct path where PyInstaller should find bundled dynamic
            # libraries. In one-file mode it points to the tmp directory where
            # bundled files are extracted at execution time.
            localpath = sys.prefix

            # A python packages has to have __path__ attribute.
            mod.__path__ = [iu._os_path_dirname(mod.__file__), self.path, localpath,
                ]

            debug("PYZOwner setting %s's __path__: %s" % (nm, mod.__path__))

            importer = iu.PathImportDirector(mod.__path__,
                {self.path: PkgInPYZImporter(nm, self),
                localpath: ExtInPkgImporter(localpath, nm)},
                [iu.DirOwner])
            mod.__importsub__ = importer.getmod

        mod.__co__ = bytecode
        return mod
コード例 #6
0
                    print e.args
                    raise
            elif pyc:
                stuff = self.fs.open(pyc[0]).read()
                try:
                    co = loadco(stuff[8:])
                    break
                except (ValueError, EOFError):
                    pyc = None
            else:
                return None
        mod = newmod(nm)
        mod.__file__ = co.co_filename
        if ispkg:
            # print "***a package may be involved"
            localpath = iu._os_path_dirname(self.fspath)
            # print "localpath: %s" % localpath
            vfspath = "vfs://<%s>%s" % (self.fskey, localpath)
            mod.__path__ = [self.path, pkgpth, iu._os_path_dirname(mod.__file__)]
            subimporter = iu.PathImportDirector(
                mod.__path__,
                {self.path: PkgInVFSImporter(nm, self), vfspath: ExtInPkgImporter(vfspath, nm)},
                [VFSOwner],
            )
            mod.__importsub__ = subimporter.getmod
        mod.__co__ = co
        # print "returning: %s" % mod
        return mod


class PkgInVFSImporter:
コード例 #7
0
             print e.args
             raise
     elif pyc:
         stuff = self.fs.open(pyc[0]).read()
         try:
             co = loadco(stuff[8:])
             break
         except (ValueError, EOFError):
             pyc = None
     else:
         return None
 mod = newmod(nm)
 mod.__file__ = co.co_filename
 if ispkg:
     #print "***a package may be involved"
     localpath = iu._os_path_dirname(self.fspath)
     #print "localpath: %s" % localpath
     vfspath = "vfs://<%s>%s" % (self.fskey, localpath)
     mod.__path__ = [
         self.path, pkgpth,
         iu._os_path_dirname(mod.__file__)
     ]
     subimporter = iu.PathImportDirector(
         mod.__path__, {
             self.path: PkgInVFSImporter(nm, self),
             vfspath: ExtInPkgImporter(vfspath, nm)
         }, [VFSOwner])
     mod.__importsub__ = subimporter.getmod
 mod.__co__ = co
 #print "returning: %s" % mod
 return mod
コード例 #8
0
                    print e.args
                    raise
            elif pyc:
                stuff = self.fs.open(pyc[0]).read()
                try:
                    co = loadco(stuff[8:])
                    break
                except (ValueError, EOFError):
                    pyc = None
            else:
                return None
        mod = newmod(nm)
        mod.__file__ = co.co_filename
        if ispkg:
            #print "***a package may be involved"
            localpath=iu._os_path_dirname(self.fspath)
            #print "localpath: %s" % localpath
            vfspath="vfs://<%s>%s" % (self.fskey, localpath)
            mod.__path__ = [self.path, pkgpth, iu._os_path_dirname(mod.__file__)]
            subimporter = iu.PathImportDirector(mod.__path__,
                                                {self.path:PkgInVFSImporter(nm, self),
                                                 vfspath:ExtInPkgImporter(vfspath, nm)},
                                                [VFSOwner])
            mod.__importsub__ = subimporter.getmod
        mod.__co__ = co
        #print "returning: %s" % mod
        return mod        

class PkgInVFSImporter:
    def __init__(self, name, owner):
        self.name = name