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. 37
      ee/core/fileutils.py
  7. 8
      ee/core/mysql.py
  8. 53
      ee/core/services.py
  9. 12
      ee/core/shellexec.py

14
ee/cli/plugins/clean.py

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

6
ee/cli/plugins/secure.py

@ -75,14 +75,16 @@ class EEsecureController(CementBaseController):
"/etc/nginx/sites-available/22222" "/etc/nginx/sites-available/22222"
.format(port=port)) .format(port=port))
else: 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': if EEVariables.ee_platform_distro == 'Debian':
EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen " EEShellExec.cmd_exec(self, "sed -i \"s/listen.*/listen "
"{port} default_server ssl;/\" " "{port} default_server ssl;/\" "
"/etc/nginx/sites-available/22222" "/etc/nginx/sites-available/22222"
.format(port=port)) .format(port=port))
else: 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) @expose(hide=True)
def secure_ip(self): 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'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
if EEService.get_service_status(self, service): 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+" ...") Log.info(self, "Downloading "+pkg_name+" ...")
urllib.request.urlretrieve(url, filename) urllib.request.urlretrieve(url, filename)
except urllib.error.URLError as e: except urllib.error.URLError as e:
Log.error(self, "Unable to donwload file, [{err}] [FAIL]" Log.error(self, "Unable to donwload file, [{err}]{1}"
.format(err=str(e.reason))) .format("[FAIL]", err=str(e.reason)))
return False return False
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
Log.error(self, "Package download failed. [{err}] [FAIL]" Log.error(self, "Package download failed. [{err}] {1}"
.format(err=str(e.reason))) .format("[FAIL]", err=str(e.reason)))
return False return False
except urllib.error.ContentTooShortError as e: except urllib.error.ContentTooShortError as e:
Log.error(self, "Package download failed. The amount of the" Log.error(self, "Package download failed. The amount of the"

4
ee/core/extract.py

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

37
ee/core/fileutils.py

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

8
ee/core/mysql.py

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

53
ee/core/services.py

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

12
ee/core/shellexec.py

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

Loading…
Cancel
Save