From 6ad672ae40cc42f8c7e775c8577f4dd9a044f664 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 2 Sep 2009 16:16:40 -0600 Subject: [PATCH] IGN:More work on leopard build --- installer/osx/py2app/launcher.py | 9 ++++-- installer/osx/py2app/loader.py | 9 ++++-- installer/osx/py2app/main.c | 5 +-- installer/osx/py2app/main.py | 52 +++++++++++++++++++++----------- src/calibre/devices/libusb.py | 35 +++++++++++---------- upload.py | 3 +- 6 files changed, 72 insertions(+), 41 deletions(-) diff --git a/installer/osx/py2app/launcher.py b/installer/osx/py2app/launcher.py index c12b6bdc3a..468feca940 100644 --- a/installer/osx/py2app/launcher.py +++ b/installer/osx/py2app/launcher.py @@ -1,6 +1,5 @@ #!/usr/bin/env python # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' @@ -39,13 +38,19 @@ def _run(): import os, sys, site sys.frozen = 'macosx_app' base = os.environ['RESOURCEPATH'] - sys.frameworks_dir = os.path.join(os.path.dirname(base, 'Frameworks')) + sys.frameworks_dir = os.path.join(os.path.dirname(base), 'Frameworks') sys.new_app_bundle = True site.addsitedir(base) site.addsitedir(os.path.join(base, 'Python', 'site-packages')) exe = os.environ.get('CALIBRE_LAUNCH_MODULE', 'calibre.gui2.main') exe = os.path.join(base, 'Python', 'site-packages', *exe.split('.')) + exe += '.py' sys.argv[0] = __file__ = exe + argv = os.environ.get('CALIBRE_LAUNCH_ARGV', None) + if argv is not None: + import cPickle + argv = cPickle.loads(argv) + sys.argv[1:] = argv execfile(exe, globals(), globals()) _run() diff --git a/installer/osx/py2app/loader.py b/installer/osx/py2app/loader.py index 533a88bbe3..ea6565c5f5 100644 --- a/installer/osx/py2app/loader.py +++ b/installer/osx/py2app/loader.py @@ -5,7 +5,7 @@ __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, sys +import os, sys, cPickle ENV = {}##ENV## MODULE = ''##MODULE## @@ -18,13 +18,16 @@ resources_dir = os.path.join(base_dir, 'Resources') frameworks_dir = os.path.join(base_dir, 'Frameworks') exe_dir = os.path.join(base_dir, 'MacOS') base_name = os.path.splitext(name)[0] -python = os.path.join(base_dir, 'MacOS', 'calibre') +python = os.path.join(base_dir, 'MacOS', 'Python') for key, val in ENV.items(): if val.startswith('@exec'): ENV[key] = os.path.normpath(val.replace('@executable_path', exe_dir)) ENV['CALIBRE_LAUNCH_MODULE'] = MODULE +ENV['CALIBRE_LAUNCH_ARGV'] = cPickle.dumps(sys.argv[1:], -1) +ENV['RESOURCEPATH'] = resources_dir os.environ.update(ENV) -args = [path] + sys.argv[1:] +launcher = os.path.join(resources_dir, 'launcher.py') +args = ['-OO', launcher] os.execv(python, args) diff --git a/installer/osx/py2app/main.c b/installer/osx/py2app/main.c index 01abe6d3a7..bc4ec1a434 100644 --- a/installer/osx/py2app/main.c +++ b/installer/osx/py2app/main.c @@ -864,9 +864,10 @@ static int py2app_main(int argc, char * const *argv, char * const *envp) { if (!getApplicationName()) return report_error(ERR_NONAME); pyLocations = (CFArrayRef)getKey("PyRuntimeLocations"); if (!pyLocations) return report_error(ERR_PYRUNTIMELOCATIONS); + printf("1111111\n;"); pyLocation = findPyLocation(pyLocations); if (!pyLocation) return report_error(ERR_NOPYTHONRUNTIME); - + printf("2222222\n"); setExecutablePath(); setResourcePath(); /* check for ':' in path, not compatible with Python due to Py_GetPath */ @@ -895,7 +896,7 @@ static int py2app_main(int argc, char * const *argv, char * const *envp) { xCFStringGetCString(pyLocation, buf, sizeof(buf), kCFStringEncodingUTF8); py_dylib = dlopen(buf, PYMACAPP_DYLD_FLAGS); if (py_dylib == NULL) return report_linkEdit_error(); - + printf("3333333\n"); #define LOOKUP_SYMBOL(NAME) \ tmpSymbol = dlsym(py_dylib, # NAME) #define LOOKUP_DEFINEADDRESS(NAME, ADDRESS) \ diff --git a/installer/osx/py2app/main.py b/installer/osx/py2app/main.py index 142d5cb763..67980053a8 100644 --- a/installer/osx/py2app/main.py +++ b/installer/osx/py2app/main.py @@ -26,6 +26,7 @@ ENV = dict( PYTHONIOENCODING='utf-8:replace', PYTHONPATH='@executable_path/../Resources/Python/site-packages', PYTHONHOME='@executable_path/../Resources/Python', + PYTHONOPTIMIZE='2', QT_PLUGIN_PATH='@executable_path' ) @@ -85,6 +86,7 @@ class Py2App(object): self.contents_dir = join(self.build_dir, 'Contents') self.resources_dir = join(self.contents_dir, 'Resources') self.frameworks_dir = join(self.contents_dir, 'Frameworks') + self.version_info = '.'.join(map(str, sys.version_info[:2])) self.to_strip = [] self.warnings = [] @@ -141,6 +143,9 @@ class Py2App(object): launcher = launcher.replace('{}##ENV##', repr(ENV)) os.mkdir(join(self.resources_dir, 'loaders')) for basename, module in zip(all_names, all_modules): + py_file = join('src', *module.split('.'))+'.py' + shutil.copy2(py_file, join(self.resources_dir, 'Python', + 'site-packages', *module.split('.'))+'.py') raw = launcher.replace("''##MODULE##", repr(module)) path = join(self.resources_dir, 'loaders', basename) open(path, 'wb').write(raw) @@ -174,13 +179,10 @@ class Py2App(object): raw = subprocess.Popen(['otool', '-L', path_to_lib], stdout=subprocess.PIPE).stdout.read() for line in raw.splitlines(): - if 'compatibility' not in line: + if 'compatibility' not in line or line.strip().endswith(':'): continue idx = line.find('(') path = line[:idx].strip() - bname = os.path.basename(path).partition('.')[0] - if bname in path_to_lib: - continue yield path @flush @@ -213,6 +215,7 @@ class Py2App(object): @flush def add_python_framework(self): + print '\nAdding Python framework' src = join(SW, 'python', 'Python.framework') x = join(self.frameworks_dir, 'Python.framework') curr = os.path.realpath(join(src, 'Versions', 'Current')) @@ -223,6 +226,10 @@ class Py2App(object): shutil.copy2(join(curr, 'Python'), currd) self.set_id(join(currd, 'Python'), self.FID+'/Python.framework/Versions/%s/Python'%basename(curr)) + python = '%s/python/Python.framework/Versions/%s/Resources/Python.app/Contents/MacOS/Python'\ + % (SW, self.version_info) + shutil.copy2(python, join(self.contents_dir, 'MacOS')) + self.fix_dependencies_in_lib(join(self.contents_dir, 'MacOS', 'Python')) @flush def add_qt_frameworks(self): @@ -264,7 +271,7 @@ class Py2App(object): os.mkdir(dest) for f in glob.glob('src/calibre/plugins/*.so'): shutil.copy2(f, dest) - self.fix_dependencies_in_lib(join(dest, basename(f))) + self.fix_dependencies_in_lib(join(dest, basename(f))) @flush @@ -279,7 +286,7 @@ class Py2App(object): CFBundleSignature='????', CFBundleExecutable='calibre', LSMinimumSystemVersion='10.5.2', - PyRuntimeLocations=[self.FID+'/Python.framework/Versions/Current/Python'], + PyRuntimeLocations=[self.FID+'/Python.framework/Versions/%s/Python'%self.version_info], LSRequiresNativeExecution=True, NSAppleScriptEnabled=False, NSHumanReadableCopyright='Copyright 2008, Kovid Goyal', @@ -369,7 +376,9 @@ class Py2App(object): def add_misc_libraries(self): for x in ('usb', 'unrar'): print '\nAdding', x - shutil.copy2(join(SW, 'lib', 'lib%s.dylib'%x), self.frameworks_dir) + x = 'lib%s.dylib'%x + shutil.copy2(join(SW, 'lib', x), self.frameworks_dir) + self.set_id(join(self.frameworks_dir, x), self.FID+'/'+x) @flush def add_site_packages(self): @@ -436,6 +445,11 @@ class Py2App(object): dest = join(dest, basename(x)) shutil.copytree(x, dest, symlinks=True, ignore=ignore) self.postprocess_package(x, dest) + for x in os.walk(dest): + for f in x[-1]: + if f.endswith('.so'): + f = join(x[0], f) + self.fix_dependencies_in_lib(f) @flush def filter_package(self, name): @@ -450,20 +464,22 @@ class Py2App(object): def add_stdlib(self): print '\nAdding python stdlib' src = join(SW, 'python/Python.framework/Versions/Current/lib/python') - src += '.'.join(map(str, sys.version_info[:2])) + src += self.version_info dest = join(self.resources_dir, 'Python', 'lib', 'python') - dest += '.'.join(map(str, sys.version_info[:2])) + dest += self.version_info + os.makedirs(dest) for x in os.listdir(src): if x in ('site-packages', 'config', 'test', 'lib2to3', 'lib-tk', 'lib-old', 'idlelib', 'plat-mac', 'plat-darwin', 'site.py'): continue + x = join(src, x) if os.path.isdir(x): - self.add_package_dir(join(src, x), dest) - elif os.path.splitext(x) in ('.so', '.py'): - shutil.copy2(join(src, x), dest) - dest = join(dest, basename(x)) - if dest.endswith('.so'): - self.fix_dependencies_in_lib(dest) + self.add_package_dir(x, dest) + elif os.path.splitext(x)[1] in ('.so', '.py'): + shutil.copy2(x, dest) + dest2 = join(dest, basename(x)) + if dest2.endswith('.so'): + self.fix_dependencies_in_lib(dest2) self.remove_bytecode(join(self.resources_dir, 'Python', 'lib')) @flush @@ -509,8 +525,10 @@ class Py2App(object): @flush def copy_launcher_and_site(self): base = os.path.dirname(__file__) - for x in ('launcher', 'site'): - shutil.copy2(join(base, x+'.py'), self.resources_dir) + shutil.copy2(join(base, 'launcher.py'), self.resources_dir) + shutil.copy2(join(base, 'site.py'), join(self.resources_dir, 'Python', + 'lib', 'python'+self.version_info)) + @flush def makedmg(self, d, volname, diff --git a/src/calibre/devices/libusb.py b/src/calibre/devices/libusb.py index a465f95029..edfec679fd 100644 --- a/src/calibre/devices/libusb.py +++ b/src/calibre/devices/libusb.py @@ -305,22 +305,25 @@ Device._fields_ = [ \ ] if _libusb is not None: - _libusb.usb_get_busses.restype = POINTER(Bus) - _libusb.usb_open.restype = POINTER(DeviceHandle) - _libusb.usb_open.argtypes = [POINTER(Device)] - _libusb.usb_close.argtypes = [POINTER(DeviceHandle)] - _libusb.usb_claim_interface.argtypes = [POINTER(DeviceHandle), c_int] - _libusb.usb_claim_interface.restype = c_int - _libusb.usb_release_interface.argtypes = [POINTER(DeviceHandle), c_int] - _libusb.usb_release_interface.restype = c_int - _libusb.usb_reset.argtypes = [POINTER(DeviceHandle)] - _libusb.usb_reset.restype = c_int - _libusb.usb_control_msg.restype = c_int - _libusb.usb_bulk_read.restype = c_int - _libusb.usb_bulk_write.restype = c_int - _libusb.usb_set_configuration.argtypes = [POINTER(DeviceHandle), c_int] - _libusb.usb_set_configuration.restype = c_int - _libusb.usb_init() + try: + _libusb.usb_get_busses.restype = POINTER(Bus) + _libusb.usb_open.restype = POINTER(DeviceHandle) + _libusb.usb_open.argtypes = [POINTER(Device)] + _libusb.usb_close.argtypes = [POINTER(DeviceHandle)] + _libusb.usb_claim_interface.argtypes = [POINTER(DeviceHandle), c_int] + _libusb.usb_claim_interface.restype = c_int + _libusb.usb_release_interface.argtypes = [POINTER(DeviceHandle), c_int] + _libusb.usb_release_interface.restype = c_int + _libusb.usb_reset.argtypes = [POINTER(DeviceHandle)] + _libusb.usb_reset.restype = c_int + _libusb.usb_control_msg.restype = c_int + _libusb.usb_bulk_read.restype = c_int + _libusb.usb_bulk_write.restype = c_int + _libusb.usb_set_configuration.argtypes = [POINTER(DeviceHandle), c_int] + _libusb.usb_set_configuration.restype = c_int + _libusb.usb_init() + except: + _libusb = None diff --git a/upload.py b/upload.py index 6e3c5fa099..9574c633b3 100644 --- a/upload.py +++ b/upload.py @@ -523,8 +523,9 @@ class VMInstaller(OptionlessCommand): --exclude "*.pyc" --exclude "*.pyo" --exclude "*.swp" --exclude "*.swo" \ rsync://%(host)s/work/%(project)s . && \ cd %(project)s && \ + rm -rf src/calibre/plugins/* && \ %%s && \ - rm -rf build/* dist/* src/calibre/plugins/* && \ + rm -rf build/* dist/* && \ %%s %%s '''%dict(host=HOST, project=__appname__))