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