Advertisement
chunkyguy

All imports

Jun 1st, 2011
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. """
  2. sid@whackylabs.com
  3. find all the import files in a project
  4.  
  5. in this case only .h and .m files
  6.  
  7. Usage: python findimports.py ~/Languages/Objective-C/Projects/sample-app/SampleProject/
  8. """
  9.  
  10. import os
  11. import sys
  12. import glob
  13.  
  14. def read_file(file,imports):
  15.     fr = open(file,"r");
  16.     for line in fr:
  17.         if line.find("#import") >= 0:
  18.             imports.append(line)
  19.  
  20. def read_dir(dir_path,imports):
  21.     for file in glob.glob(os.path.join(dir_path, '*')):
  22.         if os.path.isdir(file):
  23.             read_dir(file,imports)
  24.         elif file.find(".h") >= 0:
  25.             read_file(file,imports)
  26.         elif file.find(".m") >= 0:
  27.             read_file(file,imports)
  28.    
  29.    
  30. if __name__ == "__main__":
  31.     imports = []
  32.     read_dir(sys.argv[1],imports)
  33.     for imp in set(imports):
  34.         print imp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement