this application.
"""
raise NotImplementedError
- def checkWeb(self, deployment, output=None):
+ def checkWeb(self, deployment):
"""
- Checks if the autoinstall is viewable from the web. To get
- the HTML source that was retrieved, pass a variable containing
- an empty list to ``output``; it will be mutated to have its
- first element be the output. Subclasses should provide an
- implementation.
+ Checks if the autoinstall is viewable from the web. Subclasses should
+ provide an implementation.
.. note::
Finding a reasonable heuristic that works across skinning
not to depend on pages that are not the main page.
"""
raise NotImplementedError
+ def checkWebPage(self, deployment, page, output):
+ """
+ Checks if a given page of an autoinstall contains a particular string.
+ """
+ page = deployment.fetch(page)
+ logging.info("checkWebPage:\n\n" + page)
+ return page.find(output) != -1
def checkConfig(self, deployment):
"""
Checks whether or not an autoinstall has been configured/installed
import lxml.cssselect
import lxml.etree
import StringIO
+import logging
from wizard import app, install, resolve, shell, util
from wizard.app import php
return os.path.isfile("LocalSettings.php")
def detectVersion(self, deployment):
return self.detectVersionFromFile("includes/DefaultSettings.php", php.re_var("wgVersion"))
- def checkWeb(self, deployment, out=None):
- page = deployment.fetch("/index.php?title=Main_Page")
- if type(out) is list:
- out.append(page)
- return page.find("<!-- Served") != -1
+ def checkWeb(self, deployment):
+ return self.checkWebPage(deployment, "/index.php?title=Main_Page", "<!-- Served")
def prepareMerge(self, deployment):
resolve.fix_newlines("LocalSettings.php")
def install(self, version, options):
- try:
- os.unlink("LocalSettings.php")
- except OSError:
- pass
-
+ util.soft_unlink("LocalSettings.php")
os.chmod("config", 0777) # XXX: vaguely sketchy
postdata = {
result_etree = lxml.etree.parse(StringIO.StringIO(result), lxml.etree.HTMLParser())
selector = lxml.cssselect.CSSSelector(".error")
error_messages = [e.text for e in selector(result_etree)]
- if options.verbose or options.debug: print result
+ logging.debug("Installation output:\n\n" + result)
if result.find("Installation successful") == -1:
if not error_messages:
raise app.InstallFailure()
return "http://wordpress.org/wordpress-%s.tar.gz" % version
def checkConfig(self, deployment):
return os.path.isfile("wp-config.php")
- def checkWeb(self, deployment, out=None):
- page = deployment.fetch("")
- if type(out) is list:
- out.append(page)
- return page.find("<html") != -1
+ def checkWeb(self, deployment):
+ # XXX: this sucks pretty hard
+ return self.checkWebPage(deployment, "", "<html")
def detectVersion(self, deployment):
- # XXX: Very duplicate code with MediaWiki; refactor
- contents = deployment.read("wp-includes/version.php")
- match = php.re_var("wp_version").search(contents)
- if not match: return None
- return distutils.version.LooseVersion(match.group(2)[1:-1])
+ return self.detectVersionFromFile("wp-includes/version.php", php.re_var("wp_version"))
def prepareMerge(self, deployment):
# This file shouldn't really be edited by users, but be careful: it's
# stored as DOS and not as UNIX, so you'll get conflicts if you add this line:
# resolve.fix_newlines("wp-config.php")
pass
def install(self, version, options):
- # XXX: Hmm... we should figure out something about this
- try:
- os.unlink("wp-config.php")
- except OSError:
- pass
+ util.soft_unlink("wp-config.php")
post_setup_config = {
'dbhost': options.mysql_host,
"""
Checks if the autoinstall is viewable from the web.
"""
- out = []
- if not self.application.checkWeb(self, out):
- raise WebVerificationError(out[0])
+ if not self.application.checkWeb(self):
+ raise WebVerificationError
def fetch(self, path, post=None):
"""
Performs a HTTP request on the website.
class WebVerificationError(Error):
"""Could not access the application on the web"""
- #: Contents of web page access
- contents = None
- def __init__(self, contents):
- self.contents = contents
def __str__(self):
return """
ERROR: We were not able to access the application on the
web. This may indicate that the website is behind
-authentication on the htaccess level. The contents
-of the page were:
-
-%s""" % self.contents
+authentication on the htaccess level. You can find
+the contents of the page from the debug backtraces."""
class UnknownWebPath(Error):
"""Could not determine application's web path."""
os.rename(file, name)
return name
+def soft_unlink(file):
+ """Unlink a file, but don't complain if it doesn't exist."""
+ try:
+ os.unlink(file)
+ except OSError:
+ pass
+
def fetch(host, path, subpath, post=None):
h = httplib.HTTPConnection(host)
fullpath = path.rstrip("/") + "/" + subpath.lstrip("/") # to be lenient about input we accept