Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ To be executed from within your django application for extra initialization """
- import os
- def touch_init(directory_name, alt="__init__.py"):
- target = os.path.join(directory_name, alt)
- with open(target, "a+") as f:
- print("touching file: {}".format(target))
- f.close()
- def check_and_add_directory(app_path, directory_name):
- """
- arguments: (String app_path, String directory_name)
- functionality: check to see if that directory exists in the app and if it
- doesn't then add it .
- return type: String to the directory path
- """
- target_path = os.path.join(app_path, directory_name)
- if not os.path.exists(target_path):
- print("creating directory: {}".format(target_path))
- os.makedirs(target_path)
- return target_path
- if __name__ == "__main__":
- app_path = os.path.dirname(os.path.abspath(__file__))
- base_dir, app_name = os.path.split(app_path)
- # static resources folder(s)
- static = os.path.join('static', app_name)
- 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')]
- for folder in static_folders:
- check_and_add_directory(app_path, folder)
- # templates
- templates = os.path.join('templates', app_name)
- check_and_add_directory(app_path, templates)
- # signals
- touch_init(check_and_add_directory(app_path, "signals"))
- # models
- touch_init(check_and_add_directory(app_path, "models"))
- # templatetags
- touch_init(check_and_add_directory(app_path, 'templatetags'))
- # utils
- touch_init(check_and_add_directory(app_path, "utils"))
- # middleware
- touch_init(check_and_add_directory(app_path, "middleware"))
- # serializers
- touch_init(check_and_add_directory(app_path, "serializers"))
- # urls
- touch_init(app_path, alt="urls.py")
- print("done.")
Add Comment
Please, Sign In to add comment