Browse files

Initial commit or awesomeness.

  • Loading branch information...
0 parents commit 88e6f30b082ba2737ef7e5958f689fea56c95e84 @chrisjones-brack3t chrisjones-brack3t committed Sep 8, 2011
Showing with 64 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. 0 README.rst
  3. +62 −0 modular_settings.py
2 .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+._*
0 README.rst
No changes.
62 modular_settings.py
@@ -0,0 +1,62 @@
+import os
+
+init_content = """from .base import *
+
+try:
+ from .local import *
+except ImportError:
+ pass
+"""
+
+def get_project_dir():
+ dir_list = os.path.abspath(__file__).split('/')[:-1]
+ return '/'.join(dir_list)
+
+def awesomeness():
+ PROJECT_PATH = get_project_dir()
+
+ if os.path.exists(PROJECT_PATH + '/settings'):
+ raise Exception("A settings directory already exists.")
+
+ try:
+ settings = open(PROJECT_PATH + '/settings.py', 'r')
+ except IOError:
+ raise Exception("Cannot open your default settings file.")
+
+ try:
+ os.makedirs(PROJECT_PATH + '/settings')
+ except Error:
+ raise Exception("Could not create the settings folder.")
+
+ try:
+ init = open(PROJECT_PATH + '/settings/__init__.py', 'wb')
+ init.write(init_content)
+ init.close()
+ except IOError:
+ raise IOError("Could not create the __init__.py file.")
+
+ try:
+ base = open(PROJECT_PATH + '/settings/base.py', 'wb')
+ base.write(settings.read())
+ base.close()
+ settings.close()
+ except IOError:
+ raise IOError("WTF")
+
+ try:
+ os.remove(PROJECT_PATH + '/settings.py')
+ except OSError:
+ raise OSError("Cannot delete the default settings file.")
+
+ try:
+ local = open(PROJECT_PATH + '/settings/local.py', 'wb')
+ local.write('# your local dev settings go here.')
+ local.close()
+ except IOError:
+ raise IOError("Cannot write local.py file.")
+
+ print("Done")
+
+
+if __name__ == '__main__':
+ awesomeness()

0 comments on commit 88e6f30

Please sign in to comment.