Browse Source

Merge branch 'python' of github.com:rtCamp/easyengine into python

bugfixes
gau1991 10 years ago
parent
commit
ad55547c0b
  1. 36
      ee/cli/plugins/site.py
  2. 44
      ee/cli/plugins/site_functions.py
  3. 23
      ee/core/logging.py

36
ee/cli/plugins/site.py

@ -197,7 +197,6 @@ class EESiteCreateController(CementBaseController):
if (self.app.pargs.wpsubdir and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or
self.app.pargs.wpsubdomain or self.app.pargs.wp)):
print("Inside wpsubdir")
if (self.app.pargs.wpsubdir and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
@ -272,14 +271,23 @@ class EESiteCreateController(CementBaseController):
# Setup database for MySQL site
if 'ee_db_name' in data.keys() and not data['wp']:
data = SetupDatabase(self, data)
eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot), 'w')
eedbconfig.write("<?php \ndefine('DB_NAME', '{0}');"
"\ndefine('DB_USER', '{1}'); "
"\ndefine('DB_PASSWORD', '{2}');"
"\ndefine('DB_HOST', '{3}');\n?>"
.format(data['ee_db_name'], data['ee_db_user'],
data['ee_db_pass'], data['ee_db_host']))
eedbconfig.close()
try:
eedbconfig = open("{0}/ee-config.php".format(ee_site_webroot),
'w')
eedbconfig.write("<?php \ndefine('DB_NAME', '{0}');"
"\ndefine('DB_USER', '{1}'); "
"\ndefine('DB_PASSWORD', '{2}');"
"\ndefine('DB_HOST', '{3}');\n?>"
.format(data['ee_db_name'],
data['ee_db_user'],
data['ee_db_pass'],
data['ee_db_host']))
eedbconfig.close()
except IOError as e:
self.app.log.error("Unable to create ee-config.php for "
"{2} ({0}): {1}"
.format(e.errno, e.strerror, ee_domain))
sys.exit(1)
# Setup WordPress if Wordpress site
if data['wp']:
ee_wp_creds = SetupWordpress(self, data)
@ -288,10 +296,12 @@ class EESiteCreateController(CementBaseController):
# Setup Permissions for webroot
SetWebrootPermissions(self, data['webroot'])
if data['wp']:
print("WordPress Admin User : {0}".format(ee_wp_creds['wp_user']))
print("WordPress Admin User Password : {0}"
.format(ee_wp_creds['wp_pass']))
print("Successfully created site http://{0}".format(ee_www_domain))
Log.info(self, '\033[94m'+"WordPress Admin User :"
" {0}".format(ee_wp_creds['wp_user'])+'\033[0m')
Log.info(self, "WordPress Admin User Password : {0}"
.format(ee_wp_creds['wp_pass']))
Log.info(self, "Successfully created site"
" http://{0}".format(ee_www_domain))
class EESiteUpdateController(CementBaseController):

44
ee/cli/plugins/site_functions.py

@ -7,13 +7,14 @@ from ee.core.fileutils import EEFileUtils
from ee.core.mysql import EEMysql
from ee.core.shellexec import EEShellExec
from ee.core.variables import EEVariables
from ee.core.logging import Log
def SetupDomain(self, data):
ee_domain_name = data['site_name']
ee_site_webroot = data['webroot']
print("Creating {0}, please wait...".format(ee_domain_name))
self.app.log.info("Creating {0} ...".format(ee_domain_name))
# write nginx config for file
try:
ee_site_nginx_conf = open('/etc/nginx/sites-available/{0}.conf'
@ -23,11 +24,11 @@ def SetupDomain(self, data):
out=ee_site_nginx_conf)
ee_site_nginx_conf.close()
except IOError as e:
print("Unable to create nginx conf for {2} ({0}): {1}"
.format(e.errno, e.strerror, ee_domain_name))
Log.error(self, "Unable to create nginx conf for {2} ({0}): {1}"
.format(e.errno, e.strerror, ee_domain_name))
sys.exit(1)
except Exception as e:
print("{0}".format(e))
Log.error(self, "{0}".format(e))
sys.exit(1)
# create symbolic link for
@ -43,7 +44,7 @@ def SetupDomain(self, data):
if not os.path.exists('{0}/logs'.format(ee_site_webroot)):
os.makedirs('{0}/logs'.format(ee_site_webroot))
except Exception as e:
print("{0}".format(e))
Log.error(self, "{0}".format(e))
sys.exit(1)
EEFileUtils.create_symlink(self, ['/var/log/nginx/{0}.access.log'
@ -73,7 +74,7 @@ def SetupDatabase(self, data):
ee_db_name = input('Enter the MySQL database name [{0}]:'
.format(ee_replace_dot))
except EOFError as e:
print("{0} {1}".format(e.errorno, e.strerror))
Log.error(self, "{0} {1}".format(e.errorno, e.strerror))
sys.exit(0)
if not ee_db_name:
@ -86,7 +87,7 @@ def SetupDatabase(self, data):
ee_db_password = input('Enter the MySQL database password [{0}]: '
.format(ee_random))
except EOFError as e:
print("{0} {1}".format(e.errorno, e.strerror))
Log.error(self, "{0} {1}".format(e.errorno, e.strerror))
sys.exit(1)
if not ee_db_username:
@ -95,13 +96,14 @@ def SetupDatabase(self, data):
ee_db_password = ee_random
if len(ee_db_username) > 16:
print('Autofix MySQL username (ERROR 1470 (HY000)), please wait...')
self.app.log.info('Autofix MySQL username (ERROR 1470 (HY000)),'
' please wait...')
ee_random10 = (''.join(random.sample(string.ascii_uppercase +
string.ascii_lowercase + string.digits, 10)))
ee_db_name = (ee_db_name[0:6] + ee_random10)
# create MySQL database
print("Setting Up Database for {0}...".format(ee_domain_name))
self.app.log.info("Setting Up Database ...")
EEMysql.execute(self, "create database {0}"
.format(ee_db_name))
@ -135,7 +137,7 @@ def SetupWordpress(self, data):
ee_wp_user = ''
ee_wp_pass = ''
print("Downloading Wordpress, please wait...")
self.app.log.info("Downloading Wordpress...")
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "wp --allow-root core download")
@ -145,12 +147,12 @@ def SetupWordpress(self, data):
ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
.format(ee_replace_dot))
while re.match('^[A-Za-z0-9_]*$', ee_wp_prefix):
print("Warning: table prefix can only contain numbers, "
"letters, and underscores")
self.app.log.warn("table prefix can only "
"contain numbers, letters, and underscores")
ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
)
except EOFError as e:
print("{0} {1}".format(e.errorno, e.strerror))
Log.error(self, "{0} {1}".format(e.errorno, e.strerror))
sys.exit(1)
if not ee_wp_prefix:
@ -159,7 +161,7 @@ def SetupWordpress(self, data):
# Modify wp-config.php & move outside the webroot
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
print("Setting up WordPress Configuration...")
self.app.log.debug("Setting Up WordPress Configuration...")
if not data['multisite']:
EEShellExec.cmd_exec(self, "wp --allow-root core config "
+ "--dbname={0} --dbprefix={1} --dbuser={2} "
@ -184,9 +186,9 @@ def SetupWordpress(self, data):
if not ee_wp_user:
ee_wp_user = EEVariables.ee_user
while not ee_wp_user:
print("Warning: Usernames can have only alphanumeric"
"characters, spaces, underscores, hyphens,"
"periods and the @ symbol.")
self.app.log.warn("Usernames can have only alphanumeric"
"characters, spaces, underscores, hyphens,"
"periods and the @ symbol.")
ee_wp_user = input('Enter WordPress username: ')
if not ee_wp_pass:
@ -197,7 +199,7 @@ def SetupWordpress(self, data):
while not ee_wp_email:
ee_wp_email = input('Enter WordPress email: ')
print("Setting up WordPress, please wait...")
self.app.log.debug("Setting up WordPress Tables, please wait...")
if not data['multisite']:
EEShellExec.cmd_exec(self, "php /usr/bin/wp --allow-root core install "
@ -218,7 +220,7 @@ def SetupWordpress(self, data):
if not data['wpsubdir'] else ''),
errormsg="Unable to setup WordPress Tables")
print("Updating WordPress permalink, please wait...")
self.app.log.debug("Updating WordPress permalink, please wait...")
EEShellExec.cmd_exec(self, " php /usr/bin/wp --allow-root "
"rewrite structure "
"/%year%/%monthnum%/%day%/%postname%/",
@ -250,7 +252,7 @@ def SetupWordpressNetwork(self, data):
def InstallWP_Plugin(self, plugin_name, data):
ee_site_webroot = data['webroot']
print("Installing plugin {0}".format(plugin_name))
self.app.log.debug("Installing plugin {0}".format(plugin_name))
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "php /usr/bin/wp plugin --allow-root install "
"{0}".format(plugin_name),
@ -266,6 +268,6 @@ def InstallWP_Plugin(self, plugin_name, data):
def SetWebrootPermissions(self, webroot):
print("Setting up Webroot Permissions...")
self.app.log.debug("Setting Up Permissions...")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)

23
ee/core/logging.py

@ -0,0 +1,23 @@
class Log:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def error(self, msg):
self.app.log.error(Log.FAIL + msg + Log.ENDC)
def info(self, msg):
self.app.log.info(Log.OKBLUE + msg + Log.ENDC)
def warn(self, msg):
self.app.log.warn(Log.BOLD + msg + Log.ENDC)
def debug(self, msg):
self.app.log.debug(Log.HEADER + msg + Log.ENDC)
Loading…
Cancel
Save