~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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
"""

  This script is licensed under the GPLv3, Copyright Martin Owens 2008

  It's targeted towards Ubuntu/Debian server deployments but should be flexible
  enough to deploy onto other platforms. Email doctormo@gmail.com with pathces
  and suggestions.

"""

from moxml.config import Config
from modeploy import interface, database, installer, deployer, django, __version__
import sys, os, time

print "\nDjango MO-Deployer, version %s\n" % __version__

details_file = 'generated.xml'
web_user  = 'www-data'
web_group = 'www-data'
web_conf  = '/etc/apache2/sites-available'

options = {}
for a in sys.argv[1:]:
	if a[0:2] == '--':
		if a.find('=') >= 1:
			n = a.split('=')
			options[n[0][2:]] = n[1]
		else:
			options[a[2:]] = True
	else:
		print "Unknown option '%s'" % a

websites = django.websites()
if not websites:
	sys.exit()
sitename = websites[0]
print "Working with website '%s'" % sitename

if options.has_key('build-settings'):
	print """Building settings file...

  WARNING! this isn't perfect, please make sure you edit settings.template to add customised settings.
"""

	deployer.build_settings( sitename )
	print "\nSettings built, exiting.\n"
	sys.exit()


if not os.path.exists('settings.template'):
    print """
Unable to build site, in order to build a website the
settings file has to be a template. (settings.template)
If you want to generate this file automatically run:

%s --build-settings

""" % sys.argv[0]
    sys.exit()


if os.path.exists(details_file):
	use = interface.askYesNo("Would you like to use the existing configuration?", "y")
	if not use:
		os.remove(details_file)

details = Config(details_file, './')
details.saveOnExit()
details['name'] = sitename
details['apps'] = [ 'django' ]

if not details.has_key('same-version'):
	details['version'] = interface.askForString( label='Website Version', default=details['version'] )

# Questions about this deployment
if not details.has_key('domain') or options.has_key('regenerate-details'):
	deployer.plan_details( details )

details['www_dir'] = '/var/www/%s/' % details['domain']
details['id'] = str(details['name']).lower()

details['web_user']     = web_user
details['web_group']    = web_group
details['web_conf_dir'] = web_conf
details['apache_enabled_dir'] = os.path.abspath(os.path.join(web_conf,'..','sites-enabled'))
details['build_date']   = time.strftime("%a, %d %b %Y %H:%M:%S %z")

# Configure website details
deployer.plan_apache( details )
deployer.plan_debian( details )

if not details['database'] or options.has_key('regenerate-db'):
	# Database configuration
	details['database'] = deployer.plan_database( details )

if not details['media'] or options.has_key('regenerate-media'):
	# Media configuration
	details['media'] = deployer.plan_media( details )

if not details['stores'] or options.has_key('regenerate-stores'):
	# Configure which directories are data stores
	details['stores'] = deployer.plan_stores( details )

deployer.configure_apache( details )

deployer.configure_distutils( details )

deployer.configure_debian( details )

deployer.configure_website( details )

details['changelog']    = None
details['target_files'] = None
details['store_dirs']   = None
details['linked_files'] = None

print "\nSetup finished, hopefully you should now be able to run debuild to make your deb package.\n"