Browse Source

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

bugfixes
gau1991 10 years ago
parent
commit
2cb320a401
  1. 4
      ee/cli/plugins/clean.py
  2. 4
      ee/cli/plugins/secure.py
  3. 127
      ee/cli/plugins/site.py
  4. 8
      ee/cli/plugins/stack.py
  5. 3
      ee/core/addswap.py
  6. 6
      ee/core/download.py
  7. 2
      ee/core/extract.py
  8. 8
      ee/core/fileutils.py
  9. 33
      ee/core/services.py
  10. 10
      setup.py

4
ee/cli/plugins/clean.py

@ -18,8 +18,8 @@ class EECleanController(CementBaseController):
label = 'clean'
stacked_on = 'base'
stacked_type = 'nested'
description = 'clean command cleans different cache with following \
options'
description = ('clean command cleans different cache with following '
'options')
arguments = [
(['--all'],
dict(help='clean all cache', action='store_true')),

4
ee/cli/plugins/secure.py

@ -20,8 +20,8 @@ class EEsecureController(CementBaseController):
label = 'secure'
stacked_on = 'base'
stacked_type = 'nested'
description = 'clean command cleans different cache with following \
options'
description = ('clean command cleans different cache with following '
'options')
arguments = [
(['--auth'],
dict(help='secure auth', action='store_true')),

127
ee/cli/plugins/site.py

@ -11,6 +11,8 @@ from ee.core.git import EEGit
import sys
import os
import glob
import subprocess
from subprocess import Popen
def ee_site_hook(app):
@ -24,7 +26,7 @@ class EESiteController(CementBaseController):
stacked_on = 'base'
stacked_type = 'nested'
description = ('site command manages website configuration'
'with the help of the following subcommands')
' with the help of the following subcommands')
arguments = [
(['site_name'],
dict(help='website name')),
@ -35,11 +37,6 @@ class EESiteController(CementBaseController):
# TODO Default action for ee site command
print("Inside EESiteController.default().")
@expose(help="delete site example.com")
def delete(self):
# TODO Write code for ee site delete command here
print("Inside EESiteController.delete().")
@expose(help="enable site example.com")
def enable(self):
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
@ -152,8 +149,18 @@ class EESiteController(CementBaseController):
@expose(help="change to example.com's webroot")
def cd(self):
# TODO Write code for ee site cd here
print("Inside EESiteController.cd().")
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
ee_site_webroot = EEVariables.ee_webroot + ee_domain
EEFileUtils.chdir(self, ee_site_webroot)
try:
subprocess.call(['bash'])
except OSError as e:
Log.error(self, "Unable to edit file \ {0}{1}"
.format(e.errno, e.strerror))
sys.exit(1)
class EESiteCreateController(CementBaseController):
@ -809,11 +816,115 @@ class EESiteUpdateController(CementBaseController):
" http://{0}".format(ee_domain))
class EESiteDeleteController(CementBaseController):
class Meta:
label = 'delete'
stacked_on = 'site'
stacked_type = 'nested'
description = 'delete command deletes website'
arguments = [
(['site_name'],
dict(help='domain name to be deleted')),
(['--no-prompt'],
dict(help="dont ask for permission for delete",
action='store_true')),
(['--all'],
dict(help="delete all", action='store_true')),
(['--db'],
dict(help="delete db only", action='store_true')),
(['--files'],
dict(help="delete webroot only", action='store_true')),
]
@expose(help="update example.com")
def default(self):
# TODO Write code for ee site update here
(ee_domain, ee_www_domain) = ValidateDomain(self.app.pargs.site_name)
ee_db_name = ''
ee_prompt = ''
if os.path.isfile('/etc/nginx/sites-available/{0}'
.format(ee_domain)):
ee_site_webroot = EEVariables.ee_webroot + ee_domain
if self.app.pargs.no_prompt:
ee_prompt = 'Y'
if self.app.pargs.db:
if not ee_prompt:
ee_db_prompt = input('Do you want to delete database:[Y/N]'
)
else:
ee_db_prompt = 'Y'
if ee_db_prompt == 'Y':
deleteDB(ee_site_webroot)
if self.app.pargs.files:
if not ee_prompt:
ee_web_prompt = input('Do you want to delete webroot:[Y/N]'
)
else:
ee_web_prompt = 'Y'
if ee_web_prompt == 'Y':
deleteWebRoot(ee_site_webroot)
if self.app.pargs.all:
if not ee_prompt:
ee_db_prompt = input('Do you want to delete database:[Y/N]'
)
ee_web_prompt = input('Do you want to delete webroot:[Y/N]'
)
ee_nginx_prompt = input('Do you want to delete NGINX'
' configuration:[Y/N]')
else:
ee_db_prompt = 'Y'
ee_web_prompt = 'Y'
ee_nginx_prompt = 'Y'
if ee_db_prompt:
deleteDB(self, ee_site_webroot)
if ee_web_prompt:
deleteWebRoot(ee_site_webroot)
if ee_nginx_prompt:
EEFileutils.delete(self, '/etc/nginx/sites-available/{0}'
.format(ee_domain))
def deleteDB(self, webroot):
configfiles = glob.glob(webroot + '/*-config.php')
if configfiles:
if EEFileUtils.isexist(self, configfiles[0]):
ee_db_name = (EEFileUtils.grep(self, configfiles[0],
'DB_NAME').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_user = (EEFileUtils.grep(self, configfiles[0],
'DB_USER').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_pass = (EEFileUtils.grep(self, configfiles[0],
'DB_PASSWORD').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
ee_db_host = (EEFileUtils.grep(self, configfiles[0],
'DB_HOST').split(',')[1]
.split(')')[0].strip().replace('\'', ''))
EEMysql.execute(self,
"drop database {0}"
.format(ee_db_name))
if ee_db_user != 'root':
EEMysql.execute(self,
"drop user {0}@{1}"
.format(ee_db_user, ee_db_host))
EEMysql.execute(self,
"flush privileges")
def deleteWebRoot(webroot):
EEFileutils.delete(self, webroot)
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(EESiteController)
handler.register(EESiteCreateController)
handler.register(EESiteUpdateController)
handler.register(EESiteDeleteController)
# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', ee_site_hook)

8
ee/cli/plugins/stack.py

@ -929,7 +929,7 @@ class EEStackController(CementBaseController):
"roundcubemail/releases/download/"
"1.0.4/roundcubemail-1.0.4.tar.gz",
"/tmp/roundcube.tar.gz",
"roundcubemail"]]
"Roundcube"]]
if EEVariables.ee_ram > 1024:
apt_packages = apt_packages + EEVariables.ee_mailscanner
@ -966,7 +966,7 @@ class EEStackController(CementBaseController):
packages = packages + [["https://github.com/wp-cli/wp-cli/"
"releases/download/v0.17.1/"
"wp-cli.phar", "/usr/bin/wp",
"wp-cli"]]
"WP_CLI"]]
else:
Log.info(self, "WP-CLI is allready installed")
if self.app.pargs.phpmyadmin:
@ -979,7 +979,7 @@ class EEStackController(CementBaseController):
Log.debug(self, "Setting packages variable for Adminer ")
packages = packages + [["http://downloads.sourceforge.net/adminer"
"/adminer-4.1.0.php", "/var/www/22222/"
"htdocs/db/adminer/index.php", "adminer"]]
"htdocs/db/adminer/index.php", "Adminer"]]
if self.app.pargs.utils:
Log.debug(self, "Setting packages variable for utils")
@ -1006,7 +1006,7 @@ class EEStackController(CementBaseController):
"opcache/ocp.php", "ocp.php"],
["https://github.com/jokkedk/webgrind/"
"archive/master.tar.gz",
'/tmp/webgrind.tar.gz', 'webgrind.tar.gz'],
'/tmp/webgrind.tar.gz', 'Webgrind'],
["http://bazaar.launchpad.net/~percona-too"
"lkit-dev/percona-toolkit/2.1/download/he"
"ad:/ptquerydigest-20110624220137-or26tn4"

3
ee/core/addswap.py

@ -1,6 +1,7 @@
from ee.core.variables import EEVariables
from ee.core.shellexec import EEShellExec
from ee.core.fileutils import EEFileUtils
from ee.core.logging import Log
class EESwap():
@ -13,7 +14,7 @@ class EESwap():
def add(self):
if EEVariables.ee_ram < 512:
if EEVariables.ee_swap < 1000:
self.app.log.info("Adding SWAP")
Log.info(self, "Adding SWAP")
EEShellExec.cmd_exec(self, "dd if=/dev/zero of=/ee-swapfile "
"bs=1024 count=1048k")
EEShellExec.cmd_exec(self, "mkswap /ee-swapfile")

6
ee/core/download.py

@ -22,11 +22,11 @@ class EEDownload():
Log.info(self, "Downloading "+pkg_name+" ...")
urllib.request.urlretrieve(url, filename)
except urllib.error.URLError as e:
Log.info(self, "Unable to donwload file, [{err}]"
.format(err=str(e.reason)))
Log.error(self, "Unable to donwload file, [{err}] [FAIL]"
.format(err=str(e.reason)))
return False
except urllib.error.HTTPError as e:
Log.error(self, "Package download failed. [{err}]"
Log.error(self, "Package download failed. [{err}] [FAIL]"
.format(err=str(e.reason)))
return False
except urllib.error.ContentTooShortError as e:

2
ee/core/extract.py

@ -15,6 +15,6 @@ class EEExtract():
os.remove(file)
return True
except tarfile.TarError as e:
Log.error(self, 'Unable to extract file \{0} {1}'
Log.error(self, 'Unable to extract file \{0} {1} [FAIL]'
.format(e.errno, e.strerror))
return False

8
ee/core/fileutils.py

@ -53,17 +53,17 @@ class EEFileUtils():
try:
shutil.copy2(src, dest)
except shutil.Error as e:
Log.info(self, 'Error: {0}'.format(e))
Log.error(self, '{0}'.format(e))
except IOError as e:
Log.info(self, 'Error: {e}'.format(e.strerror))
Log.error(self, '{e}'.format(e.strerror))
def searchreplace(self, fnm, sstr, rstr):
try:
for line in fileinput.input(fnm, inplace=True):
Log.info(line.replace(sstr, rstr), end='')
Log.info(line.replace(sstr, rstr))
fileinput.close()
except Exception as e:
Log.info(self, 'Error : {0}'.format(e))
Log.error(self, '{0}'.format(e))
def mvfile(self, src, dst):
try:

33
ee/core/services.py

@ -17,11 +17,12 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} start'
.format(service_name))
if retcode[0] == 0:
Log.info(self, "Started : {0}".format(service_name))
Log.info(self, "Started : {0} [ok]"
.format(service_name))
else:
Log.error(self, retcode[1])
except OSError as e:
Log.error(self, "Failed to start service {0} {1}"
Log.error(self, "Failed to start service {0} {1} [FAIL]"
.format(e.errno, e.strerror))
return False
@ -30,12 +31,13 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} stop'
.format(service_name))
if retcode[0] == 0:
Log.info(self, "Stopped : {0}".format(service_name))
Log.info(self, "Stopped : {0} [OK]"
.format(service_name))
return True
else:
return False
except OSError as e:
Log.error(self, "Failed to stop service : {0}{1}"
Log.error(self, "Failed to stop service : {0}{1} [FAIL]"
.format(e.errno, e.strerror))
return False
@ -43,8 +45,10 @@ class EEService():
try:
EEService.stop_service(self, service_name)
EEService.start_service(self, service_name)
Log.info(self, "restart : {0} [OK]"
.format(service_name))
except OSError as e:
Log.error(self, "Failed to restart services \{0} {1}"
Log.error(self, "Failed to restart services \{0} {1} [FAIL]"
.format(e.errno, e.strerror))
def reload_service(self, service_name):
@ -55,26 +59,27 @@ class EEService():
if retcode[0] == 0:
subprocess.getstatusoutput('service {0} reload'
.format(service_name))
self.app.log.info("reload : {0} [OK]"
.format(service_name))
Log.info(self, "reload : {0} [OK]"
.format(service_name))
return True
else:
self.app.log.error("reload : {0} [FAIL]"
.format(service_name))
self.app.log.debug("{0}"
.format(retcode[1]))
Log.error(self, "reload : {0} [FAIL]"
.format(service_name))
Log.debug("{0}"
.format(retcode[1]))
return False
retcode = subprocess.getstatusoutput('service {0} reload'
.format(service_name))
if retcode[0] == 0:
Log.info(self, "reload : {0}".format(service_name))
Log.info(self, "reload : {0} [OK]"
.format(service_name))
return True
else:
return False
except OSError as e:
Log.error(self, "Failed to reload {0} {1}"
Log.error(self, "Failed to reload {0} {1} [FAIL]"
.format(service_name, e))
sys.exit(1)
@ -92,6 +97,6 @@ class EEService():
else:
return False
except OSError as e:
Log.error(self, "Unable to get services status \ {0}{1}"
Log.error(self, "Unable to get services status \ {0}{1} [FAIL]"
.format(e.errno, e.strerror))
return False

10
setup.py

@ -16,11 +16,11 @@ for name in glob.glob('ee/cli/templates/*.mustache'):
setup(name='ee',
version='3.0',
description="EasyEngine is the commandline tool to manage your Websites"
" based on WordPress and NGINX with easy to use commands.",
long_description="EasyEngine is the commandline tool to manage your "
"Websites based on WordPress and NGINX with easy"
" to use commands.",
description=('EasyEngine is the commandline tool to manage your Websites'
'based on WordPress and NGINX with easy to use commands.'),
long_description=('EasyEngine is the commandline tool to manage your '
'Websites based on WordPress and NGINX with easy'
'to use commands.'),
classifiers=[],
keywords='',
author='rtCamp Soultions Pvt. LTD',

Loading…
Cancel
Save