summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Boddie <paul@boddie.org.uk>2014-08-07 12:26:13 (GMT)
committerPaul Boddie <paul@boddie.org.uk>2014-08-07 12:26:13 (GMT)
commit258a9829cdf6f661ab4213586ad910ed47f5360d (patch)
tree1ccd523da85f9a0f729f90c38ef394a3f54e5562
parent10fa9029b4958df6c24a177a5daac150ad0a9e9f (diff)
downloadpykolab-258a9829cdf6f661ab4213586ad910ed47f5360d.tar.gz
Tidied php setup.
Added debconf support.
-rw-r--r--pykolab/setup/setup_php.py104
1 files changed, 62 insertions, 42 deletions
diff --git a/pykolab/setup/setup_php.py b/pykolab/setup/setup_php.py
index 7eed80d..91885f4 100644
--- a/pykolab/setup/setup_php.py
+++ b/pykolab/setup/setup_php.py
@@ -18,10 +18,7 @@
#
from augeas import Augeas
-import os
-import shutil
-import subprocess
-import tempfile
+from os.path import isfile, join
import components
@@ -30,6 +27,7 @@ import pykolab
from pykolab import utils
from pykolab.auth import Auth
from pykolab.constants import *
+from pykolab.setup.services import *
from pykolab.translate import _
log = pykolab.getLogger('pykolab.setup')
@@ -57,54 +55,76 @@ def cli_options():
help = _("Specify the path to the php.ini file used with the webserver.")
)
+ php_group.add_option(
+ "--reset-php-config",
+ dest = "reset_php_config",
+ action = "store_true",
+ default = False,
+ help = _("Reset the PHP configuration.")
+ )
+
def description():
return _("Setup PHP.")
def execute(*args, **kw):
- if conf.timezone == None:
- print >> sys.stderr, utils.multiline_message(
- _("""
- Please supply the timezone PHP should be using.
- You have to use a Continent or Country / City locality name
- like 'Europe/Berlin', but not just 'CEST'.
- """)
- )
-
- conf.timezone = utils.ask_question(
- _("Timezone ID"),
- default="UTC"
- )
-
- if not conf.php_ini_path == None:
- if not os.path.isfile(conf.php_ini_path):
- log.error(_("Cannot configure PHP through %r (No such file or directory)") % (conf.php_ini_path))
- return
- php_ini = conf.php_ini_path
- else:
- # Search and destroy
- php_ini = "/etc/php.ini"
- if not os.path.isfile(php_ini):
- php_ini = "/etc/php5/apache2/php.ini"
+ # Signal that interaction may occur. This will involve debconf and similar
+ # system-specific mechanisms if available.
- if not os.path.isfile(php_ini):
- log.error(_("Could not find PHP configuration file php.ini"))
- return
+ start_interaction("kolab-conf/title-php")
+ try:
+ _execute(*args, **kw)
+ finally:
+ stop_interaction()
- myaugeas = Augeas()
+def _execute(*args, **kw):
+ timezone = get_system_timezone()
+ php_ini = get_php_ini_file()
- setting_base = '/files%s/' % (php_ini)
+ if not php_ini:
+ if conf.php_ini_path:
+ log.error(_("Cannot configure PHP through %r (No such file or directory)") % (conf.php_ini_path))
+ else:
+ log.error(_("Could not find PHP configuration file php.ini"))
+ return
- setting = os.path.join(setting_base, 'Date', 'date.timezone')
- current_value = myaugeas.get(setting)
+ myaugeas = Augeas()
- if current_value == None:
- insert_paths = myaugeas.match('/files%s/Date/*' % (php_ini))
- insert_path = insert_paths[(len(insert_paths)-1)]
- myaugeas.insert(insert_path, 'date.timezone', False)
+ setting_base = '/files%s/' % php_ini
- log.debug(_("Setting key %r to %r") % ('Date/date.timezone', conf.timezone), level=8)
- myaugeas.set(setting, conf.timezone)
+ setting = join(setting_base, 'Date', 'date.timezone')
+ php_timezone = myaugeas.get(setting)
- myaugeas.save()
+ if php_timezone and not conf.reset_php_config:
+ if conf.check_only:
+ utils.setup_status("php", _("setup done"))
+ else:
+ print >> sys.stderr, _("The PHP configuration is already modified and will not be configured.")
+ else:
+ if conf.check_only:
+ utils.setup_status("php", _("needs setup"))
+ return
+ if timezone:
+ log.info(_("Using system timezone for PHP."))
+ elif conf.timezone:
+ log.info(_("Using configured timezone for PHP."))
+ else:
+ timezone = conf.timezone = ask_question("kolab-conf/php-timezone",
+ _("""
+ Please supply the region-based timezone PHP should be using.
+ You have to use a continent or 'country/city' locality name
+ like 'Europe/Berlin'. Conventional time zones such as CEST
+ are not acceptable.
+ """),
+ _("Timezone ID"),
+ default="UTC"
+ )
+
+ insert_paths = myaugeas.match('/files%s/Date/*' % php_ini)
+ myaugeas.insert(insert_paths[-1], 'date.timezone', False)
+
+ log.debug(_("Setting key %r to %r") % ('Date/date.timezone', timezone), level=8)
+ myaugeas.set(setting, timezone)
+
+ myaugeas.save()