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

Commit

Permalink
Finished code for release 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jcsackett committed Jul 20, 2009
1 parent c046297 commit 4164b54
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
20 changes: 10 additions & 10 deletions templates/fabfile.py.tmpl
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
config.fab_hosts = [{{staging}}, {{production}}, {{internal}}]
config.fab_hosts = ['{{staging}}', '{{production}}', '{{internal}}']

def internal():
config.fab_hosts = [{{internal}}]
config.db_user = {{internal_db_user}}
config.db_password = {internal_db_password}}
config.fab_hosts = ['{{internal}}']
config.db_user = '{{internal_db_user}}'
config.db_password = '{{internal_db_password}}'
config.conf = 'internal'

def staging():
config.fab_hosts = [{{staging}}]
config.db_user = {{staging_db_user}}
config.db_password = {{staging_db_password}}
config.fab_hosts = ['{{staging}}']
config.db_user = '{{staging_db_user}}'
config.db_password = '{{staging_db_password}}'
config.conf = 'staging'

def production():
config.fab_hosts = [{{production}}]
config.db_user = {{production_db_user}}
config.db_password = {{production_db_password}}
config.fab_hosts = ['{{production}}']
config.db_user = '{{production_db_user}}'
config.db_password = '{{production_db_password}}'
config.conf = 'production'

def init():
Expand Down
3 changes: 1 addition & 2 deletions templates/settings.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ CODE_HOME = '' #the name of the directory the code will be hosted in
REPO_TYPE = '' #one of git, hg, or svn
REPO = '' #the url of the code repo
USER = '' #The user for the server
MYSQL_DB = PROJECT
#MYSQL_DB = '' #the name of the database
MYSQL_DB = PROJECT

#SERVER BASED SETUP INFO
# Each of the following variables consists of a three part tuple, defining
# that variable for each server in STAGING, INTERNAL, and PRODUCTION

ADMIN = ('', '', '') #The admin email for the apache instance (e.g. [email protected])
MYSQL_USER = ('', '', '') #The mysql user for the project
MYSQL_PASSWORD = ('', '', '') #The password for the mysql user on the project
Expand Down
4 changes: 3 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
class SettingsError(Exception):
pass

def get_setting(setting_name, setting_mod, transform=lambda x: x):
def get_setting(setting_mod, setting_name, transform=lambda x: x):
setting = getattr(setting_mod, setting_name)
#if the setting is just a string, we know it stays the same across servers
if type(setting) == str:
return transform(setting)
#tuples, however, mean the setting changes from server to server
elif type(setting) == tuple:
setting = dict(
staging=transform(setting[0]),
Expand Down
43 changes: 37 additions & 6 deletions weaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class WeaverConfig(object):
config = WeaverConfig()

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

def init(args):
Expand All @@ -38,6 +38,7 @@ def build(args):
load_settings()
scripts()
conf()
fabfile()

def load_settings():
working_dir = os.getcwd()
Expand All @@ -47,14 +48,18 @@ def load_settings():
config.project = get_setting(settings, 'PROJECT_HOME')
config.code = get_setting(settings, 'CODE_HOME')
config.user = get_setting(settings, 'USER')
config.server = get_setting(settings, 'SERVER')
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])
config.repo_cmd = get_setting(settings, 'REPO_TYPE',lambda x: repo_types[x])
config.db = get_setting(settings, 'MYSQL_DB')
config.db_user = get_setting(settings, 'MYSQL_USER')
config.db_password = get_setting(settings, 'MYSQL_PASSWORD')

def scripts():
os.mkdir('scripts')
Expand All @@ -67,6 +72,26 @@ def scripts():
content = template.render(project=config.project, code=config.code)
file(os.path.join('scripts', 'setup_syslinks.sh'), 'w').write(content)

def fabfile():
template = env.get_template('fabfile.py.tmpl')
content = template.render(
project=config.project,
code=config.code,
repo=config.repo,
repo_cmd=config.repo_cmd,
db=config.db,
staging='%s@%s' % (config.user, config.server['staging']),
staging_db_user=config.db_user['staging'],
staging_db_password=config.db_password['staging'],
internal='%s@%s' % (config.user, config.server['internal']),
internal_db_user=config.db_user['internal'],
internal_db_password=config.db_password['internal'],
production='%s@%s' % (config.user, config.server['production']),
production_db_user=config.db_user['production'],
production_db_password=config.db_password['production'],
)
file('fabfile.py', 'w').write(content)

def conf():
os.mkdir('conf')
os.mkdir(os.path.join('conf', 'staging'))
Expand Down Expand Up @@ -108,11 +133,17 @@ def conf():
file(os.path.join('conf', 'staging', filename), 'w').write(staging_content)
file(os.path.join('conf', 'production', filename), 'w').write(production_content)
file(os.path.join('conf', 'internal', filename), 'w').write(internal_content)


def reset(args):
os.remove('fabfile.py')
os.remove('settings.pyc')
shutil.rmtree('conf')
shutil.rmtree('scripts')

commands = {
'init':init,
'build':build
'build':build,
'reset':reset
}

if __name__ == '__main__':
Expand Down

0 comments on commit 4164b54

Please sign in to comment.