Skip to content

Commit

Permalink
Initial commit or awesomeness.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjones-brack3t committed Sep 8, 2011
0 parents commit 88e6f30
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store
._*
Empty file added README.rst
Empty file.
62 changes: 62 additions & 0 deletions 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.