cleanup code

This commit is contained in:
VirtuBox
2019-03-14 13:11:54 +01:00
parent 0c8aca3dd8
commit d6d2ebe0fc
4 changed files with 51 additions and 32 deletions

View File

@@ -1,6 +1,12 @@
"""WordOps main application entry point."""
import sys
import os
from cement.core import foundation
from cement.utils.misc import init_defaults
from cement.core.exc import FrameworkError, CaughtSignal
from cement.ext.ext_argparse import ArgParseArgumentHandler
from wo.core import exc
from wo.cli.ext.wo_outputhandler import WOOutputHandler
# this has to happen after you import sys, but before you import anything
# from Cement "source: https://github.com/datafolklabs/cement/issues/290"
@@ -10,13 +16,6 @@ if '--debug' in sys.argv:
else:
TOGGLE_DEBUG = False
from cement.core import foundation
from cement.utils.misc import init_defaults
from cement.core.exc import FrameworkError, CaughtSignal
from cement.ext.ext_argparse import ArgParseArgumentHandler
from wo.core import exc
from wo.cli.ext.wo_outputhandler import WOOutputHandler
# Application default. Should update config/wo.conf to reflect any
# changes, or additions here.
defaults = init_defaults('wo')

View File

@@ -193,7 +193,8 @@ class WOStackController(CementBaseController):
if len(apt_packages):
if set(WOVariables.wo_nginx).issubset(set(apt_packages)):
if set(["nginx-plus"]).issubset(set(apt_packages)) or set(["nginx"]).issubset(set(apt_packages)):
if set(["nginx-plus"]).issubset(set(apt_packages)) or
set(["nginx"]).issubset(set(apt_packages)):
# Fix for white screen death with NGINX PLUS
if not WOFileUtils.grep(self, '/etc/nginx/fastcgi_params',
'SCRIPT_FILENAME'):
@@ -372,7 +373,8 @@ class WOStackController(CementBaseController):
# Nginx-Plus does not have nginx package structure like this
# So creating directories
if set(["nginx-plus"]).issubset(set(apt_packages)) or set(["nginx"]).issubset(set(apt_packages)):
if set(["nginx-plus"]).issubset(set(apt_packages)) or
set(["nginx"]).issubset(set(apt_packages)):
Log.info(self,
"Installing WordOpsConfigurations for" "NGINX")
if not os.path.exists('/etc/nginx/sites-available'):
@@ -484,7 +486,8 @@ class WOStackController(CementBaseController):
WOGit.add(self,
["/etc/nginx"], msg="Adding Nginx into Git")
WOService.reload_service(self, 'nginx')
if set(["nginx-plus"]).issubset(set(apt_packages)) or set(["nginx"]).issubset(set(apt_packages)):
if set(["nginx-plus"]).issubset(set(apt_packages)) or
set(["nginx"]).issubset(set(apt_packages)):
WOShellExec.cmd_exec(self, "sed -i -e 's/^user/#user/'"
" -e '/^#user/a user"
"\ www-data\;'"
@@ -558,7 +561,8 @@ class WOStackController(CementBaseController):
"'\"$http_referer\" \"$http_user_agent\"';\n")
# setup nginx common folder for php7
if self.app.pargs.php73:
if os.path.isdir("/etc/nginx/common") and (not os.path.isfile("/etc/nginx/common/php73.conf")):
if os.path.isdir("/etc/nginx/common") and
(not os.path.isfile("/etc/nginx/common/php73.conf")):
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/locations-php73.conf')
@@ -600,7 +604,8 @@ class WOStackController(CementBaseController):
out=wo_nginx)
wo_nginx.close()
if os.path.isdir("/etc/nginx/common") and (not os.path.isfile("/etc/nginx/common/redis-php73.conf")):
if os.path.isdir("/etc/nginx/common") and
(not os.path.isfile("/etc/nginx/common/redis-php73.conf")):
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
'file /etc/nginx/common/redis-php73.conf')
@@ -618,7 +623,8 @@ class WOStackController(CementBaseController):
"upstream debug73 {\nserver 127.0.0.1:9173;\n}\n")
if set(WOVariables.wo_redis).issubset(set(apt_packages)):
if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/common/redis-php72.conf")):
if os.path.isfile("/etc/nginx/nginx.conf") and
(not os.path.isfile("/etc/nginx/common/redis-php72.conf")):
data = dict()
Log.debug(self, 'Writting the nginx configuration to '
@@ -639,8 +645,10 @@ class WOStackController(CementBaseController):
" server 127.0.0.1:6379;\n"
" keepalive 10;\n}\n")
if os.path.isfile("/etc/nginx/nginx.conf") and (not os.path.isfile("/etc/nginx/conf.d/redis.conf")):
with open("/etc/nginx/conf.d/redis.conf", "a") as redis_file:
if os.path.isfile("/etc/nginx/nginx.conf")
and (not os.path.isfile("/etc/nginx/conf.d/redis.conf")):
with open("/etc/nginx/conf.d/redis.conf", "a") as
redis_file:
redis_file.write("# Log format Settings\n"
"log_format rt_cache_redis "
"'$remote_addr "
@@ -778,7 +786,8 @@ class WOStackController(CementBaseController):
WOService.restart_service(self, 'php7.2-fpm')
# PHP7.3 configuration for debian
if (WOVariables.wo_platform_distro == 'debian') and set(WOVariables.wo_php73).issubset(set(apt_packages)):
if (WOVariables.wo_platform_distro == 'debian') and
set(WOVariables.wo_php73).issubset(set(apt_packages)):
# Create log directories
if not os.path.exists('/var/log/php/7.3/'):
Log.debug(self, 'Creating directory /var/log/php/7.3/')
@@ -903,7 +912,8 @@ class WOStackController(CementBaseController):
WOService.restart_service(self, 'php7.3-fpm')
# preconfiguration for php7.3
if (WOVariables.wo_platform_distro == 'ubuntu') and set(WOVariables.wo_php73).issubset(set(apt_packages)):
if (WOVariables.wo_platform_distro == 'ubuntu') and
set(WOVariables.wo_php73).issubset(set(apt_packages)):
# Create log directories
if not os.path.exists('/var/log/php/7.3/'):
Log.debug(self, 'Creating directory /var/log/php/7.3/')

View File

@@ -85,15 +85,18 @@ class WOStackStatusController(CementBaseController):
def stop(self):
"""Stop services"""
services = []
if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73
or self.app.pargs.mysql or self.app.pargs.memcached
or self.app.pargs.redis):
if not (self.app.pargs.nginx or self.app.pargs.php or
self.app.pargs.php73 or
self.app.pargs.mysql or
self.app.pargs.memcached or
self.app.pargs.redis):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.nginx:
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
if WOAptGet.is_installed(self, 'nginx-custom') or
WOAptGet.is_installed(self, 'nginx-mainline'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
@@ -148,15 +151,18 @@ class WOStackStatusController(CementBaseController):
def restart(self):
"""Restart services"""
services = []
if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73
or self.app.pargs.mysql or self.app.pargs.memcached
or self.app.pargs.redis):
if not (self.app.pargs.nginx or self.app.pargs.php or
self.app.pargs.php73 or
self.app.pargs.mysql or
self.app.pargs.memcached or
self.app.pargs.redis):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.nginx:
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
if WOAptGet.is_installed(self, 'nginx-custom') or
WOAptGet.is_installed(self, 'nginx-mainline'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
@@ -219,7 +225,8 @@ class WOStackStatusController(CementBaseController):
self.app.pargs.mysql = True
if self.app.pargs.nginx:
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
if WOAptGet.is_installed(self, 'nginx-custom') or
WOAptGet.is_installed(self, 'nginx-mainline'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")
@@ -274,15 +281,18 @@ class WOStackStatusController(CementBaseController):
def reload(self):
"""Reload service"""
services = []
if not (self.app.pargs.nginx or self.app.pargs.php or self.app.pargs.php73
or self.app.pargs.mysql or self.app.pargs.memcached
or self.app.pargs.redis):
if not (self.app.pargs.nginx or self.app.pargs.php or
self.app.pargs.php73 or
self.app.pargs.mysql or
self.app.pargs.memcached or
self.app.pargs.redis):
self.app.pargs.nginx = True
self.app.pargs.php = True
self.app.pargs.mysql = True
if self.app.pargs.nginx:
if WOAptGet.is_installed(self, 'nginx-custom') or WOAptGet.is_installed(self, 'nginx-mainline'):
if WOAptGet.is_installed(self, 'nginx-custom') or
WOAptGet.is_installed(self, 'nginx-mainline'):
services = services + ['nginx']
else:
Log.info(self, "Nginx is not installed")

View File

@@ -40,10 +40,10 @@ class WOSyncController(CementBaseController):
# search for wp-config.php inside htdocs/
if not configfiles:
Log.debug(self, "Config files not found in {0}/ "
.format(wo_site_webroot))
.format(wo_site_webroot))
if site.site_type != 'mysql':
Log.debug(self, "Searching wp-config.php in {0}/htdocs/ "
.format(wo_site_webroot))
.format(wo_site_webroot))
configfiles = glob.glob(wo_site_webroot + '/htdocs/wp-config.php')
if configfiles: