More fixes for a frozen build. Adds the code used by pypy into a zip which pypy uses. This makes for a cleaner install.

master
daid 2012-06-01 11:29:21 +02:00
parent fa1fcfebc8
commit 5769b22cd1
6 changed files with 92 additions and 35 deletions

View File

@ -8,7 +8,6 @@ Cura is a GPL tool chain to forge a gcode skein for a model. Based on Skeinforge
The slicing code is the same as Skeinforge. But the UI has been revamped to be... sane.
"""
from __future__ import absolute_import
import __init__

View File

@ -10,6 +10,7 @@ import __init__
import os
import sys
import traceback
import zipfile
__author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
@ -101,10 +102,20 @@ def getFilePaths(fileInDirectory=''):
def getFilePathsByDirectory(directoryName):
'Get the file paths in the directory of the file in directory.'
absoluteDirectoryPath = os.path.abspath(directoryName)
directory = os.listdir(directoryName)
filePaths = []
for fileName in directory:
filePaths.append(os.path.join(absoluteDirectoryPath, fileName))
if os.path.isdir(directoryName):
for fileName in os.listdir(directoryName):
filePaths.append(os.path.join(absoluteDirectoryPath, fileName))
elif '.zip/' in directoryName:
zipfilename = directoryName[:directoryName.rfind('.zip/')+4]
subpath = directoryName[directoryName.rfind('.zip/')+5:]
z = zipfile.ZipFile(zipfilename, 'r')
for name in z.namelist():
if os.path.dirname(name) == subpath:
filePaths.append(os.path.join(zipfilename, name))
z.close()
print directoryName, filePaths
return filePaths
def getFilePathsRecursively(fileInDirectory=''):
@ -156,14 +167,30 @@ def getFilesWithFileTypeWithoutWords(fileType, words = [], fileInDirectory=''):
def getFileText(fileName, printWarning=True, readMode='r'):
'Get the entire text of a file.'
if '.zip/' in fileName:
zipfilename = fileName[:fileName.rfind('.zip/')+4]
subpath = fileName[fileName.rfind('.zip/')+5:]
try:
z = zipfile.ZipFile(zipfilename, 'r')
f = z.open(subpath, 'r')
fileText = f.read()
f.close()
z.close()
return fileText
except KeyError:
if printWarning:
print('The file ' + fileName + ' does not exist.')
return ''
try:
file = open(fileName, readMode)
fileText = file.read()
file.close()
f = open(fileName, readMode)
fileText = f.read()
f.close()
return fileText
except IOError:
if printWarning:
print('The file ' + fileName + ' does not exist.')
return ''
def getFileTextInFileDirectory(fileInDirectory, fileName, readMode='r'):

View File

@ -35,7 +35,7 @@ def getGNUTranslatorFilesUnmodified():
def getGNUTranslatorGcodeFileTypeTuples():
"Get the file type tuples from the translators in the import plugins folder plus gcode."
fileTypeTuples = getTranslatorFileTypeTuples()
fileTypeTuples = [] #getTranslatorFileTypeTuples()
fileTypeTuples.append( ('Gcode text files', '*.gcode') )
fileTypeTuples.sort()
return fileTypeTuples

View File

@ -165,8 +165,8 @@ def ResetMatrixRotationAndScale():
matrix[2][2] = 1.0
if matrix[3][2] != 0.0:
matrix[3][0] /= -matrix[3][2] / 100
matrix[3][1] /= -matrix[3][2] / 100
matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100)
matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100)
matrix[3][2] = -100
else:
matrix[0][0] = scale2D

View File

@ -1,4 +1,4 @@
import sys
import sys, os, zipfile
try:
import cx_Freeze
except:
@ -10,19 +10,19 @@ if freezeVersion[0] < 4 or freezeVersion[0] == 4 and freezeVersion[1] < 2:
print "ERROR: Your cx-Freeze version is too old to use with Cura."
sys.exit(1)
sys.path.append('./cura_sf/')
sys.path.append(os.path.abspath('cura_sf'))
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": [
build_exe_options = {
"silent": True,
"packages": [
'encodings.utf_8',
"OpenGL", "OpenGL.arrays", "OpenGL.platform", "OpenGL.GLU",
], "excludes": ['Tkinter', 'tcl'], "optimize": 0, "include_files": [
], "excludes": [
'Tkinter', 'tcl', 'cura_sf', 'fabmetheus_utilities', 'skeinforge_application', 'numpy',
], "include_files": [
('images', 'images'),
('cura.py', 'cura.py'),
('__init__.py', '__init__.py'),
('util', 'util'),
('cura_sf', 'cura_sf')
]}
], "build_exe": 'freeze_build'}
# GUI applications require a different base on Windows (the default is for a
# console application).
@ -31,8 +31,31 @@ if sys.platform == "win32":
base = "Win32GUI"
cx_Freeze.setup( name = "Cura",
version = "RC5",
description = "Cura",
options = {"build_exe": build_exe_options},
executables = [cx_Freeze.Executable("cura.py", base=base)])
version = "RC5",
description = "Cura",
options = {"build_exe": build_exe_options},
executables = [cx_Freeze.Executable("cura.py", base=base)])
m = cx_Freeze.ModuleFinder(excludes=["gui"])
m.IncludeFile(os.path.abspath("cura.py"))
m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/profile_plugins/extrusion.py"))
m.IncludeFile(os.path.abspath("cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/stl.py"))
m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/static_plugins/gcode_small.py"))
for name in os.listdir("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins"):
if name.endswith('.py'):
m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/" + name))
m.ReportMissingModules()
cwd = os.path.abspath(".")
z = zipfile.ZipFile("freeze_build/cura_sf.zip", "w", zipfile.ZIP_DEFLATED)
for mod in m.modules:
if mod.file != None and mod.file.startswith(cwd):
if mod.file[len(cwd)+1:] == "cura.py":
z.write(mod.file[len(cwd)+1:], "__main__.py")
else:
z.write(mod.file[len(cwd)+1:])
z.write('cura_sf/fabmetheus_utilities/templates/layer_template.svg')
z.write('cura_sf/fabmetheus_utilities/version.txt')
z.write('__init__.py')
z.close()

View File

@ -2,10 +2,11 @@ from __future__ import absolute_import
import platform, os, subprocess, sys
cura_sf_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../cura_sf/"))
if cura_sf_path not in sys.path:
sys.path.append(cura_sf_path)
from skeinforge_application.skeinforge_utilities import skeinforge_craft
if not hasattr(sys, 'frozen'):
cura_sf_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../cura_sf/"))
if cura_sf_path not in sys.path:
sys.path.append(cura_sf_path)
from skeinforge_application.skeinforge_utilities import skeinforge_craft
from util import profile
@ -77,13 +78,20 @@ def runSlice(fileNames):
if platform.python_implementation() == "PyPy":
skeinforge_craft.writeOutput(fileName)
elif pypyExe == False:
print "************************************************"
print "* Failed to find pypy, so slicing with python! *"
print "************************************************"
skeinforge_craft.writeOutput(fileName)
print "************************************************"
print "* Failed to find pypy, so sliced with python! *"
print "************************************************"
if not hasattr(sys, 'frozen'):
print "************************************************"
print "* Failed to find pypy, so slicing with python! *"
print "************************************************"
skeinforge_craft.writeOutput(fileName)
print "************************************************"
print "* Failed to find pypy, so sliced with python! *"
print "************************************************"
else:
print "******************************************************************"
print "* Failed to find pypy, we need pypy to slice with a frozen build *"
print "* Place pypy in the same directory as Cura so Cura can find it. *"
print "******************************************************************"
sys.exit(1)
else:
subprocess.call(getSliceCommand(fileName))
@ -149,7 +157,7 @@ def getSliceCommand(filename):
#In case we have a frozen exe, then argv[0] points to the executable, but we want to give pypy a real script file.
if hasattr(sys, 'frozen'):
mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "cura.py"))
mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "cura_sf.zip"))
else:
mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1]))
cmd = [pypyExe, mainScriptFile, '-p', profile.getGlobalProfileString()]