def _run():
global __file__
import os, site
sys.frozen = 'macosx_app'
base = os.environ['RESOURCEPATH']
argv0 = os.path.basename(os.environ['ARGVZERO'])
script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT)
path = os.path.join(base, script)
sys.argv[0] = __file__ = path
if sys.version_info[0] == 2:
with open(path, 'rU') as fp:
source = fp.read() + "\n"
else:
with open(path, 'rb') as fp:
encoding = guess_encoding(fp)
with open(path, 'r', encoding=encoding) as fp:
source = fp.read() + '\n'
exec(compile(source, path, 'exec'), globals(), globals())
python类frozen()的实例源码
def main():
global __file__
# Needed on OS X <= 10.8, which passes -psn_... as a command line arg when
# starting via launch services
for arg in tuple(sys.argv[1:]):
if arg.startswith('-psn_'):
sys.argv.remove(arg)
base = sys.resourcepath
sys.frozen = 'macosx_app'
sys.new_app_bundle = True
abs__file__()
add_calibre_vars(base)
addsitedir(sys.site_packages)
if sys.calibre_is_gui_app and not (
sys.stdout.isatty() or sys.stderr.isatty() or sys.stdin.isatty()):
nuke_stdout()
return run_entry_point()
def main():
sys.frozen = 'windows_exe'
sys.setdefaultencoding('utf-8')
aliasmbcs()
sys.meta_path.insert(0, PydImporter())
sys.path_importer_cache.clear()
import linecache
def fake_getline(filename, lineno, module_globals=None):
return ''
linecache.orig_getline = linecache.getline
linecache.getline = fake_getline
abs__file__()
add_calibre_vars()
# Needed for pywintypes to be able to load its DLL
sys.path.append(os.path.join(sys.app_dir, 'app', 'DLLs'))
return run_entry_point()
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
def _run():
global __file__
import os, site
sys.frozen = 'macosx_app'
base = os.environ['RESOURCEPATH']
argv0 = os.path.basename(os.environ['ARGVZERO'])
script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT)
path = os.path.join(base, script)
sys.argv[0] = __file__ = path
if sys.version_info[0] == 2:
with open(path, 'rU') as fp:
source = fp.read() + "\n"
else:
with open(path, 'rb') as fp:
encoding = guess_encoding(fp)
with open(path, 'r', encoding=encoding) as fp:
source = fp.read() + '\n'
BOM=b'\xef\xbb\xbf'.decode('utf-8')
if source.startswith(BOM):
source = source[1:]
exec(compile(source, path, 'exec'), globals(), globals())
def main():
try:
if not is_admin():
try:
elevate([sys.executable, os.path.abspath(sys.argv[0])])
except NotImplementedError as exc:
if sys.frozen:
raise
print('note:', exc)
import c4dinstaller
res = c4dinstaller.main()
except Exception as exc:
traceback.print_exc()
fatal(traceback.format_exc())
raise
else:
sys.exit(res)
def initForm(self):
self.dataFile = os.path.basename(sys.argv[0]) + '.data'
self.dataFile = os.path.join(os.path.dirname(sys.argv[0]), self.dataFile)
if not os.path.isfile(self.dataFile):
if sys.frozen:
fatal('"{}" does not exist'.format(self.dataFile))
# If we're not in a frozen environment (built with PyInstaller),
# for testing purposes we still want the uninstaller to run.
self.dataFile = None
self.welcomePage = WelcomePage(self)
self.uninstallPage = UninstallPage(self)
self.stackedPages.addWidget(self.welcomePage)
self.stackedPages.addWidget(self.uninstallPage)
self.setWindowTitle(self.ls('uninstall.title'))
self.setCurrentPage(self.welcomePage)
super().initForm()
def is_multiprocessing_available():
if (pycam.Utils.get_platform() == pycam.Utils.OSPlatform.WINDOWS) and \
hasattr(sys, "frozen") and sys.frozen:
return False
try:
import multiprocessing
# try to initialize a semaphore - this can trigger shm access failures
# (e.g. on Debian Lenny with Python 2.6.6)
multiprocessing.Semaphore()
return True
except ImportError:
if "missing_module" not in __issued_warnings:
log.info("Python's multiprocessing module is missing: disabling parallel processing")
__issued_warnings.append("missing_module")
except OSError:
if "shm_access_failed" not in __issued_warnings:
log.info("Python's multiprocessing module failed to acquire read/write access to "
"shared memory (shm) - disabling parallel processing")
__issued_warnings.append("shm_access_failed")
return False
def init():
import sys
import os
import os.path
if sys.version_info.major != 2:
sys.exit('Python 2 is required to run this program')
fdir = None
if hasattr(sys, "frozen") and \
sys.frozen in ("windows_exe", "console_exe"):
fdir = os.path.dirname(os.path.abspath(sys.executable))
sys.path.append(fdir)
fdir = os.path.join(fdir, '..')
else:
fdir = os.path.dirname(__file__)
with open(os.path.join(fdir, 'apikey.cfg')) as f:
exec(f.read())
srv = locals().get('SERVER')
from facepp import API
return API(API_KEY, API_SECRET, srv = srv)
__boot__.py 文件源码
项目:Mosaic-for-Lego-Digital-Designer
作者: JosephSamela
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def _run():
global __file__
import os, site
sys.frozen = 'macosx_app'
argv0 = os.path.basename(os.environ['ARGVZERO'])
script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT)
sys.argv[0] = __file__ = script
if sys.version_info[0] == 2:
with open(script, 'rU') as fp:
source = fp.read() + "\n"
else:
with open(script, 'rb') as fp:
encoding = guess_encoding(fp)
with open(script, 'r', encoding=encoding) as fp:
source = fp.read() + '\n'
BOM=b'\xef\xbb\xbf'.decode('utf-8')
if source.startswith(BOM):
source = source[1:]
exec(compile(source, script, 'exec'), globals(), globals())
def __init__(self):
import win32api
win32api.MessageBox(0, "NextID.__init__ started", "NextID.py")
global d
if sys.frozen:
for entry in sys.path:
if entry.find('?') > -1:
here = os.path.dirname(entry.split('?')[0])
break
else:
here = os.getcwd()
else:
here = os.path.dirname(__file__)
self.fnm = os.path.join(here, 'id.cfg')
try:
d = eval(open(self.fnm, 'rU').read()+'\n')
except:
d = {
'systemID': 0xaaaab,
'highID': 0
}
win32api.MessageBox(0, "NextID.__init__ complete", "NextID.py")
def __init__(self, name):
self.msg = ("Failed to load dynlib/dll %r. "
"Most probably this dynlib/dll was not found "
"when the application was frozen.") % name
self.args = (self.msg,)
def _run():
global __file__
import os, site
sys.frozen = 'macosx_app'
base = os.environ['RESOURCEPATH']
argv0 = os.path.basename(os.environ['ARGVZERO'])
script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT)
path = os.path.join(base, script)
sys.argv[0] = __file__ = path
if sys.version_info[0] == 2:
with open(path, 'rU') as fp:
source = fp.read() + "\n"
else:
with open(path, 'rb') as fp:
encoding = guess_encoding(fp)
with open(path, 'r', encoding=encoding) as fp:
source = fp.read() + '\n'
BOM=b'\xef\xbb\xbf'.decode('utf-8')
if source.startswith(BOM):
source = source[1:]
exec(compile(source, path, 'exec'), globals(), globals())
def main():
shell.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = shell.get_config(True)
daemon.daemon_exec(config)
try:
logging.info("starting local at %s:%d" %
(config['local_address'], config['local_port']))
dns_resolver = asyncdns.DNSResolver()
tcp_server = tcprelay.TCPRelay(config, dns_resolver, True)
udp_server = udprelay.UDPRelay(config, dns_resolver, True)
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
tcp_server.add_to_loop(loop)
udp_server.add_to_loop(loop)
def handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
tcp_server.close(next_tick=True)
udp_server.close(next_tick=True)
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)
def test_get_home_dir_2():
"""Testcase for py2exe logic, compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
home_dir = path.get_home_dir(True)
nt.assert_equal(home_dir, unfrozen)
def main():
shell.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = shell.get_config(True)
daemon.daemon_exec(config)
try:
logging.info("starting local at %s:%d" %
(config['local_address'], config['local_port']))
dns_resolver = asyncdns.DNSResolver()
tcp_server = tcprelay.TCPRelay(config, dns_resolver, True)
udp_server = udprelay.UDPRelay(config, dns_resolver, True)
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
tcp_server.add_to_loop(loop)
udp_server.add_to_loop(loop)
def handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
tcp_server.close(next_tick=True)
udp_server.close(next_tick=True)
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
def main():
utils.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = utils.get_config(True)
daemon.daemon_exec(config)
utils.print_shadowsocks()
encrypt.try_cipher(config['password'], config['method'])
try:
logging.info("starting local at %s:%d" %
(config['local_address'], config['local_port']))
dns_resolver = asyncdns.DNSResolver()
tcp_server = tcprelay.TCPRelay(config, dns_resolver, True)
udp_server = udprelay.UDPRelay(config, dns_resolver, True)
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
tcp_server.add_to_loop(loop)
udp_server.add_to_loop(loop)
def handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
tcp_server.close(next_tick=True)
udp_server.close(next_tick=True)
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
loop.run()
except (KeyboardInterrupt, IOError, OSError) as e:
logging.error(e)
if config['verbose']:
import traceback
traceback.print_exc()
os._exit(1)
def initForm(self):
self.initButtonBox()
dataFile = self.installer.dataFile
self.uninstallThread = UninstallThread(dataFile)
self.uninstallThread.progressUpdate.connect(self.on_progressUpdate, Qt.QueuedConnection)
self.becomesVisible.connect(self.on_becomesVisible)
self.buttonClose.setEnabled(False)
self.progressBar.setValue(0)
if not dataFile:
self.label.setText('devnote: Not in a frozen environment, no uninstall file found')
else:
self.label.setText(self.ls('uninstall.processing'))
def getAppPrefix(self, *args):
''' Return the location the app is running from'''
isFrozen = False
try:
isFrozen = sys.frozen
except AttributeError:
pass
if isFrozen:
appPrefix = os.path.split(sys.executable)[0]
else:
appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
if args:
appPrefix = os.path.join(appPrefix,*args)
return appPrefix
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)
def test_get_home_dir_2():
"""Testcase for py2exe logic, compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
home_dir = path.get_home_dir(True)
nt.assert_equal(home_dir, unfrozen)
def main():
shell.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = shell.get_config(True)
daemon.daemon_exec(config)
dns_resolver = asyncdns.DNSResolver()
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
_config = config.copy()
_config["local_port"] = _config["tunnel_port"]
logging.info("starting tcp tunnel at %s:%d forward to %s:%d" %
(_config['local_address'], _config['local_port'],
_config['tunnel_remote'], _config['tunnel_remote_port']))
tunnel_tcp_server = tcprelay.TCPRelay(_config, dns_resolver, True)
tunnel_tcp_server._is_tunnel = True
tunnel_tcp_server.add_to_loop(loop)
logging.info("starting udp tunnel at %s:%d forward to %s:%d" %
(_config['local_address'], _config['local_port'],
_config['tunnel_remote'], _config['tunnel_remote_port']))
tunnel_udp_server = udprelay.UDPRelay(_config, dns_resolver, True)
tunnel_udp_server._is_tunnel = True
tunnel_udp_server.add_to_loop(loop)
def handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
tunnel_tcp_server.close(next_tick=True)
tunnel_udp_server.close(next_tick=True)
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
daemon.set_user(config.get('user', None))
loop.run()
def main():
shell.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = shell.get_config(True)
daemon.daemon_exec(config)
logging.info("starting local at %s:%d" %
(config['local_address'], config['local_port']))
dns_resolver = asyncdns.DNSResolver()
tcp_server = tcprelay.TCPRelay(config, dns_resolver, True)
udp_server = udprelay.UDPRelay(config, dns_resolver, True)
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
tcp_server.add_to_loop(loop)
udp_server.add_to_loop(loop)
def handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
tcp_server.close(next_tick=True)
udp_server.close(next_tick=True)
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
daemon.set_user(config.get('user', None))
loop.run()
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)
def test_get_home_dir_2():
"""Testcase for py2exe logic, compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower()
home_dir = path.get_home_dir(True)
nt.assert_equal(home_dir, unfrozen)
def teardown_environment():
"""Restore things that were remembered by the setup_environment function
"""
(oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff
os.chdir(old_wd)
reload(path)
for key in list(env):
if key not in oldenv:
del env[key]
env.update(oldenv)
if hasattr(sys, 'frozen'):
del sys.frozen
# Build decorator that uses the setup_environment/setup_environment
def test_get_home_dir_1():
"""Testcase for py2exe logic, un-compressed lib
"""
unfrozen = path.get_home_dir()
sys.frozen = True
#fake filename for IPython.__init__
IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py"))
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, unfrozen)