chunkyguy

All imports

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