chiark / gitweb /
More fixes for a frozen build. Adds the code used by pypy into a zip which pypy uses...
authordaid <daid303@gmail.com>
Fri, 1 Jun 2012 09:29:21 +0000 (11:29 +0200)
committerdaid <daid303@gmail.com>
Fri, 1 Jun 2012 09:29:21 +0000 (11:29 +0200)
Cura/cura.py
Cura/cura_sf/fabmetheus_utilities/archive.py
Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/fabmetheus_interpret.py
Cura/gui/opengl.py
Cura/setup.py
Cura/util/sliceRun.py

index 8e86f7bcca4e845507f6b48e0a716544b9e35e21..1b9fe2ffa6873b4b2d715ba2ae4b49f41c30a056 100644 (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__
 
index 8b6d93fa1970a828d03bc033112cf5a585afa078..c9e56557ad2261740e6abe6fceac5eab1978f568 100644 (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'):
index 65de7cf73f69423e19d12e93e7e081d1a7d3a8a2..d291420869e4db7d5f191c34c47d156909301f19 100644 (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
index e5204cff692a070ff16751b9afc53953462e6cb6..9ed0573f70ddd459cbf1ed273d7bc33c908ca8a9 100644 (file)
@@ -165,8 +165,8 @@ def ResetMatrixRotationAndScale():
        matrix[2][2] = 1.0\r
        \r
        if matrix[3][2] != 0.0:\r
-               matrix[3][0] /= -matrix[3][2] / 100\r
-               matrix[3][1] /= -matrix[3][2] / 100\r
+               matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100)\r
+               matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100)\r
                matrix[3][2] = -100\r
        else:\r
                matrix[0][0] = scale2D\r
index eb8c763edbd4b4187f459391d72ce65be22e2eb2..e077f6774f3929f6c08cd3f05ee349224fdf11ef 100644 (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()
 
index 221003677458ba42c4458995dbf07716a70976cd..483dbc5aa83290bb0538b5e97c63035d2b7a3df9 100644 (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()]