Browse Source

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

bugfixes
shital.rtcamp 10 years ago
parent
commit
dc512bbf53
  1. 20
      ee/cli/ext/ee_outputhandler.py
  2. 25
      ee/cli/main.py
  3. 1
      ee/cli/plugins/clean.py
  4. 29
      ee/cli/plugins/debug.py
  5. 1
      ee/cli/plugins/import_slow_log.py
  6. 1
      ee/cli/plugins/info.py
  7. 1
      ee/cli/plugins/log.py
  8. 1
      ee/cli/plugins/secure.py
  9. 1
      ee/cli/plugins/site.py
  10. 4
      ee/cli/plugins/site_functions.py
  11. 10
      ee/cli/plugins/stack.py
  12. 79
      ee/core/aptget.py

20
ee/cli/ext/ee_outputhandler.py

@ -0,0 +1,20 @@
# Based on https://github.com/datafolklabs/cement/issues/295
# To avoid encoding releated error,we defined our custom output handler
# I hope we will remove this when we upgarde to Cement 2.6 (Not released yet)
import os
from cement.utils import fs
from cement.ext.ext_mustache import MustacheOutputHandler
class EEOutputHandler(MustacheOutputHandler):
class Meta:
label = 'ee_output_handler'
def _load_template_from_file(self, path):
for templ_dir in self.app._meta.template_dirs:
full_path = fs.abspath(os.path.join(templ_dir, path))
if os.path.exists(full_path):
self.app.log.debug('loading template file %s' % full_path)
return open(full_path, encoding='utf-8', mode='r').read()
else:
continue

25
ee/cli/main.py

@ -13,10 +13,9 @@ else:
from cement.core import foundation
from cement.utils.misc import init_defaults
from cement.core.exc import FrameworkError, CaughtSignal
from cement.utils import fs
from cement.ext.ext_mustache import MustacheOutputHandler
from cement.ext.ext_argparse import ArgParseArgumentHandler
from ee.core import exc
from ee.cli.ext.ee_outputhandler import EEOutputHandler
# Application default. Should update config/ee.conf to reflect any
# changes, or additions here.
@ -31,22 +30,12 @@ defaults['ee']['plugin_dir'] = '/var/lib/ee/plugins'
# External templates (generally, do not ship with application code)
defaults['ee']['template_dir'] = '/var/lib/ee/templates'
# Based on https://github.com/datafolklabs/cement/issues/295
# To avoid encoding releated error,we defined our custom output handler
# I hope we will remove this when we upgarde to Cement 2.6 (Not released yet)
class EEOutputHandler(MustacheOutputHandler):
class EEArgHandler(ArgParseArgumentHandler):
class Meta:
label = 'ee_output_handler'
label = 'ee_args_handler'
def _load_template_from_file(self, path):
for templ_dir in self.app._meta.template_dirs:
full_path = fs.abspath(os.path.join(templ_dir, path))
if os.path.exists(full_path):
self.app.log.debug('loading template file %s' % full_path)
return open(full_path, encoding='utf-8', mode='r').read()
else:
continue
def error(self, message):
super(EEArgHandler, self).error("unknown args")
class EEApp(foundation.CementApp):
@ -72,6 +61,8 @@ class EEApp(foundation.CementApp):
# default output handler
output_handler = EEOutputHandler
arg_handler = EEArgHandler
debug = TOGGLE_DEBUG

1
ee/cli/plugins/clean.py

@ -31,6 +31,7 @@ class EECleanController(CementBaseController):
(['--opcache'],
dict(help='Clean OpCache', action='store_true'))
]
usage = "ee clean [options]"
@expose(hide=True)
def default(self):

29
ee/cli/plugins/debug.py

@ -14,27 +14,6 @@ import glob
import signal
import subprocess
usage = """
Usage: ee debug {<sitename>} {arguments}
arguments usage:
--all --all=on start debugging all server parameters.
--all=off stop debugging all server parameters
--nginx --nginx=on start debugging nginx server configuration for site
--nginx=off stop debugging nginx server configuration for site
--rewrite --rewrite=on start debugging nginx rewrite rules for site
--rewrite=off stop debugging nginx rewrite rules for site
--php --php=on start debugging server php configuration
--php=off stop debugging server php configuration
--fpm --fpm=on start debugging fastcgi configuration
--fpm=off stop debugging fastcgi configuration
--mysql --mysql=on start debugging mysql server
--mysql=off stop debugging mysql server
--wp --wp=on start wordpress debugging
--wp=off stop wordpress debugging
"""
def debug_plugin_hook(app):
# do something with the ``app`` object here.
@ -89,6 +68,7 @@ class EEDebugController(CementBaseController):
(['site_name'],
dict(help='Website Name', nargs='?', default=None))
]
usage = "ee debug [<site_name>] [options] "
@expose(hide=True)
def debug_nginx(self):
@ -493,9 +473,10 @@ class EEDebugController(CementBaseController):
and (not self.app.pargs.all)
and (not self.app.pargs.site_name)):
if self.app.pargs.stop or self.app.pargs.start:
print("--start/stop option is deprecated in ee3.0.5", usage)
print("--start/stop option is deprecated in ee3.0.5")
self.app.args.print_help()
else:
print(usage)
self.app.args.print_help()
if self.app.pargs.all == 'on':
if self.app.pargs.site_name:
@ -519,7 +500,7 @@ class EEDebugController(CementBaseController):
and (not self.app.pargs.fpm) and (not self.app.pargs.mysql)
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite)
and self.app.pargs.site_name):
print(usage)
self.app.args.print_help()
# self.app.pargs.nginx = 'on'
# self.app.pargs.wp = 'on'
# self.app.pargs.rewrite = 'on'

1
ee/cli/plugins/import_slow_log.py

@ -16,6 +16,7 @@ class EEImportslowlogController(CementBaseController):
stacked_on = 'base'
stacked_type = 'nested'
description = 'Import MySQL slow log to Anemometer database'
usage = "ee import-slow-log"
@expose(hide=True)
def default(self):

1
ee/cli/plugins/info.py

@ -33,6 +33,7 @@ class EEInfoController(CementBaseController):
dict(help='Get Nginx configuration information',
action='store_true')),
]
usage = "ee info [options]"
@expose(hide=True)
def info_nginx(self):

1
ee/cli/plugins/log.py

@ -43,6 +43,7 @@ class EELogController(CementBaseController):
(['site_name'],
dict(help='Website Name', nargs='?', default=None))
]
usage = "ee log [<site_name>] [options]"
@expose(hide=True)
def default(self):

1
ee/cli/plugins/secure.py

@ -34,6 +34,7 @@ class EESecureController(CementBaseController):
dict(help='user input', nargs='?', default=None)),
(['user_pass'],
dict(help='user pass', nargs='?', default=None))]
usage = "ee secure [options]"
@expose(hide=True)
def default(self):

1
ee/cli/plugins/site.py

@ -31,6 +31,7 @@ class EESiteController(CementBaseController):
(['site_name'],
dict(help='Website name', nargs='?')),
]
usage = "ee site (command) <site_name> [options]"
@expose(hide=True)
def default(self):

4
ee/cli/plugins/site_functions.py

@ -156,7 +156,9 @@ def setupwordpress(self, data):
Log.info(self, "Downloading Wordpress \t\t", end='')
EEFileUtils.chdir(self, '{0}/htdocs/'.format(ee_site_webroot))
EEShellExec.cmd_exec(self, "wp --allow-root core download")
EEShellExec.cmd_exec(self, "wp --allow-root core"
" download") or Log.error(self, "Unable to download"
" wordpress core")
Log.info(self, "[" + Log.ENDC + "Done" + Log.OKBLUE + "]")
if not (data['ee_db_name'] and data['ee_db_user'] and data['ee_db_pass']):

10
ee/cli/plugins/stack.py

@ -69,6 +69,7 @@ class EEStackController(CementBaseController):
(['--utils'],
dict(help='Install Utils stack', action='store_true')),
]
usage = "ee stack (command) [options]"
@expose(hide=True)
def default(self):
@ -546,6 +547,15 @@ class EEStackController(CementBaseController):
"/dovecot.pem")
# Custom Dovecot configuration by EasyEngine
data = dict()
Log.debug(self, "Writting configuration into file"
"/etc/dovecot/conf.d/auth-sql.conf.ext ")
ee_dovecot = open('/etc/dovecot/conf.d/auth-sql.conf.ext',
encoding='utf-8', mode='w')
self.app.render((data), 'auth-sql-conf.mustache',
out=ee_dovecot)
ee_dovecot.close()
data = dict(email=EEVariables.ee_email)
Log.debug(self, "Writting configuration into file"
"/etc/dovecot/conf.d/99-ee.conf ")

79
ee/core/aptget.py

@ -2,6 +2,7 @@
import apt
import apt_pkg
import sys
import subprocess
from ee.core.logging import Log
from sh import apt_get
from sh import ErrorReturnCode
@ -14,14 +15,22 @@ class EEAptGet():
"""
Similar to `apt-get upgrade`
"""
global apt_get
apt_get = apt_get.bake("-y")
try:
for line in apt_get.update(_iter=True):
Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to run apt-get update")
with open('/var/log/ee/ee.log', 'a') as f:
proc = subprocess.Popen('apt-get update',
shell=True,
stdin=None, stdout=f, stderr=f,
executable="/bin/bash")
proc.wait()
if proc.returncode == 0:
return True
else:
Log.error(self, "Unable to run apt-get update")
except Exception as e:
Log.error(self, "Error while installing packages, "
"apt-get exited with error")
def dist_upgrade():
"""
@ -44,30 +53,48 @@ class EEAptGet():
Log.error(self, 'Unable to Fetch update')
def install(self, packages):
global apt_get
apt_get = apt_get.bake("-y")
all_packages = ' '.join(packages)
try:
for line in apt_get.install("-o",
"Dpkg::Options::=--force-confold",
*packages, _iter=True):
Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to run apt-get install")
with open('/var/log/ee/ee.log', 'a') as f:
proc = subprocess.Popen("apt-get install -o Dpkg::Options::=--"
"force-confold -y {0}"
.format(all_packages), shell=True,
stdin=None, stdout=f, stderr=f,
executable="/bin/bash")
proc.wait()
if proc.returncode == 0:
return True
else:
Log.error(self, "Unable to run apt-get install")
except Exception as e:
Log.error(self, "Error while installing packages, "
"apt-get exited with error")
def remove(self, packages, auto=False, purge=False):
global apt_get
apt_get = apt_get.bake("-y")
all_packages = ' '.join(packages)
try:
if purge:
for line in apt_get.purge(*packages, _iter=True):
Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
with open('/var/log/ee/ee.log', 'a') as f:
if purge:
proc = subprocess.Popen('apt-get purge -y {0}'
.format(all_packages), shell=True,
stdin=None, stdout=f, stderr=f,
executable="/bin/bash")
else:
proc = subprocess.Popen('apt-get remove -y {0}'
.format(all_packages), shell=True,
stdin=None, stdout=f, stderr=f,
executable="/bin/bash")
proc.wait()
if proc.returncode == 0:
return True
else:
for line in apt_get.remove(*packages, _iter=True):
Log.info(self, Log.ENDC+line+Log.OKBLUE, end=' ')
except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to remove packages")
Log.error(self, "Unable to run apt-get remove/purge")
except Exception as e:
Log.error(self, "Error while installing packages, "
"apt-get exited with error")
def auto_clean(self):
"""

Loading…
Cancel
Save