#!/usr/bin/env python
"""
"""
import os
import sys
import shutil
def unbufferedPrint():
class Unbuffered(object):
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
sys.stdout = Unbuffered(sys.stdout)
def process(path, hint):
''' expects a list of directories to process
'''
failed = False
libs = []
root_output = os.path.join(path, 'compiledlib', 'tmp-iOS')
dst_ip_d = os.path.join(root_output, 'iphone', 'Debug')
dst_ip_r = os.path.join(root_output, 'iphone', 'Release')
dst_is_d = os.path.join(root_output, 'iphonesimulator', 'Debug')
dst_is_r = os.path.join(root_output, 'iphonesimulator', 'Release')
# create output
# try: shutil.rmtree(root_output)
# except: pass
try:
os.makedirs(dst_ip_d)
os.makedirs(dst_ip_r)
os.makedirs(dst_is_d)
os.makedirs(dst_is_r)
except:
print 'Failed to create output directories'
if hint == 'simulator':
dst_ip_d = dst_is_d
dst_ip_r = dst_is_r
elif hint == 'ios':
dst_is_d = dst_ip_d
dst_is_r = dst_ip_r
for root, dirs, files in os.walk(os.path.join(path, 'lib')):
if '.svn' in dirs: dirs.remove('.svn')
for f in files :
dst = None
if f.lower().endswith('.a'):
src = os.path.join(root, f)
# distribute output
name, ext = os.path.splitext(f)
if name.endswith('_d') :
if 'iphone' in root : dst = dst_ip_d
elif 'iphonesimulator' in root : dst = dst_is_d
if root.endswith('Debug-iphone') : dst = dst_ip_d
elif root.endswith('Debug-iphoneos') : dst = dst_ip_d
elif root.endswith('Debug-iphonesimulator') : dst = dst_is_d
elif root.endswith('Debug-iphonesimulatoros') : dst = dst_is_d
elif root.endswith('Release-iphone') : dst = dst_ip_r
elif root.endswith('Release-iphoneos') : dst = dst_ip_r
elif root.endswith('Release-iphonesimulator') : dst = dst_is_r
elif root.endswith('Release-iphonesimulatoros') : dst = dst_is_r
elif root.endswith('ios') :
if name.endswith('_d') : dst = dst_ip_d
else : dst = dst_ip_r
elif root.endswith('simulator') :
if name.endswith('_d') : dst = dst_is_d
else : dst = dst_is_r
elif root.endswith('ios_debug') : dst = dst_ip_d
elif root.endswith('ios_release') : dst = dst_ip_r
elif root.endswith('Debug') : dst = dst_ip_d
elif root.endswith('Release') : dst = dst_ip_r
if dst:
dstfile = os.path.join(dst, f)
if os.path.isfile(dstfile): # file exists
if os.path.getctime(src) > os.path.getctime(dstfile):
print 'existing file', dstfile, 'is older than', src
shutil.copy(src, dst)
else:
print 'existing file', dstfile, 'is newer than', src
else:
print 'new file:', src, '->', dst
shutil.copy(src, dst)
else:
# print 'unable to detect destination for', src
pass
return failed
if __name__ == '__main__':
unbufferedPrint()
sys.exit(process(sys.argv[1], sys.argv[2]))