Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. """ To be executed from within your django application for extra initialization """
  2.  
  3. import os
  4.  
  5. def touch_init(directory_name, alt="__init__.py"):
  6. target = os.path.join(directory_name, alt)
  7. with open(target, "a+") as f:
  8. print("touching file: {}".format(target))
  9. f.close()
  10.  
  11. def check_and_add_directory(app_path, directory_name):
  12. """
  13. arguments: (String app_path, String directory_name)
  14.  
  15. functionality: check to see if that directory exists in the app and if it
  16. doesn't then add it .
  17.  
  18. return type: String to the directory path
  19. """
  20. target_path = os.path.join(app_path, directory_name)
  21. if not os.path.exists(target_path):
  22. print("creating directory: {}".format(target_path))
  23. os.makedirs(target_path)
  24. return target_path
  25.  
  26.  
  27. if __name__ == "__main__":
  28. app_path = os.path.dirname(os.path.abspath(__file__))
  29. base_dir, app_name = os.path.split(app_path)
  30.  
  31. # static resources folder(s)
  32. static = os.path.join('static', app_name)
  33. static_folders = [static, os.path.join(static, 'css'), os.path.join(static, 'js'), os.path.join(static, 'img'), os.path.join(static, 'doc'), os.path.join(static, 'plugins')]
  34. for folder in static_folders:
  35. check_and_add_directory(app_path, folder)
  36.  
  37. # templates
  38. templates = os.path.join('templates', app_name)
  39. check_and_add_directory(app_path, templates)
  40.  
  41. # signals
  42. touch_init(check_and_add_directory(app_path, "signals"))
  43.  
  44. # models
  45. touch_init(check_and_add_directory(app_path, "models"))
  46.  
  47. # templatetags
  48. touch_init(check_and_add_directory(app_path, 'templatetags'))
  49.  
  50. # utils
  51. touch_init(check_and_add_directory(app_path, "utils"))
  52.  
  53. # middleware
  54. touch_init(check_and_add_directory(app_path, "middleware"))
  55.  
  56. # serializers
  57. touch_init(check_and_add_directory(app_path, "serializers"))
  58.  
  59. # urls
  60. touch_init(app_path, alt="urls.py")
  61.  
  62. print("done.")
Add Comment
Please, Sign In to add comment