.. autofunction:: soft_unlink
.. autofunction:: fetch
.. autofunction:: mixed_newlines
+.. autofunction:: random_key
Exceptions
----------
import shutil
import sqlalchemy
import sqlalchemy.exc
-import random
import string
import urlparse
import tempfile
deprecated_keys = set()
#: Keys that we can simply generate random strings for if they're missing
random_keys = set()
+ #: Values that are not sufficiently random for a random key. This can
+ #: include default values for a random configuration option,
+ random_blacklist = set()
#: Dictionary of variable names to extractor functions. These functions
#: take a :class:`wizard.deploy.Deployment` as an argument and return the value of
#: the variable, or ``None`` if it could not be found.
result[k] = extractor(deployment)
# XXX: ugh... we have to do quoting
for k in self.random_keys:
- if result[k] is None:
- result[k] = "'%s'" % ''.join(random.choice(string.letters + string.digits) for i in xrange(30))
+ if result[k] is None or result[k] in self.random_blacklist:
+ result[k] = "'%s'" % util.random_key()
return result
def dsn(self, deployment):
"""
:attr:`parametrized_files` and a simple search and replace on those
files.
"""
+ # deployment is not used in this implementation, but note that
+ # we do have the invariant the current directory matches
+ # deployment's directory
variables = ref_deployment.extract()
for file in self.parametrized_files:
try:
install_schema = install.ArgSchema("db", "admin", "email", "title")
deprecated_keys = set(['WIZARD_SECRETKEY'])
random_keys = set(['WIZARD_SECRETKEY', 'WIZARD_AUTH_KEY', 'WIZARD_SECURE_AUTH_KEY', 'WIZARD_LOGGED_IN_KEY', 'WIZARD_NONCE_KEY'])
+ random_blacklist = set(['put your unique phrase here'])
def urlFromExtract(self, deployment):
try:
meta = sql.connect(deployment.dsn)
pluggable_file.write(pluggable)
pluggable_file.close()
+ # replace random variable stubs with real values
+ old_config = open('wp-config.php').read()
+ def replace_with_random(s):
+ return s.replace('put your unique phrase here', util.random_key(), 1)
+ config = replace_with_random(old_config)
+ while config != old_config:
+ old_config = config
+ config = replace_with_random(config)
+ open('wp-config.php', 'w').write(config)
+
php.ini_replace_vars()
def upgrade(self, d, version, options):
result = d.fetch("wp-admin/upgrade.php?step=1")
import urllib
import time
import logging
+import random
+import string
import wizard
f.close() # just to be safe
return ret
+def random_key(length=30):
+ """Generates a random alphanumeric key of ``length`` size."""
+ return ''.join(random.choice(string.letters + string.digits) for i in xrange(length))
+
class NoOperatorInfo(wizard.Error):
"""No information could be found about the operator from Kerberos."""
pass