~doctormo/django-deployer/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python

from modeploy import installer, deployer, interface, database
from moxml.config import Config
from random import choice
import os, sys

interface.rootRequired()

if len(sys.argv) < 2:
	print "\nUse %s [www directory]\n" % sys.argv[0]
	sys.exit()

www_dir = sys.argv[1]

if os.path.exists(os.path.join(www_dir, 'generated.xml')):
	config = Config('generated.xml', www_dir)
else:
	print "couldn't find generated.xml file in provided path %s" % www_dir
	sys.exit()


target = www_dir

# These are set for now, I must figure out a way of making them configurable
# Or detectable, this is a job for later if the project is useful to others.
config['admin_name'] = 'Bob'
config['admin_email'] = 'bob@localhost'
config['debug'] = 'False'

config['unique_key'] = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
config['time_zone'] = installer.quick_read('/etc/timezone').replace('\n','').replace('\r','')
config['language_code'] = 'en'

stores = config['stores']
linked = config['linked']

# Make sure writable directories are owned by web server process
for dir in stores:
	installer.rchown(str(dir), str(config['web_user']), str(config['web_group']))

for link in linked:
	installer.makeLink(str(link[0]), str(link[1]))

def askDBUser( name ):
	db_user = interface.askForString("Database Admin Username", default=name)
	db_pass = interface.askForPassword("Database Admin Password")
	return [ db_user, db_pass ]

if config['database']['on_deploy'] == 1:
	config['database'] = deployer.configure_database( config['database'], str(config['name']) )
db = config['database']

if db['gen'] == 1:
	(db_user, db_pass) = askDBUser( 'root' )
	if db['type'] == 'mysql':
		dbo = database.MySQLServer( host=db['server'], port=db['port'], username=db_user, password=db_pass, askmethod=askDBUser )
	dbo.createDatabase(str(db['name']))
	if str(db['server'])=='localhost':
		dbo.createUser(str(db['username']), str(db['password']))
		dbo.grantAll(str(db['name']), str(db['username']))
	else:
		dbo.createUser(str(db['username']), str(db['password']), str(config['domain']))
		dbo.grantAll(str(db['name']), str(db['username']), str(config['domain']))
	dbo.commit()


installer.fileReplacement( config, os.path.join(www_dir,str(config['name']),"settings.py") )