Commit 1263a639 authored by talljosh's avatar talljosh

Changes to allow the Python 3 version to build and run for an alpha test.

--HG--
branch : unstable
parent 882669f55b66
......@@ -20,5 +20,11 @@
# Import trosnoth.
import trosnoth.main
# For the sake of cx_Freeze, explicitly import things that won't be included otherwise.
try:
import trosnoth.bots.john, trosnoth.bots.ranger, trosnoth.bots.balance, trosnoth.bots.sirrobin, trosnoth.bots.puppet, trosnoth.bots.onezone
except ImportError:
pass
# Run the user interface.
trosnoth.main.main()
......@@ -4,22 +4,13 @@ import sys
from setuptools import setup, find_packages
additional_dlls = [
'pygame/SDL_ttf.dll',
'pygame/libvorbis-0.dll',
'pygame/libvorbisfile-3.dll',
'pygame/libfreetype-6.dll',
'pygame/SDL_mixer.dll',
'pygame/libogg-0.dll',
]
here = os.path.abspath(os.path.dirname(__file__))
trosnoth_version = imp.load_source('trosnoth.version', os.path.join(
here, 'trosnoth', 'version.py')).version
def main():
global trosnoth_version
if 'py2exe' in sys.argv:
import py2exe
......@@ -71,6 +62,32 @@ def main():
},
},
}
elif sys.argv[1] == 'windows':
sys.argv[1] = 'build'
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
from cx_Freeze import setup, Executable
moreargs = {
'executables': [
Executable('scripts/trosnoth', icon='wininstall/icon.ico'),
],
'build_exe': {
'include_files': [
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
],
'include_msvcr': True,
'namespace_packages': ['zope'],
'zip_excludes_package': '*',
},
}
# Windows doesn't like things like 'a1' at the end
if any(c.isalpha() for c in trosnoth_version):
trosnoth_version = trosnoth_version.replace('rc', '.').replace('a', '.').replace('b', '.')
else:
moreargs = {}
......
......@@ -36,7 +36,7 @@ def getPath(module, *bits):
if _datapath is None:
return os.path.join(os.path.dirname(module.__file__), *bits)
return os.path.join(_datapath, module.__name__.replace('.', '/'), *bits)
return os.path.join(_datapath, 'lib', module.__name__.replace('.', '/'), *bits)
def getUserPath(*bits):
......
......@@ -3,9 +3,12 @@ import os
import time
import pygame
from tkinter import Tk
from tkinter.filedialog import askopenfilename
#from twisted.internet import tksupport
try:
from tkinter import Tk
from tkinter.filedialog import askopenfilename
from twisted.internet import tksupport
except ImportError:
Tk = askopenfilename = tksupport = None
from trosnoth.data import getPath, user, makeDirs
from trosnoth.gui import browser
......@@ -143,7 +146,9 @@ class SavedGameTab(Tab):
self.buttons = [
self.watchButton, self.statsButton, self.refreshButton,
self.cancelButton, self.loadFileButton]
self.cancelButton]
if Tk is not None:
self.buttons.append(self.loadFileButton)
# Replay list
self.gameList = ListBox(
......
......@@ -16,7 +16,7 @@
# 02110-1301, USA.
'''buildInstallScript.py: generates an .nsi file using the selected
source code. To run this script, you will need to have NSIS and py2exe
source code. To run this script, you will need to have NSIS and cx_freeze
installed.'''
......@@ -25,7 +25,7 @@ import os, textwrap, sys, shutil, errno, stat, winreg, subprocess
# Get the correct version number.
_spath = os.path.join(os.path.split(os.path.abspath(__file__))[0], '..')
sys.path.insert(0, _spath)
from setup import trosnoth_version, additional_dlls
from setup import trosnoth_version
# The defines dictionary is what will be used to replace everything
# within square brackets in the Trosnoth Installer Base.
......@@ -34,7 +34,7 @@ defines = {}
baseFilename = 'Trosnoth Installer Base.nsi'
saveFile = 'Trosnoth Installer Script.nsi'
# Name of the setup file that will be compiled
defines['SetupFilename'] = '..\\dist\\trosnoth-setup-%s.exe' % (trosnoth_version,)
defines['SetupFilename'] = '..\\..\\dist\\trosnoth-setup-%s.exe' % (trosnoth_version,)
# Version name
defines['Version'] = trosnoth_version
......@@ -53,23 +53,9 @@ def main():
# Move to the correct top directory.
os.chdir(os.path.split(os.path.abspath(__file__))[0])
# First we need to make a clean py2exe build.
deltree('../dist')
os.mkdir('../dist')
# First we need to make a clean cx_freeze build.
os.chdir('..')
assert os.system(r'%HomeDrive%\Python27\python.exe setup.py py2exe') == 0
deltree('build')
os.rename('dist', 'build')
# Copy any additional dll files needed.
if len(additional_dlls) > 0:
import twisted
sitepackages = os.path.abspath(twisted.__path__[0] + '/..')
for dll in additional_dlls:
path = os.path.join(sitepackages, dll)
outpath = os.path.join('build', os.path.split(path)[1])
print('Coping %s to %s' % (path, outpath))
open(outpath, 'wb').write(open(path, 'rb').read())
assert os.system(r'python.exe setup.py windows') == 0
# SetOutPath '$INSTDIR\<directory>'
# File 'source-code\<filepath>'
......@@ -79,7 +65,8 @@ def main():
lineList = []
os.chdir('build')
BUILD_PATH = r'build\exe.win32-3.6'
os.chdir(BUILD_PATH)
for root, dirs, files in os.walk('.'):
installTarget = root.replace('.', '$INSTDIR', 1)
line = ' SetOutPath "%s"' % installTarget
......@@ -116,7 +103,7 @@ def main():
print('done.')
print('')
os.chdir('..')
os.chdir(r'..\..')
# Time to generate the .nsi file
print('Opening .nsi base...', end=' ')
......@@ -138,9 +125,13 @@ def main():
print('')
print('Writing to %s...' % saveFile, end=' ')
os.mkdir('dist')
try:
os.mkdir('dist')
except FileExistsError:
pass
open('build/'+saveFile, 'w').write(baseFile)
fullSaveFile = os.path.join(BUILD_PATH, saveFile)
open(fullSaveFile, 'w').write(baseFile)
print('done.')
print('')
......@@ -170,10 +161,10 @@ def main():
break
print('Compiling...')
shutil.copy('wininstall\\Trosnoth License.txt', 'build\\Trosnoth License.txt')
shutil.copy('wininstall\\Trosnoth License.txt', os.path.join(BUILD_PATH, 'Trosnoth License.txt'))
compilerPath = compilerPath.replace('makensisw', 'makensis')
command = '"%s" "%s"' % (compilerPath, os.path.abspath('build/'+saveFile))
command = '"%s" "%s"' % (compilerPath, os.path.abspath(fullSaveFile))
process = subprocess.Popen(command)
process.wait()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment