extract.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. import os
  3. def extract_archive(pathtoarchive, destfolder) :
  4. archive = open(pathtoarchive, 'rb')
  5. global_header = archive.read(8)
  6. if global_header != '!<arch>\n' :
  7. print "Oops!, " + pathtoarchive + " seems not to be an archive file!"
  8. exit()
  9. if destfolder[-1] != '/' :
  10. destfolder = destfolder + '/'
  11. os.makedirs(destfolder)
  12. print 'Trying to extract object files from ' + pathtoarchive
  13. # We don't need the first and second chunk
  14. # they're just symbol and name tables
  15. content_descriptor = archive.readline()
  16. chunk_size = int(content_descriptor[48:57])
  17. archive.read(chunk_size)
  18. content_descriptor = archive.readline()
  19. chunk_size = int(content_descriptor[48:57])
  20. archive.read(chunk_size)
  21. unique_key = 0;
  22. while True :
  23. content_descriptor = archive.readline()
  24. if len(content_descriptor) < 60 :
  25. break
  26. chunk_size = int(content_descriptor[48:57])
  27. output_obj = open(destfolder + pathtoarchive.split('/')[-1] + '.' + str(unique_key) + '.o', 'wb')
  28. output_obj.write(archive.read(chunk_size))
  29. if chunk_size%2 == 1 :
  30. archive.read(1)
  31. output_obj.close()
  32. unique_key = unique_key + 1
  33. archive.close()
  34. print 'Object files extracted to ' + destfolder + '.'
  35. extract_archive('libfbxsdk.a', 'build/Release')