本文整理汇总了Python中PyInstaller.building.datastruct.TOC类的典型用法代码示例。如果您正苦于以下问题:Python TOC类的具体用法?Python TOC怎么用?Python TOC使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TOC类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insert_other_case_pymodule
def test_insert_other_case_pymodule():
# python modules should not use C-I comparisons. Both 'encodings' and
# 'EnCodIngs' should be added.
toc = TOC(ELEMS1)
elem = ('EnCodIngs', '/usr/lib/python2.7/encodings.py', 'PYMODULE')
toc.insert(1, elem)
expected = list(ELEMS1)
expected.insert(1, elem)
assert toc == expected
示例2: test_insert_other_case_mixed
def test_insert_other_case_mixed():
# If a binary file is added with the same filename as an existing pymodule,
# it should not be added
toc = TOC(ELEMS1)
elem = ('EnCodIngs', '/usr/lib/python2.7/encodings.py', 'BINARY')
toc.insert(1, elem)
expected = list(ELEMS1)
assert toc == expected
示例3: __init__
def __init__(self, *tocs, **kwargs):
"""
tocs
One or more TOCs (Tables of Contents), normally an
Analysis.pure.
If this TOC has an attribute `_code_cache`, this is
expected to be a dict of module code objects from
ModuleGraph.
kwargs
Possible keywork arguments:
name
A filename for the .pyz. Normally not needed, as the generated
name will do fine.
cipher
The block cipher that will be used to encrypt Python bytecode.
"""
from ..config import CONF
Target.__init__(self)
name = kwargs.get('name', None)
cipher = kwargs.get('cipher', None)
self.toc = TOC()
# If available, use code objects directly from ModuleGraph to
# speed up PyInstaller.
self.code_dict = {}
for t in tocs:
self.toc.extend(t)
self.code_dict.update(getattr(t, '_code_cache', {}))
# Paths to remove from filenames embedded in code objects
self.replace_paths = sys.path + CONF['pathex']
# Make sure paths end with os.sep
self.replace_paths = [os.path.join(f, '') for f in self.replace_paths]
self.name = name
if name is None:
self.name = os.path.splitext(self.tocfilename)[0] + '.pyz'
# PyInstaller bootstrapping modules.
self.dependencies = get_bootstrap_modules()
# Bundle the crypto key.
self.cipher = cipher
if cipher:
key_file = ('pyimod00_crypto_key',
os.path.join(CONF['workpath'], 'pyimod00_crypto_key.pyc'),
'PYMODULE')
# Insert the key as the first module in the list. The key module contains
# just variables and does not depend on other modules.
self.dependencies.insert(0, key_file)
# Compile the top-level modules so that they end up in the CArchive and can be
# imported by the bootstrap script.
self.dependencies = misc.compile_py_files(self.dependencies, CONF['workpath'])
self.__postinit__()
示例4: __init__
def __init__(self, *args, **kws):
"""
args
One or more arguments that are either TOCs Targets.
kws
Possible keywork arguments:
name
The name of the directory to be built.
"""
from ..config import CONF
Target.__init__(self)
self.strip_binaries = kws.get('strip', False)
self.console = True
if CONF['hasUPX']:
self.upx_binaries = kws.get('upx', False)
else:
self.upx_binaries = False
self.name = kws.get('name')
# Old .spec format included in 'name' the path where to collect files
# for the created app.
# app. New format includes only directory name.
#
# The 'name' directory is created in DISTPATH and necessary files are
# then collected to this directory.
self.name = os.path.join(CONF['distpath'], os.path.basename(self.name))
self.toc = TOC()
for arg in args:
if isinstance(arg, TOC):
self.toc.extend(arg)
elif isinstance(arg, Target):
self.toc.append((os.path.basename(arg.name), arg.name, arg.typ))
if isinstance(arg, EXE):
self.console = arg.console
for tocnm, fnm, typ in arg.toc:
if tocnm == os.path.basename(arg.name) + ".manifest":
self.toc.append((tocnm, fnm, typ))
if not arg.append_pkg:
self.toc.append((os.path.basename(arg.pkgname), arg.pkgname, 'PKG'))
self.toc.extend(arg.dependencies)
else:
self.toc.extend(arg)
self.__postinit__()
示例5: __init__
def __init__(self, *args, **kwargs):
"""
args
One or more arguments that are either TOCs Targets.
kwargs
Possible keywork arguments:
console
On Windows or OSX governs whether to use the console executable
or the windowed executable. Always True on Linux/Unix (always
console executable - it does not matter there).
debug
Setting to True gives you progress mesages from the executable
(for console=False there will be annoying MessageBoxes on Windows).
name
The filename for the executable. On Windows suffix '.exe' is
appended.
exclude_binaries
Forwarded to the PKG the EXE builds.
icon
Windows or OSX only. icon='myicon.ico' to use an icon file or
icon='notepad.exe,0' to grab an icon resource.
version
Windows only. version='myversion.txt'. Use grab_version.py to get
a version resource from an executable and then edit the output to
create your own. (The syntax of version resources is so arcane
that I wouldn't attempt to write one from scratch).
uac_admin
Windows only. Setting to True creates a Manifest with will request
elevation upon application restart
uac_uiaccess
Windows only. Setting to True allows an elevated application to
work with Remote Desktop
"""
from ..config import CONF
Target.__init__(self)
# Available options for EXE in .spec files.
self.exclude_binaries = kwargs.get('exclude_binaries', False)
self.console = kwargs.get('console', True)
self.debug = kwargs.get('debug', False)
self.name = kwargs.get('name', None)
self.icon = kwargs.get('icon', None)
self.versrsrc = kwargs.get('version', None)
self.manifest = kwargs.get('manifest', None)
self.resources = kwargs.get('resources', [])
self.strip = kwargs.get('strip', False)
# If ``append_pkg`` is false, the archive will not be appended
# to the exe, but copied beside it.
self.append_pkg = kwargs.get('append_pkg', True)
# On Windows allows the exe to request admin privileges.
self.uac_admin = kwargs.get('uac_admin', False)
self.uac_uiaccess = kwargs.get('uac_uiaccess', False)
if CONF['hasUPX']:
self.upx = kwargs.get('upx', False)
else:
self.upx = False
# Old .spec format included in 'name' the path where to put created
# app. New format includes only exename.
#
# Ignore fullpath in the 'name' and prepend DISTPATH or WORKPATH.
# DISTPATH - onefile
# WORKPATH - onedir
if self.exclude_binaries:
# onedir mode - create executable in WORKPATH.
self.name = os.path.join(CONF['workpath'], os.path.basename(self.name))
else:
# onefile mode - create executable in DISTPATH.
self.name = os.path.join(CONF['distpath'], os.path.basename(self.name))
# Old .spec format included on Windows in 'name' .exe suffix.
if is_win or is_cygwin:
# Append .exe suffix if it is not already there.
if not self.name.endswith('.exe'):
self.name += '.exe'
base_name = os.path.splitext(os.path.basename(self.name))[0]
else:
base_name = os.path.basename(self.name)
self.pkgname = base_name + '.pkg'
self.toc = TOC()
for arg in args:
if isinstance(arg, TOC):
self.toc.extend(arg)
elif isinstance(arg, Target):
self.toc.append((os.path.basename(arg.name), arg.name, arg.typ))
self.toc.extend(arg.dependencies)
else:
self.toc.extend(arg)
if is_win:
filename = os.path.join(CONF['workpath'], CONF['specnm'] + ".exe.manifest")
self.manifest = winmanifest.create_manifest(filename, self.manifest,
self.console, self.uac_admin, self.uac_uiaccess)
manifest_filename = os.path.basename(self.name) + ".manifest"
#.........这里部分代码省略.........
示例6: EXE
class EXE(Target):
"""
Creates the final executable of the frozen app.
This bundles all necessary files together.
"""
typ = 'EXECUTABLE'
def __init__(self, *args, **kwargs):
"""
args
One or more arguments that are either TOCs Targets.
kwargs
Possible keywork arguments:
console
On Windows or OSX governs whether to use the console executable
or the windowed executable. Always True on Linux/Unix (always
console executable - it does not matter there).
debug
Setting to True gives you progress mesages from the executable
(for console=False there will be annoying MessageBoxes on Windows).
name
The filename for the executable. On Windows suffix '.exe' is
appended.
exclude_binaries
Forwarded to the PKG the EXE builds.
icon
Windows or OSX only. icon='myicon.ico' to use an icon file or
icon='notepad.exe,0' to grab an icon resource.
version
Windows only. version='myversion.txt'. Use grab_version.py to get
a version resource from an executable and then edit the output to
create your own. (The syntax of version resources is so arcane
that I wouldn't attempt to write one from scratch).
uac_admin
Windows only. Setting to True creates a Manifest with will request
elevation upon application restart
uac_uiaccess
Windows only. Setting to True allows an elevated application to
work with Remote Desktop
"""
from ..config import CONF
Target.__init__(self)
# Available options for EXE in .spec files.
self.exclude_binaries = kwargs.get('exclude_binaries', False)
self.console = kwargs.get('console', True)
self.debug = kwargs.get('debug', False)
self.name = kwargs.get('name', None)
self.icon = kwargs.get('icon', None)
self.versrsrc = kwargs.get('version', None)
self.manifest = kwargs.get('manifest', None)
self.resources = kwargs.get('resources', [])
self.strip = kwargs.get('strip', False)
# If ``append_pkg`` is false, the archive will not be appended
# to the exe, but copied beside it.
self.append_pkg = kwargs.get('append_pkg', True)
# On Windows allows the exe to request admin privileges.
self.uac_admin = kwargs.get('uac_admin', False)
self.uac_uiaccess = kwargs.get('uac_uiaccess', False)
if CONF['hasUPX']:
self.upx = kwargs.get('upx', False)
else:
self.upx = False
# Old .spec format included in 'name' the path where to put created
# app. New format includes only exename.
#
# Ignore fullpath in the 'name' and prepend DISTPATH or WORKPATH.
# DISTPATH - onefile
# WORKPATH - onedir
if self.exclude_binaries:
# onedir mode - create executable in WORKPATH.
self.name = os.path.join(CONF['workpath'], os.path.basename(self.name))
else:
# onefile mode - create executable in DISTPATH.
self.name = os.path.join(CONF['distpath'], os.path.basename(self.name))
# Old .spec format included on Windows in 'name' .exe suffix.
if is_win or is_cygwin:
# Append .exe suffix if it is not already there.
if not self.name.endswith('.exe'):
self.name += '.exe'
base_name = os.path.splitext(os.path.basename(self.name))[0]
else:
base_name = os.path.basename(self.name)
self.pkgname = base_name + '.pkg'
self.toc = TOC()
for arg in args:
if isinstance(arg, TOC):
self.toc.extend(arg)
elif isinstance(arg, Target):
self.toc.append((os.path.basename(arg.name), arg.name, arg.typ))
self.toc.extend(arg.dependencies)
else:
self.toc.extend(arg)
#.........这里部分代码省略.........
示例7: PYZ
class PYZ(Target):
"""
Creates a ZlibArchive that contains all pure Python modules.
"""
typ = 'PYZ'
def __init__(self, *tocs, **kwargs):
"""
tocs
One or more TOCs (Tables of Contents), normally an
Analysis.pure.
If this TOC has an attribute `_code_cache`, this is
expected to be a dict of module code objects from
ModuleGraph.
kwargs
Possible keywork arguments:
name
A filename for the .pyz. Normally not needed, as the generated
name will do fine.
cipher
The block cipher that will be used to encrypt Python bytecode.
"""
from ..config import CONF
Target.__init__(self)
name = kwargs.get('name', None)
cipher = kwargs.get('cipher', None)
self.toc = TOC()
# If available, use code objects directly from ModuleGraph to
# speed up PyInstaller.
self.code_dict = {}
for t in tocs:
self.toc.extend(t)
self.code_dict.update(getattr(t, '_code_cache', {}))
self.name = name
if name is None:
self.name = os.path.splitext(self.tocfilename)[0] + '.pyz'
# PyInstaller bootstrapping modules.
self.dependencies = get_bootstrap_modules()
# Bundle the crypto key.
self.cipher = cipher
if cipher:
key_file = ('pyimod00_crypto_key',
os.path.join(CONF['workpath'], 'pyimod00_crypto_key.pyc'),
'PYMODULE')
# Insert the key as the first module in the list. The key module contains
# just variables and does not depend on other modules.
self.dependencies.insert(0, key_file)
# Compile the top-level modules so that they end up in the CArchive and can be
# imported by the bootstrap script.
self.dependencies = misc.compile_py_files(self.dependencies, CONF['workpath'])
self.__postinit__()
_GUTS = (# input parameters
('name', _check_guts_eq),
('toc', _check_guts_toc), # todo: pyc=1
# no calculated/analysed values
)
def _check_guts(self, data, last_build):
if Target._check_guts(self, data, last_build):
return True
return False
def assemble(self):
logger.info("Building PYZ (ZlibArchive) %s", self.name)
# Do not bundle PyInstaller bootstrap modules into PYZ archive.
toc = self.toc - self.dependencies
for entry in toc[:]:
if not entry[0] in self.code_dict and entry[2] == 'PYMODULE':
# For some reason the code-object, modulegraph created
# is not available. Recreate it
try:
self.code_dict[entry[0]] = get_code_object(entry[0], entry[1])
except SyntaxError:
# Exclude the module in case this is code meant for a newer Python version.
toc.remove(entry)
# sort content alphabetically to support reproducible builds
toc.sort()
# Remove leading parts of paths in code objects
self.code_dict = {
key: strip_paths_in_code(code)
for key, code in self.code_dict.items()
}
pyz = ZlibArchiveWriter(self.name, toc, code_dict=self.code_dict, cipher=self.cipher)
logger.info("Building PYZ (ZlibArchive) %s completed successfully.",
self.name)
示例8: test_extend_existing
def test_extend_existing():
toc = TOC(ELEMS1)
toc.extend(ELEMS1)
expected = list(ELEMS1)
assert toc == expected
示例9: test_extend
def test_extend():
toc = TOC(ELEMS1)
toc.extend(ELEMS2)
expected = list(ELEMS1)
expected.extend(ELEMS2)
assert toc == expected
示例10: test_insert_keep_filename
def test_insert_keep_filename():
# name in TOC should be the same as the one added
toc = TOC()
entry = ('EnCodIngs', '/usr/lib/python2.7/encodings.py', 'BINARY')
toc.insert(1, entry)
assert toc[0][0] == entry[0]
示例11: test_insert
def test_insert():
toc = TOC(ELEMS1)
toc.insert(1, ('li-la-lu', '/home/myself/li-la-su', 'SOMETHING'))
expected = list(ELEMS1)
expected.insert(1, ('li-la-lu', '/home/myself/li-la-su', 'SOMETHING'))
assert toc == expected
示例12: test_append_existing
def test_append_existing():
toc = TOC(ELEMS1)
toc.append(ELEMS1[-1])
expected = list(ELEMS1)
assert toc == expected
示例13: test_append
def test_append():
toc = TOC(ELEMS1)
toc.append(('li-la-lu', '/home/myself/li-la-su', 'SOMETHING'))
expected = list(ELEMS1)
expected.append(('li-la-lu', '/home/myself/li-la-su', 'SOMETHING'))
assert toc == expected
示例14: test_insert_other_case_binary
def test_insert_other_case_binary():
# binary files should use C-I comparisons. 'LiBrEADlInE.so.6' should not be added.
toc = TOC(ELEMS1)
toc.insert(1, ('LiBrEADlInE.so.6', '/lib64/libreadline.so.6', 'BINARY'))
expected = list(ELEMS1)
assert toc == expected
示例15: PYZ
class PYZ(Target):
"""
Creates a ZlibArchive that contains all pure Python modules.
"""
typ = 'PYZ'
def __init__(self, *tocs, **kwargs):
"""
tocs
One or more TOCs (Tables of Contents), normally an
Analysis.pure.
If this TOC has an attribute `_code_cache`, this is
expected to be a dict of module code objects from
ModuleGraph.
kwargs
Possible keywork arguments:
name
A filename for the .pyz. Normally not needed, as the generated
name will do fine.
cipher
The block cipher that will be used to encrypt Python bytecode.
"""
from ..config import CONF
Target.__init__(self)
name = kwargs.get('name', None)
cipher = kwargs.get('cipher', None)
self.toc = TOC()
# If available, use code objects directly from ModuleGraph to
# speed up PyInstaller.
self.code_dict = {}
for t in tocs:
self.toc.extend(t)
self.code_dict.update(getattr(t, '_code_cache', {}))
self.name = name
if name is None:
self.name = os.path.splitext(self.tocfilename)[0] + '.pyz'
# PyInstaller bootstrapping modules.
self.dependencies = get_bootstrap_modules()
# Bundle the crypto key.
self.cipher = cipher
if cipher:
key_file = ('pyimod00_crypto_key',
os.path.join(CONF['workpath'], 'pyimod00_crypto_key.pyc'),
'PYMODULE')
# Insert the key as the first module in the list. The key module contains
# just variables and does not depend on other modules.
self.dependencies.insert(0, key_file)
# Compile the top-level modules so that they end up in the CArchive and can be
# imported by the bootstrap script.
self.dependencies = misc.compile_py_files(self.dependencies, CONF['workpath'])
self.__postinit__()
_GUTS = (# input parameters
('name', _check_guts_eq),
('toc', _check_guts_toc), # todo: pyc=1
# no calculated/analysed values
)
def _check_guts(self, data, last_build):
if Target._check_guts(self, data, last_build):
return True
return False
# TODO Could this function be merged with 'PyInstaller.utils.misc:get_code_object()'?
def __get_code(self, modname, filename):
"""
Get the code-object for a module.
This is a extra-simple version for compiling a module. It's
not worth spending more effort here, as it is only used in the
rare case if outXX-Analysis.toc exists, but outXX-PYZ.toc does
not.
"""
def load_code(modname, filename):
path_item = os.path.dirname(filename)
if os.path.basename(filename).startswith('__init__.py'):
# this is a package
path_item = os.path.dirname(path_item)
if os.path.basename(path_item) == '__pycache__':
path_item = os.path.dirname(path_item)
importer = pkgutil.get_importer(path_item)
package, _, modname = modname.rpartition('.')
if sys.version_info >= (3,3) and hasattr(importer, 'find_loader'):
loader, portions = importer.find_loader(modname)
else:
loader = importer.find_module(modname)
portions = []
assert loader and hasattr(loader, 'get_code')
logger.debug('Compiling %s', filename)
return loader.get_code(modname)
try:
#.........这里部分代码省略.........