]> scripts.mit.edu Git - wizard.git/blob - wizard/app/phpBB.py
Rewrite parametrize to use new parametrizeWithVars
[wizard.git] / wizard / app / phpBB.py
1 import shutil
2 import logging
3 import os.path
4 import distutils.version
5
6 from wizard import app, install, resolve, util
7 from wizard.app import php
8
9 #phpBB                104 installs
10 #    2.0.19            87  ++++++++++++++++++++++++++++++
11 #    3.0.4             17  ++++++
12
13 CONFIG = 'config.php'
14 def make_filename_regex(var):
15     """See :ref:`versioning config <seed>` for more information."""
16     return CONFIG, php.re_var(var)
17
18 seed = util.dictmap(make_filename_regex, {
19         'WIZARD_DBSERVER' : 'dbhost',
20         'WIZARD_DBNAME' : 'dbname',
21         'WIZARD_DBUSER' : 'dbuser',
22         'WIZARD_DBPASSWORD' : 'dbpasswd' })
23
24 class Application(app.Application):
25     install_schema = install.ArgSchema('db', 'admin', 'email', 'title')
26     database = 'mysql'
27     parametrized_files = [ CONFIG ] + php.parametrized_files
28     extractors = app.make_extractors(seed)
29     extractors.update(php.extractors)
30     substitutions = app.make_substitutions(seed)
31     substitutions.update(php.substitutions)
32
33     def checkConfig(self, deployment):
34         return os.path.getsize('config.php')
35
36     def detectVersion(self, deployment):
37         version = str(self.detectVersionFromFile('install/update_to_latest.php', php.re_var('updates_to_version')))
38         if version.startswith('.'): # blehh, but phpBB2 uses '.0.19'...
39             version = '2' + version
40         return distutils.version.LooseVersion(version)
41
42     def remove(self, deployment, options):
43         app.remove_database(deployment)
44
45     def install(self, version, options):
46         old_mode = os.stat(".").st_mode
47         os.chmod("config.php", 0777)
48         self.install_2(options)
49         os.chmod("config.php", old_mode)
50         php.ini_replace_vars()
51
52     def install_2(self, options):
53         database_dict = {
54                 'lang' : 'english',
55                 'dbms' : 'mysql',
56                 'upgrade' : '0',
57                 'dbhost' : options.dsn.host,
58                 'dbname' : options.dsn.database,
59                 'dbuser' : options.dsn.username,
60                 'dbpasswd' : options.dsn.password,
61                 'prefix' : '',
62                 'board_email' : options.email,
63                 'server_name' : options.web_host,
64                 'server_port' : '80',
65                 'script_path' : options.web_path,
66                 'admin_name' : options.admin_name,
67                 'admin_pass1' : options.admin_password,
68                 'admin_pass2' : options.admin_password,
69                 'install_step' : '1',
70                 'cur_lang' : 'english' }
71
72         result = install.fetch(options, 'install/install.php', database_dict)
73         logging.debug('install.php output:\n\n' + result)
74         if 'Thank you' not in result:
75             raise app.InstallFailure()
76         #shutil.rmtree('install')
77         #shutil.rmtree('contrib')
78
79     def install_3(self, options):
80         def install_helper(sub, post):
81             uri = 'install/index.php?mode=install&language=en'
82             if sub:
83                 uri += '&sub=%s' % sub
84             result = install.fetch(options, uri, post)
85             logging.debug('%s (%s) output:\n\n' % (uri, sub) + result)
86             return result
87
88         # *deep breath*
89         install_helper('', {})
90         install_helper('requirements', {})
91
92         database_dict = { 'img_imagick' : '/usr/bin/' }
93         install_helper('database', database_dict)
94
95         database_dict.update({
96                 'dbms' : 'mysql',
97                 'dbhost' : options.mysql_host,
98                 'dbname' : options.mysql_db,
99                 'dbuser' : options.mysql_user,
100                 'dbpasswd' : options.mysql_password,
101                 'table_prefix' : '',
102                 'img_imagick' : '/usr/bin/',
103                 'language' : 'en',
104                 'testdb' : 'true' })
105         install_helper('database', database_dict)
106
107         database_dict['dbport'] = ''
108         del database_dict['testdb']
109         install_helper('administrator', database_dict)
110
111         database_dict.update({
112                 'default_lang' : 'en',
113                 'admin_name' : options.admin_name,
114                 'admin_pass1' : options.admin_password,
115                 'admin_pass2' : options.admin_password,
116                 'board_email1' : options.email,
117                 'board_email2' : options.email,
118                 'check' : 'true' })
119         install_helper('administrator', database_dict)
120
121         del database_dict['check']
122         install_helper('config_file', database_dict)
123         install_helper('advanced', database_dict)
124
125         database_dict.update({
126                 'email_enable' : '1',
127                 'smtp_delivery' : '0',
128                 'smtp_auth' : 'PLAIN',
129                 'cookie_secure' : '0',
130                 'force_server_vars' : '0',
131                 'server_protocol' : 'http://',
132                 'server_name' : options.web_host,
133                 'server_port' : '80',
134                 'script_path' : options.web_path })
135         install_helper('create_table', database_dict)
136
137         database_dict.update({
138                 'ftp_path' : '',
139                 'ftp_user' : '',
140                 'ftp_pass' : '',
141                 'smtp_host' : '',
142                 'smtp_user' : '',
143                 'smtp_pass' : '' })
144         install_helper('final', database_dict)