2015-04-23 06:46:06 +08:00
|
|
|
"""
|
|
|
|
Installs cx_freeze from source, but first patching
|
|
|
|
setup.py as described here:
|
|
|
|
|
|
|
|
http://stackoverflow.com/questions/25107697/compiling-cx-freeze-under-ubuntu
|
|
|
|
"""
|
|
|
|
import glob
|
|
|
|
import tarfile
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import platform
|
2015-09-17 22:54:44 +08:00
|
|
|
import py
|
2015-04-23 06:46:06 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if 'ubuntu' not in platform.version().lower():
|
|
|
|
|
|
|
|
print('Not Ubuntu, installing using pip. (platform.version() is %r)' %
|
|
|
|
platform.version())
|
|
|
|
res = os.system('pip install cx_freeze')
|
|
|
|
if res != 0:
|
|
|
|
sys.exit(res)
|
|
|
|
sys.exit(0)
|
|
|
|
|
2015-09-18 01:52:51 +08:00
|
|
|
rootdir = py.path.local.make_numbered_dir(prefix='cx_freeze')
|
2015-04-23 06:46:06 +08:00
|
|
|
|
2015-09-17 22:54:44 +08:00
|
|
|
res = os.system('pip install --download %s --no-use-wheel '
|
|
|
|
'cx_freeze' % rootdir)
|
2015-04-23 06:46:06 +08:00
|
|
|
if res != 0:
|
|
|
|
sys.exit(res)
|
|
|
|
|
2015-09-17 22:54:44 +08:00
|
|
|
packages = glob.glob('%s/*.tar.gz' % rootdir)
|
2015-04-23 06:46:06 +08:00
|
|
|
assert len(packages) == 1
|
|
|
|
tar_filename = packages[0]
|
|
|
|
|
|
|
|
tar_file = tarfile.open(tar_filename)
|
|
|
|
try:
|
2015-09-17 22:54:44 +08:00
|
|
|
tar_file.extractall(path=str(rootdir))
|
2015-04-23 06:46:06 +08:00
|
|
|
finally:
|
|
|
|
tar_file.close()
|
|
|
|
|
|
|
|
basename = os.path.basename(tar_filename).replace('.tar.gz', '')
|
2015-09-17 22:54:44 +08:00
|
|
|
setup_py_filename = '%s/%s/setup.py' % (rootdir, basename)
|
2015-04-23 06:46:06 +08:00
|
|
|
with open(setup_py_filename) as f:
|
|
|
|
lines = f.readlines()
|
|
|
|
|
|
|
|
line_to_patch = 'if not vars.get("Py_ENABLE_SHARED", 0):'
|
|
|
|
for index, line in enumerate(lines):
|
|
|
|
if line_to_patch in line:
|
|
|
|
indent = line[:line.index(line_to_patch)]
|
|
|
|
lines[index] = indent + 'if True:\n'
|
|
|
|
print('Patched line %d' % (index + 1))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
sys.exit('Could not find line in setup.py to patch!')
|
|
|
|
|
|
|
|
with open(setup_py_filename, 'w') as f:
|
|
|
|
f.writelines(lines)
|
|
|
|
|
2015-09-18 10:32:27 +08:00
|
|
|
os.chdir('%s/%s' % (rootdir, basename))
|
2015-04-23 06:46:06 +08:00
|
|
|
res = os.system('python setup.py install')
|
|
|
|
if res != 0:
|
|
|
|
sys.exit(res)
|
|
|
|
|
2015-09-17 22:54:44 +08:00
|
|
|
sys.exit(0)
|