Browse Source

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

bugfixes
gau1991 10 years ago
parent
commit
718f56ff14
  1. 383
      ee/cli/plugins/site.py
  2. 35
      ee/cli/plugins/site_functions.py
  3. 30
      ee/cli/plugins/sitedb.py
  4. 54
      ee/core/fileutils.py
  5. 11
      ee/core/shellexec.py
  6. 3
      ee/core/variables.py

383
ee/cli/plugins/site.py

@ -7,6 +7,7 @@ from ee.core.fileutils import EEFileUtils
from ee.cli.plugins.site_functions import *
from ee.core.services import EEService
from ee.cli.plugins.sitedb import *
from ee.core.git import EEGit
import sys
import os
@ -127,11 +128,12 @@ class EESiteCreateController(CementBaseController):
sys.exit(1)
# setup nginx configuration for site
# HTmL
# HTML
if (self.app.pargs.html and not (self.app.pargs.php or
self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=True, basic=False, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False,
@ -144,17 +146,19 @@ class EESiteCreateController(CementBaseController):
self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot)
stype = 'php'
cache = 'basic'
#ySQL
#MySQL
if (self.app.pargs.mysql and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.wp or self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False,
@ -168,8 +172,10 @@ class EESiteCreateController(CementBaseController):
self.app.pargs.wpsc) and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if (self.app.pargs.wp 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,
static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=False,
@ -178,8 +184,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wp'
cache = 'basic'
if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=False,
@ -188,8 +196,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wp'
cache = 'w3tc'
if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=False,
@ -198,8 +208,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wp'
cache = 'wpfc'
if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=False,
@ -208,10 +220,12 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wp'
cache = 'wpsc'
#WPSUBDIR
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)):
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,
@ -222,8 +236,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wpsubdir'
cache = 'basic'
if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True,
@ -232,8 +248,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wpsubdir'
cache = 'w3tc'
if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True,
@ -242,8 +260,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wpsubdir'
cache = 'wpfc'
if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True,
@ -252,12 +272,15 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wpsubdir'
cache = 'wpsc'
#WPSUBDOAIN
if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or
self.app.pargs.wpsubdir or self.app.pargs.wp)):
if (self.app.pargs.wpsubdomain 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,
static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=True,
@ -266,8 +289,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wpsubdomain'
cache = 'basic'
if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True,
@ -276,8 +301,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wpsubdomain'
cache = 'w3tc'
if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True,
@ -286,8 +313,10 @@ class EESiteCreateController(CementBaseController):
ee_db_host='')
stype = 'wpsubdomain'
cache = 'wpfc'
if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)):
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True,
@ -325,6 +354,10 @@ class EESiteCreateController(CementBaseController):
ee_wp_creds = SetupWordpress(self, data)
# Service Nginx Reload
EEService.reload_service(self, 'nginx')
EEGit.add(self, ["/etc/nginx"],
msg="{0} created with {1} {2}"
.format(ee_www_domain, stype, cache))
# Setup Permissions for webroot
SetWebrootPermissions(self, data['webroot'])
if data['wp']:
@ -334,7 +367,7 @@ class EESiteCreateController(CementBaseController):
.format(ee_wp_creds['wp_pass']))
addNewSite(self, ee_www_domain, stype, cache, ee_site_webroot)
Log.info(self, "Successfully created site"
" http://{0}".format(ee_www_domain))
" http://{0}".format(ee_domain))
class EESiteUpdateController(CementBaseController):
@ -370,21 +403,335 @@ class EESiteUpdateController(CementBaseController):
@expose(help="update example.com")
def default(self):
# TODO Write code for ee site update here
print("Inside EESiteUpdateController.default().")
# site command Options and subcommand calls and definations to
# mention here
# If using an output handler such as 'mustache', you could also
# render a data dictionary using a template. For example:
#
# data = dict(foo='bar')
# self.app.render(data, 'default.mustache')
#
#
# The 'default.mustache' file would be loaded from
# ``ee.cli.templates``, or ``/var/lib/ee/templates/``.
#
(ee_domain,
ee_www_domain, ) = ValidateDomain(self.app.pargs.site_name)
ee_site_webroot = EEVariables.ee_webroot + ee_domain
check_site = getSiteInfo(self, ee_domain)
if check_site is None:
Log.error(self, "Site {0} does not exist.".format(ee_domain))
else:
oldsitetype = check_site.site_type
oldcachetype = check_site.cache_type
if (self.app.pargs.html and not (self.app.pargs.php or
self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
pass
#PHP
if (self.app.pargs.php and not (self.app.pargs.html or
self.app.pargs.mysql or self.app.pargs.wp or self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if oldsitetype != 'html':
Log.error("Cannot update {0} to php".format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot,
currsitetype=oldsitetype, currcachetype=oldcachetype)
#MySQL
if (self.app.pargs.mysql and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.wp or self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if oldsitetype != 'html' or oldsitetype != 'php':
Log.error("Cannot update {0} to mysql".format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=True, wp=False, w3tc=False,
wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
#WP
if ((self.app.pargs.wp or self.app.pargs.w3tc or self.app.pargs.wpfc or
self.app.pargs.wpsc) and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or
self.app.pargs.wpsubdir or self.app.pargs.wpsubdomain)):
if (self.app.pargs.wp and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp']
and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wp basic"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp']
and oldsitetype not in ['basic', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wp w3tc".format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)):
if (oldsitetype not in ['html', 'php', 'wp']
and oldsitetype not in ['basic', 'w3tc', 'wpsc']):
Log.error("Cannot update {0} to wp wpfc".format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=False,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)):
if (oldsitetype not in ['html', 'php', 'wp']
and oldsitetype not in ['basic', 'w3tc', 'wpfc']):
Log.error("Cannot update {0} to wp wpsc".format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=False,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
#WPSUBDIR
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)):
if (self.app.pargs.wpsubdir and not (self.app.pargs.w3tc
or self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir']
and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdir basic"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=True,
wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir']
and oldsitetype not in ['basic', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdir w3tc"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True,
wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir']
and oldsitetype not in ['basic', 'w3tc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdir wpfc"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True,
wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdir']
and oldsitetype not in ['basic', 'w3tc', 'wpfc']):
Log.error("Cannot update {0} to wpsubdir wpsc"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True,
wpsubdir=True, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.wpsubdomain and not (self.app.pargs.html or
self.app.pargs.php or self.app.pargs.mysql or
self.app.pargs.wpsubdir or self.app.pargs.wp)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain']
and oldsitetype not in ['w3tc', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdomain basic"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=True, wp=True, w3tc=False,
wpfc=False, wpsc=False, multisite=True,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.w3tc and not
(self.app.pargs.wpfc or self.app.pargs.wpsc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain']
and oldsitetype not in ['basic', 'wpfc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdomain w3tc"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=True,
wpfc=False, wpsc=False, multisite=True,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.wpfc and not
(self.app.pargs.wpsc or self.app.pargs.w3tc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain']
and oldsitetype not in ['basic', 'w3tc', 'wpsc']):
Log.error("Cannot update {0} to wpsubdomain wpfc"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=True, wpsc=False, multisite=True,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
if (self.app.pargs.wpsc and not
(self.app.pargs.w3tc or self.app.pargs.wpfc)):
if (oldsitetype not in ['html', 'php', 'wp', 'wpsubdomain']
and oldsitetype not in ['basic', 'w3tc', 'wpfc']):
Log.error("Cannot update {0} to wpsubdomain wpsc"
.format(ee_domain))
sys.exit(1)
data = dict(site_name=ee_domain, www_domain=ee_www_domain,
static=False, basic=False, wp=True, w3tc=False,
wpfc=False, wpsc=True, multisite=True,
wpsubdir=False, webroot=ee_site_webroot,
ee_db_name='', ee_db_user='', ee_db_pass='',
ee_db_host='', currsitetype=oldsitetype,
currcachetype=oldcachetype)
# TODO take site backup before site update
siteBackup(self, data)
# TODO Check for required packages before update
# setup NGINX configuration, and webroot
SetupDomain(self, data)
if 'ee_db_name' in data.keys() and not data['wp']:
data = SetupDatabase(self, data)
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()
stype = mysql
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)
if oldsitetype == 'mysql':
config_file = (ee_site_webroot + '/backup/{0}/ee-config.php'
.format(EEVariables.ee_date))
data['ee_db_name'] = EEFileUtils.grep(EEFileUtils
.grep(self, config_file,
'DB_NAME')
.split(',')[1]
.split(')')[0].strip())
data['ee_db_user'] = EEFileUtils.grep(EEFileUtils
.grep(self, config_file,
'DB_USER')
.split(',')[1]
.split(')')[0].strip())
data['ee_db_pass'] = EEFileUtils.grep(EEFileUtils
.grep(self, config_file,
'DB_PASSWORD')
.split(',')[1]
.split(')')[0].strip())
# Setup WordPress if Wordpress site
if data['wp']:
ee_wp_creds = SetupWordpress(self, data)
# Service Nginx Reload
EEService.reload_service(self, 'nginx')
EEGit.add(self, ["/etc/nginx"],
msg="{0} created with {1} {2}"
.format(ee_www_domain, stype, cache))
# Setup Permissions for webroot
SetWebrootPermissions(self, data['webroot'])
if data['wp']:
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']))
addNewSite(self, ee_www_domain, stype, cache, ee_site_webroot)
Log.info(self, "Successfully created site"
" http://{0}".format(ee_domain))
def load(app):

35
ee/cli/plugins/site_functions.py

@ -8,6 +8,7 @@ from ee.core.mysql import EEMysql
from ee.core.shellexec import EEShellExec
from ee.core.variables import EEVariables
from ee.core.logging import Log
import glob
def SetupDomain(self, data):
@ -141,7 +142,8 @@ def SetupWordpress(self, data):
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "wp --allow-root core download")
data = SetupDatabase(self, data)
if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):
data = SetupDatabase(self, data)
if prompt_wpprefix == 'True' or prompt_wpprefix == 'true':
try:
ee_wp_prefix = input('Enter the WordPress table prefix [wp_]: '
@ -247,7 +249,9 @@ def SetupWordpressNetwork(self, data):
ee_site_webroot = data['webroot']
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, 'wp --allow-root core multisite-convert'
'--title=')
'--title={0} {subdomains}'
.format(data['www_domain'], subdomains='--subdomains'
if not data['wpsubdir'] else ''))
def InstallWP_Plugin(self, plugin_name, data):
@ -271,3 +275,30 @@ def SetWebrootPermissions(self, webroot):
self.app.log.debug("Setting Up Permissions...")
EEFileUtils.chown(self, webroot, EEVariables.ee_php_user,
EEVariables.ee_php_user, recursive=True)
def siteBackup(self, data):
ee_site_webroot = data['webroot']
backup_path = ee_site_webroot + '/backup/{0}'.format(EEVariables.ee_date)
if not EEFileUtils.isexist(self, backup_path):
EEFileUtils.mkdir(self, backup_path)
Log.info(self, "Backup Location : {0}".format(backup_path))
EEFileUtils.copyfile(self, '/etc/nginx/sites-available/{0}.conf'
.format(data['ee_domain']), backup_path)
if data['currsitetype'] in ['html', 'php', 'mysql']:
Log.info(self, "Backup Webroot ...")
EEFileUtils.mvfile(self, ee_site_webroot + '/htdocs', backup_path)
configfiles = glob(ee_site_webroot + '/htdocs/*-config.php')
for file in configfiles:
if EEFileUtils.isexist(self, file):
ee_db_name = (EEFileUtils.grep(self, file, 'DB_NAME').split(',')[1]
.split(')')[0].strip())
Log.info(self, 'Backup Database, please wait')
EEShellExec.cmd_exec(self, "mysqldump {0} > {1}/{0}.sql"
.format(ee_db_name, backup_path),
"Failed: Backup Database")
# move wp-config.php/ee-config.php to backup
EEFileUtils.mvfile(self, file, backup_path)

30
ee/cli/plugins/sitedb.py

@ -27,9 +27,18 @@ class SiteDB(Base):
storage_fs = Column(String)
storage_db = Column(String)
# def __init__(self):
def __init__(self):
# from sqlalchemy import create_engine
# self.engine = create_engine('sqlite:///orm_in_detail.sqlite')
self.sitename = sitename
self.site_type = site_type
self.cache_type = cache_type
self.site_path = site_path
self.created_on = created_on
self.site_enabled = site_enabled
self.is_ssl = is_ssl
self.storage_fs = storage_fs
self.storage_db = storage_db
# if __name__ == "__main__":
#
@ -69,3 +78,22 @@ def addNewSite(self, site, stype, cache, path,
Log.error(self, "Unable to add site to database : {0}"
.format(e))
sys.exit(1)
def getSiteInfo(self, site):
db_path = self.app.config.get('site', 'db_path')
try:
from sqlalchemy import create_engine
engine = create_engine(db_path)
from sqlalchemy.orm import sessionmaker
session = sessionmaker()
session.configure(bind=engine)
Base.metadata.create_all(engine)
s = session()
q = s.query(SiteDB).filter_by(sitename=site).first()
s.flush()
return q
except Exception as e:
Log.error(self, "Unable to add site to database : {0}"
.format(e))
sys.exit(1)

54
ee/core/fileutils.py

@ -5,6 +5,7 @@ import sys
import glob
import shutil
import fileinput
from ee.core.logging import Log
class EEFileUtils():
@ -25,11 +26,11 @@ class EEFileUtils():
shutil.rmtree(file)
self.app.log.info("Done")
except shutil.Error as e:
self.app.log.error('Unable to Remove file {err}'
.format(err=str(e.reason)))
Log.error(self, 'Unable to Remove file {err}'
.format(err=str(e.reason)))
sys.exit(1)
def create_symlink(self, paths):
def create_symlink(self, paths, errormsg=''):
src = paths[0]
dst = paths[1]
if not os.path.islink(dst):
@ -46,8 +47,8 @@ class EEFileUtils():
try:
os.unlink(filepath)
except Exception as e:
self.app.log.error("Unable to reomove symbolic link ...\n {0} {1}"
.format(e.errno, e.strerror))
Log.error(self, "Unable to reomove symbolic link ...\n {0} {1}"
.format(e.errno, e.strerror))
sys.exit(1)
def copyfile(self, src, dest):
@ -70,16 +71,16 @@ class EEFileUtils():
try:
shutil.move(src, dst)
except shutil.Error as e:
self.app.log.error('Unable to move file {err}'
.format(err=str(e.reason)))
Log.error(self, 'Unable to move file {err}'
.format(err=str(e.reason)))
sys.exit(1)
def chdir(self, path):
try:
os.chdir(path)
except OSError as e:
self.app.log.error('Unable to Change Directory {err}'
.format(err=e.strerror))
Log.error(self, 'Unable to Change Directory {err}'
.format(err=e.strerror))
sys.exit(1)
def chown(self, path, user, group, recursive=False):
@ -95,10 +96,10 @@ class EEFileUtils():
else:
shutil.chown(path, user=user, group=group)
except shutil.Error as e:
self.app.log.error("Unable to change owner : {0} ".format(e))
Log.error(self, "Unable to change owner : {0} ".format(e))
sys.exit(1)
except Exception as e:
self.app.log.error("Unable to change owner {0}".format(e))
Log.error(self, "Unable to change owner {0}".format(e))
sys.exit(1)
def chmod(self, path, perm, recursive=False):
@ -112,5 +113,34 @@ class EEFileUtils():
else:
os.chmod(path, perm)
except OSError as e:
self.log.error("Unable to change owner {0}".format(e.strerror))
Log.error(self, "Unable to change owner {0}".format(e.strerror))
sys.exit(1)
def mkdir(self, path):
try:
os.makedirs(path)
except OSError as e:
Log.error(self, "Unable to create directory {0}"
.format(e.strerror))
sys.exit(1)
def isexist(self, path):
try:
if os.path.exists(path):
return (True)
else:
return (False)
except OSError as e:
Log.error(self, "Unable to check path {0}"
.format(e.strerror))
sys.exit(1)
def grep(self, fnm, sstr):
try:
for line in open(fnm):
if sstr in line:
return line
except OSError as e:
Log.error(self, "Unable to Search string {0}"
.format(e.strerror))
sys.exit(1)

11
ee/core/shellexec.py

@ -3,6 +3,7 @@ import os
import sys
import subprocess
from subprocess import Popen
from ee.core.logging import Log
class EEShellExec():
@ -21,10 +22,10 @@ class EEShellExec():
return False
except OSError as e:
if errormsg:
self.app.log.error("{0}", errormsg)
Log.error(self, errormsg)
else:
self.app.log.error("Unable to execute command \ {0}{1}"
.format(e.errno, e.strerror))
self.app.log.debug("Unable to execute command \ {0}{1}"
.format(e.errno, e.strerror))
Log.error(self, "Unable to execute command \ {0}{1}"
.format(e.errno, e.strerror))
Log.debug(self, "Unable to execute command \ {0}{1}"
.format(e.errno, e.strerror))
sys.exit(1)

3
ee/core/variables.py

@ -5,6 +5,7 @@ import configparser
import os
import sys
import psutil
import datetime
class EEVariables():
@ -12,6 +13,8 @@ class EEVariables():
config = configparser.ConfigParser()
config.read(os.path.expanduser("~")+'/.gitconfig')
ee_date = datetime.datetime.now().strftime('%d%b%Y%H%M%S')
# EasyEngine core variables
ee_platform_distro = platform.linux_distribution()[0]
ee_platform_version = platform.linux_distribution()[1]

Loading…
Cancel
Save