Browse Source

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

bugfixes
gau1991 10 years ago
parent
commit
d86a31ace5
  1. 14
      ee/cli/plugins/clean.py
  2. 6
      ee/cli/plugins/secure.py
  3. 2
      ee/cli/plugins/stack_services.py
  4. 8
      ee/core/download.py
  5. 4
      ee/core/extract.py
  6. 35
      ee/core/fileutils.py
  7. 8
      ee/core/mysql.py
  8. 51
      ee/core/services.py
  9. 12
      ee/core/shellexec.py

14
ee/cli/plugins/clean.py

@ -53,11 +53,11 @@ class EECleanController(CementBaseController):
try:
if(EEAptGet.is_installed("memcached")):
EEService.restart_service(self, "memcached")
Log.info(self, "Cleaning memcache..")
Log.info(self, "Cleaning memcache...")
else:
Log.error(self, "Memcache not installed")
Log.error(self, "Memcache not installed{0}".format("[FAIL]"))
except:
Log.error(self, "Unable to restart memcached")
Log.error(self, "Unable to restart memcached{0}".format("[FAIL]"))
@expose(hide=True)
def clean_fastcgi(self):
@ -65,16 +65,18 @@ class EECleanController(CementBaseController):
Log.info(self, "Cleaning NGINX FastCGI cache, please wait...")
EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*")
else:
Log.error(self, "Unable to clean FastCGI cache")
Log.error(self, "Unable to clean FastCGI cache{0}"
.format("[FAIL]"))
@expose(hide=True)
def clean_opcache(self):
try:
Log.info(self, "Cleaning opcache.... ")
Log.info(self, "Cleaning opcache... ")
wp = urllib.request.urlopen(" https://127.0.0.1:22222/cache"
"/opcache/opgui.php?page=reset").read()
except Exception as e:
Log.error(self, "Unable to clean opacache {0}".format(e))
Log.error(self, "Unable to clean opacache {0:10}{1}"
.format(e, "[FAIL]"))
def load(app):

6
ee/cli/plugins/secure.py

@ -75,14 +75,16 @@ class EEsecureController(CementBaseController):
"/etc/nginx/sites-available/22222"
.format(port=port))
else:
Log.info(self, "Unable to change EasyEngine admin port")
Log.info(self, "Unable to change EasyEngine admin port{0}"
.format("[FAIL]"))
if EEVariables.ee_platform_distro == 'Debian':
EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen "
"{port} default_server ssl;/\" "
"/etc/nginx/sites-available/22222"
.format(port=port))
else:
Log.info(self, "Unable to change EasyEngine admin port")
Log.info(self, "Unable to change EasyEngine admin port{0}"
.format("[FAIL]"))
@expose(hide=True)
def secure_ip(self):

2
ee/cli/plugins/stack_services.py

@ -124,4 +124,4 @@ class EEStackStatusController(CementBaseController):
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services:
if EEService.get_service_status(self, service):
Log.info(self, "{0}: Running".format(service))
Log.info(self, "{0:10}: {1}".format(service, "Running"))

8
ee/core/download.py

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

4
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} [FAIL]'
.format(e.errno, e.strerror))
Log.error(self, 'Unable to extract file \{0} {1}{2}'
.format(e.errno, e.strerror, "[FAIL]"))
return False

35
ee/core/fileutils.py

@ -36,7 +36,7 @@ class EEFileUtils():
os.symlink(src, dst)
except Exception as e:
Log.error(self, "Unable to create symbolic link ...\n {0} "
" {1}".format(e.errno, e.strerror))
" {1} {2}".format(e.errno, e.strerror, "[FAIL]"))
sys.exit(1)
else:
Log.debug(self, "Destination: {0} exists".format(dst))
@ -45,8 +45,8 @@ class EEFileUtils():
try:
os.unlink(filepath)
except Exception as e:
Log.error(self, "Unable to reomove symbolic link ...\n {0} {1}"
.format(e.errno, e.strerror))
Log.error(self, "Unable to reomove symbolic link ...\n {0} {1} {2}"
.format(e.errno, e.strerror, "[FAIL]"))
sys.exit(1)
def copyfile(self, src, dest):
@ -69,16 +69,16 @@ class EEFileUtils():
try:
shutil.move(src, dst)
except shutil.Error as e:
Log.error(self, 'Unable to move file {err}'
.format(err=str(e.reason)))
Log.error(self, 'Unable to move file {err}{1}'
.format("[FAIL]", err=str(e.reason)))
sys.exit(1)
def chdir(self, path):
try:
os.chdir(path)
except OSError as e:
Log.error(self, 'Unable to Change Directory {err}'
.format(err=e.strerror))
Log.error(self, 'Unable to Change Directory {1}{err}'
.format("[FAIL]", err=e.strerror))
sys.exit(1)
def chown(self, path, user, group, recursive=False):
@ -94,10 +94,12 @@ class EEFileUtils():
else:
shutil.chown(path, user=user, group=group)
except shutil.Error as e:
Log.error(self, "Unable to change owner : {0} ".format(e))
Log.error(self, "Unable to change owner : {0}{1}"
.format(e, "[FAIL]"))
sys.exit(1)
except Exception as e:
Log.error(self, "Unable to change owner {0}".format(e))
Log.error(self, "Unable to change owner {0}{1}"
.format(e, "[FAIL]"))
sys.exit(1)
def chmod(self, path, perm, recursive=False):
@ -111,15 +113,16 @@ class EEFileUtils():
else:
os.chmod(path, perm)
except OSError as e:
Log.error(self, "Unable to change owner {0}".format(e.strerror))
Log.error(self, "Unable to change owner {0}{1}"
.format(e.strerror, "[FAIL]"))
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))
Log.error(self, "Unable to create directory {0}{1} "
.format(e.strerror, "[FAIL]"))
sys.exit(1)
def isexist(self, path):
@ -129,8 +132,8 @@ class EEFileUtils():
else:
return (False)
except OSError as e:
Log.error(self, "Unable to check path {0}"
.format(e.strerror))
Log.error(self, "Unable to check path {0}{1}"
.format(e.strerror, "[FAIL]"))
sys.exit(1)
def grep(self, fnm, sstr):
@ -139,6 +142,6 @@ class EEFileUtils():
if sstr in line:
return line
except OSError as e:
Log.error(self, "Unable to Search string {0}"
.format(e.strerror))
Log.error(self, "Unable to Search string {0}{1}"
.format(e.strerror, "[FAIL]"))
sys.exit(1)

8
ee/core/mysql.py

@ -30,15 +30,15 @@ class EEMysql():
user=user, passwd=passwd)
cur = conn.cursor()
except Exception as e:
Log.error(self, 'Unable to connect to database: {0}'
.format(e))
Log.error(self, 'Unable to connect to database: {0} {1}'
.format(e, "[FAIL]"))
sys.exit(1)
try:
cur.execute(statement)
except Exception as e:
Log.error(self, 'Error occured while executing: {0}'
.format(e))
Log.error(self, 'Unable to execute statement: {0} {1}'
.format(e, "[FAIL]"))
cur.close()
conn.close()
sys.exit(1)

51
ee/core/services.py

@ -4,6 +4,7 @@ import sys
import subprocess
from subprocess import Popen
from ee.core.logging import Log
import pystache
class EEService():
@ -17,13 +18,13 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} start'
.format(service_name))
if retcode[0] == 0:
Log.info(self, "Started : {0} [ok]"
.format(service_name))
Log.info(self, "Started : {0:10}{1}"
.format(service_name, "[OK]"))
else:
Log.error(self, retcode[1])
except OSError as e:
Log.error(self, "Failed to start service {0} {1} [FAIL]"
.format(e.errno, e.strerror))
Log.error(self, "Failed to start service {0} {1} {2}"
.format(e.errno, e.strerror, "[FAIL]"))
return False
def stop_service(self, service_name):
@ -31,25 +32,25 @@ class EEService():
retcode = subprocess.getstatusoutput('service {0} stop'
.format(service_name))
if retcode[0] == 0:
Log.info(self, "Stopped : {0} [OK]"
.format(service_name))
Log.info(self, "Stopped : {0:10}{1}"
.format(service_name, "[OK]"))
return True
else:
return False
except OSError as e:
Log.error(self, "Failed to stop service : {0}{1} [FAIL]"
.format(e.errno, e.strerror))
Log.error(self, "Failed to stop service : {0}{1}{2}"
.format(e.errno, e.strerror, "[FAIL]"))
return False
def restart_service(self, service_name):
try:
EEService.stop_service(self, service_name)
EEService.start_service(self, service_name)
Log.info(self, "restart : {0} [OK]"
.format(service_name))
Log.info(self, "restart : {0:10}{1}"
.format(service_name, "[OK]"))
except OSError as e:
Log.error(self, "Failed to restart services \{0} {1} [FAIL]"
.format(e.errno, e.strerror))
Log.error(self, "Failed to restart services \{0} {1} {2}"
.format(e.errno, e.strerror, "[FAIL]"))
def reload_service(self, service_name):
try:
@ -59,34 +60,32 @@ class EEService():
if retcode[0] == 0:
subprocess.getstatusoutput('service {0} reload'
.format(service_name))
Log.info(self, "reload : {0} [OK]"
.format(service_name))
Log.info(self, "reload : {0} {0:10}"
.format(service_name, "[OK]"))
return True
else:
Log.error(self, "reload : {0} [FAIL]"
.format(service_name))
Log.debug("{0}"
.format(retcode[1]))
Log.error(self, "reload : {0}{1}"
.format(service_name, "[FAIL]"))
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} [OK]"
.format(service_name))
Log.info(self, "reload : {0:10}{1}"
.format(service_name, "[OK]"))
return True
else:
return False
except OSError as e:
Log.error(self, "Failed to reload {0} {1} [FAIL]"
.format(service_name, e))
Log.error(self, "Failed to reload {0} {1} {2}"
.format(service_name, e, "[FAIL]"))
sys.exit(1)
def get_service_status(self, service_name):
try:
is_exist = subprocess.getstatusoutput('which {0}'
.format(service_name))[0]
.format(service_name))
if is_exist == 0:
retcode = subprocess.getstatusoutput('service {0} status'
.format(service_name))
@ -97,6 +96,6 @@ class EEService():
else:
return False
except OSError as e:
Log.error(self, "Unable to get services status \ {0}{1} [FAIL]"
.format(e.errno, e.strerror))
Log.error(self, "Unable to get services status \ {0}{1}{2}"
.format(e.errno, e.strerror, "[FAIL]"))
return False

12
ee/core/shellexec.py

@ -24,10 +24,8 @@ class EEShellExec():
if errormsg:
Log.error(self, errormsg)
else:
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))
Log.error(self, "Unable to execute command \ {0}{1}{2}"
.format(e.errno, e.strerror, "[FAIL]"))
sys.exit(1)
def invoke_editor(self, filepath, errormsg=''):
@ -37,8 +35,6 @@ class EEShellExec():
if errormsg:
Log.error(self, errormsg)
else:
Log.error(self, "Unable to edit file \ {0}{1}"
.format(e.errno, e.strerror))
Log.debug(self, "Unable to edit file \ {0}{1}"
.format(e.errno, e.strerror))
Log.error(self, "Unable to edit file \ {0}{1}{2}"
.format(e.errno, e.strerror, "[FAIL]"))
sys.exit(1)

Loading…
Cancel
Save