1#!/usr/bin/env python 2""" 3This script will rewrite the macho headers of the frameworks in the 4nightly webkit snapshot, to make sure PyObjC can use them. 5""" 6import os, shutil 7 8from macholib.MachO import MachO 9 10def rewriteFramework(framework, frameworkMap): 11 12 basename = os.path.splitext(os.path.basename(framework))[0] 13 dyld = os.path.abspath(os.path.join(framework, basename)) 14 15 macho = MachO(dyld) 16 17 def changefunc(key): 18 if key == dyld: 19 return dyld 20 21 dirname, filename = os.path.split(key) 22 return frameworkMap.get(filename) 23 24 macho.rewriteLoadCommands(changefunc) 25 macho.write(open(dyld, 'rb+')) 26 27def rewriteFrameworksInDirectory(dirname): 28 frameworks = [ 29 fn for fn in os.listdir(dirname) if fn.endswith('.framework') ] 30 mapping = {} 31 for fn in frameworks: 32 mapping[os.path.splitext(fn)[0]] = os.path.join(os.path.abspath(dirname), fn , os.path.splitext(fn)[0]) 33 34 for fn in frameworks: 35 rewriteFramework(fn, mapping) 36 37def extractWebKitApp(pathToApp, outputDir): 38 resources = os.path.join(pathToApp, 'Contents', 'Resources') 39 frameworks = [ 40 fn for fn in os.listdir(resources) if fn.endswith('.framework') ] 41 for framework in frameworks: 42 if os.path.exists(os.path.join(outputDir, framework)): 43 shutil.rmtree(os.path.join(outputDir, framework)) 44 45 shutil.copytree( 46 os.path.join(resources, framework), 47 os.path.join(outputDir, framework), symlinks=True) 48 49 rewriteFrameworksInDirectory(outputDir) 50 51def main(): 52 extractWebKitApp('WebKit.app', '.') 53 54 55if __name__ == '__main__': 56 main() 57