Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Added utils thing to take out some of the messy per server settings c…
Browse files Browse the repository at this point in the history
…ode. Finished processing settings in weaver
  • Loading branch information
j.c.sackett committed Jul 17, 2009
1 parent 71c1b69 commit c046297
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
18 changes: 18 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Set of utilities for weaver.

class SettingsError(Exception):
pass

def get_setting(setting_name, setting_mod, transform=lambda x: x):
setting = getattr(setting_mod, setting_name)
if type(setting) == str:
return transform(setting)
elif type(setting) == tuple:
setting = dict(
staging=transform(setting[0]),
internal=transform(setting[1]),
production=transform(setting[2]),
)
return setting
else:
raise SettingsError('Settings must be one of: str, tuple')
51 changes: 20 additions & 31 deletions weaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import shutil
from jinja2 import Environment, FileSystemLoader

from utils import get_setting

WEAVER_DIR = os.path.dirname(os.path.abspath(__file__))
env = Environment(loader=FileSystemLoader(os.path.join(WEAVER_DIR, 'templates')))

Expand All @@ -13,6 +15,12 @@ class WeaverConfig(object):

config = WeaverConfig()

repo_types = dict(
'git':'git clone',
'svn':'svn co',
'hg':'hg clone'
)

def init(args):
target_dir = args[0]
try:
Expand All @@ -36,36 +44,17 @@ def load_settings():
sys.path += [working_dir]
import settings

config.project = getattr(settings, 'PROJECT_HOME')
config.code = getattr(settings, 'CODE_HOME')
config.user = getattr(settings, 'USER')
config.repo = getattr(settings, 'REPO')
config.repo_type = getattr(settings, 'REPO_TYPE')

config.url = getattr(settings, 'URL')
config.url = dict(
staging='^%s$' % '\.'.join(config.url[0].split('.')),
internal='^%s$' % '\.'.join(config.url[1].split('.')),
production='^%s$' % '\.'.join(config.url[2].split('.')),
)
config.port = getattr(settings, 'PORT')
config.port = dict(
staging=config.port[0],
internal=config.port[1],
production=config.port[2]
)
config.admin = getattr(settings, 'ADMIN')
config.admin = dict(
staging=config.admin[0],
internal=config.admin[1],
production=config.admin[2]
)
config.django_process = getattr(settings, 'DJANGO_PROCESS')
config.django_process = dict(
staging=config.django_process[0],
internal=config.django_process[1],
production=config.django_process[2]
)
config.project = get_setting(settings, 'PROJECT_HOME')
config.code = get_setting(settings, 'CODE_HOME')
config.user = get_setting(settings, 'USER')
config.repo = get_setting(settings, 'REPO')
config.repo_type = get_setting(settings, 'REPO_TYPE')
config.url = get_setting(settings, 'URL', lambda x: '\.'.join(x.split('.')))
config.port = get_setting(settings, 'PORT')
config.admin = get_setting(settings, 'ADMIN')
config.django_process = get_setting(settings, 'DJANGO_PROCESS')
config.repo = get_setting(settings, 'REPO')
config.repo_cmd = get_settings(settings, 'REPO_TYPE',lambda x: repo_types[x])

def scripts():
os.mkdir('scripts')
Expand Down Expand Up @@ -134,4 +123,4 @@ def conf():
if c is None:
print '%s is not a weaver command.' % cmd
else:
c(args)
c(args)

0 comments on commit c046297

Please sign in to comment.