Browse Source

custom error msg

bugfixes
harshadyeola 10 years ago
parent
commit
cd912517a5
  1. 14
      config/ee.conf
  2. 14
      ee/cli/controllers/base.py
  3. 4
      ee/cli/main.py
  4. 10
      ee/cli/plugins/clean.py
  5. 6
      ee/cli/plugins/secure.py
  6. 2
      ee/cli/plugins/stack_services.py
  7. 14
      ee/core/download.py
  8. 4
      ee/core/extract.py
  9. 56
      ee/core/fileutils.py
  10. 8
      ee/core/git.py
  11. 11
      ee/core/mysql.py
  12. 57
      ee/core/services.py
  13. 13
      ee/core/shellexec.py
  14. 6
      setup.py

14
config/ee.conf

@ -18,25 +18,25 @@
# template_dir = /var/lib/ee/templates/ # template_dir = /var/lib/ee/templates/
[log] [log.logging]
### Where the log file lives (no log file by default) ### Where the log file lives (no log file by default)
# file = none file = /var/log/ee/ee.log
### The level for which to log. One of: info, warn, error, fatal, debug ### The level for which to log. One of: info, warn, error, fatal, debug
# level = info level = debug
### Whether or not to log to console ### Whether or not to log to console
# to_console = true to_console = true
### Whether or not to rotate the log file when it reaches `max_bytes` ### Whether or not to rotate the log file when it reaches `max_bytes`
# rotate = false rotate = true
### Max size in bytes that a log file can grow until it is rotated. ### Max size in bytes that a log file can grow until it is rotated.
# max_bytes = 512000 max_bytes = 512000
### The maximun number of log files to maintain when rotating ### The maximun number of log files to maintain when rotating
# max_files = 4 max_files = 7
[stack] [stack]

14
ee/cli/controllers/base.py

@ -31,17 +31,3 @@ class EEBaseController(CementBaseController):
# #
# The 'default.mustache' file would be loaded from # The 'default.mustache' file would be loaded from
# ``ee.cli.templates``, or ``/var/lib/ee/templates/``. # ``ee.cli.templates``, or ``/var/lib/ee/templates/``.
#
# ViMbAdmin Nginx configuration
data = dict(site_name='webmail', www_domain='webmail', static=False,
basic=True, wp=False, w3tc=False, wpfc=False,
wpsc=False, multisite=False, wpsubdir=False,
webroot='/var/www', ee_db_name='',
ee_db_user='', ee_db_pass='', ee_db_host='',
rc=True)
self.app.log.debug('Writting the nginx configration for'
' ViMbAdmin')
ee_rc = open('/etc/nginx/sites-available/webmail.conf', 'w')
self.app.render((data), 'virtualconf.mustache',
out=ee_rc)
ee_rc.close()

4
ee/cli/main.py

@ -23,10 +23,6 @@ class EEApp(foundation.CementApp):
class Meta: class Meta:
label = 'ee' label = 'ee'
# Log writing to file
defaults = init_defaults('ee', 'log.logging')
defaults['log.logging']['file'] = '/tmp/my.log'
config_defaults = defaults config_defaults = defaults
# All built-in application bootstrapping (always run) # All built-in application bootstrapping (always run)

10
ee/cli/plugins/clean.py

@ -53,11 +53,12 @@ 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")
except: except Exception as e:
Log.error(self, "Unable to restart memcached") Log.error(self, "Unable to restart memcached")
Log.debug(self, "{0}".format(e))
@expose(hide=True) @expose(hide=True)
def clean_fastcgi(self): def clean_fastcgi(self):
@ -70,11 +71,12 @@ class EECleanController(CementBaseController):
@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")
Log.debug(self, "{0}".format(e))
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"))

14
ee/core/download.py

@ -22,16 +22,18 @@ 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, {0}"
.format(err=str(e.reason))) .format(filename))
Log.debug(self, "[{err}]".format(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. {0}"
.format(err=str(e.reason))) .format(pkg_name))
Log.debug(self, "[{err}]".format(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"
" downloaded data is less than " " downloaded data is less than "
"the expected amount \{0} {1}" "the expected amount \{0} ".format(pkg_name))
.format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False return False

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}'.format(file))
.format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False return False

56
ee/core/fileutils.py

@ -24,8 +24,8 @@ class EEFileUtils():
Log.info(self, "Removing "+os.path.basename(file)+"...") Log.info(self, "Removing "+os.path.basename(file)+"...")
shutil.rmtree(file) shutil.rmtree(file)
except shutil.Error as e: except shutil.Error as e:
Log.error(self, 'Unable to Remove file {err}' Log.error(self, 'Unable to Remove file ')
.format(err=str(e.reason))) Log.debug(self, "{err}".format(err=str(e.reason)))
sys.exit(1) sys.exit(1)
def create_symlink(self, paths, errormsg=''): def create_symlink(self, paths, errormsg=''):
@ -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 ")
" {1}".format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
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,40 +45,47 @@ 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")
.format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1) sys.exit(1)
def copyfile(self, src, dest): def copyfile(self, src, dest):
try: try:
shutil.copy2(src, dest) shutil.copy2(src, dest)
except shutil.Error as e: except shutil.Error as e:
Log.error(self, '{0}'.format(e)) Log.error(self, 'Unable to copy file from {0} to {1}'
.format(src, dest))
Log.debug(self, "{0}".format(e))
except IOError as e: except IOError as e:
Log.error(self, '{e}'.format(e.strerror)) Log.error(self, "Unable to copy file from {0} to {1}"
.fromat(src, dest))
Log.debug(self, "{e}".format(e.strerror))
def searchreplace(self, fnm, sstr, rstr): def searchreplace(self, fnm, sstr, rstr):
try: try:
for line in fileinput.input(fnm, inplace=True): for line in fileinput.input(fnm, inplace=True):
Log.info(line.replace(sstr, rstr)) print(line.replace(sstr, rstr), end='')
fileinput.close() fileinput.close()
except Exception as e: except Exception as e:
Log.error(self, '{0}'.format(e)) Log.error(self, "Unable to search {0} and replace {1} {2}"
.format(fnm, sstr, rstr))
Log.debug(self, "{0}".format(e))
def mvfile(self, src, dst): def mvfile(self, src, dst):
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 from {0} to {1}'
.format(err=str(e.reason))) .format(src, dst))
Log.debug(self, "{err}".format(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 {0}'.format(path))
.format(err=e.strerror)) Log.debug(self, "{err}".format(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 +101,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}".format(path))
Log.debug(self, "{0}".format(e))
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} ".format(path))
Log.debug(self, "{0}".format(e))
sys.exit(1) sys.exit(1)
def chmod(self, path, perm, recursive=False): def chmod(self, path, perm, recursive=False):
@ -111,15 +120,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}".format(path))
Log.debug(self, "{0}".format(e.strerror))
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} ".format(path))
.format(e.strerror)) Log.debug(self, "{0}".format(e.strerror))
sys.exit(1) sys.exit(1)
def isexist(self, path): def isexist(self, path):
@ -129,8 +139,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}".format(path))
.format(e.strerror)) Log.debug(self, "{0}".format(e.strerror))
sys.exit(1) sys.exit(1)
def grep(self, fnm, sstr): def grep(self, fnm, sstr):
@ -139,8 +149,8 @@ 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)
def rm(self, path): def rm(self, path):

8
ee/core/git.py

@ -21,7 +21,9 @@ class EEGit:
.format(path)) .format(path))
git.init(path) git.init(path)
except ErrorReturnCode as e: except ErrorReturnCode as e:
Log.error(e) Log.error(self, "Unable to git init at {0}"
.format(path))
Log.error(self, "{0}".format(e))
sys.exit(1) sys.exit(1)
status = git.status("-s") status = git.status("-s")
if len(status.splitlines()) > 0: if len(status.splitlines()) > 0:
@ -31,7 +33,9 @@ class EEGit:
git.add("--all") git.add("--all")
git.commit("-am {0}".format(msg)) git.commit("-am {0}".format(msg))
except ErrorReturnCode as e: except ErrorReturnCode as e:
Log.error(e) Log.error(self, "Unable to git commit at {0} "
.format(path))
Log.debug(self, "{0}".format(e))
sys.exit(1) sys.exit(1)
else: else:
Log.debug(self, "EEGit: Path {0} not present".format(path)) Log.debug(self, "EEGit: Path {0} not present".format(path))

11
ee/core/mysql.py

@ -31,20 +31,21 @@ class EEMysql():
cur = conn.cursor() cur = conn.cursor()
except Exception as e: except Exception as e:
if errormsg: if errormsg:
Log.debug(self, '{0}'
.format(e))
Log.error(self, '{0}' Log.error(self, '{0}'
.format(errormsg)) .format(errormsg))
else: else:
Log.debug(self, '{0}'
.format(e))
Log.error(self, 'Unable to connect to database: {0}' Log.error(self, 'Unable to connect to database: {0}'
.format(e)) .format(e))
Log.debug(self, 'Unable to connect to database: {0}'
.format(e))
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:')
.format(e)) Lod.debug(self, "{0}".format(e))
cur.close() cur.close()
conn.close() conn.close()
sys.exit(1) sys.exit(1)

57
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,14 @@ 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}"
.format(e.errno, e.strerror)) .format(service_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False return False
def stop_service(self, service_name): def stop_service(self, service_name):
@ -31,25 +33,27 @@ 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}"
.format(e.errno, e.strerror)) .format(service_name))
Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
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}"
.format(e.errno, e.strerror)) .format(service_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
def reload_service(self, service_name): def reload_service(self, service_name):
try: try:
@ -59,34 +63,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}".format(service_name))
.format(service_name)) Log.debug("{0}".format(retcode[1]))
Log.debug("{0}"
.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 service {0}"
Log.error(self, "Failed to reload {0} {1} [FAIL]" .format(service_name))
.format(service_name, e)) Log.debug(self, "{0}".format(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 +99,7 @@ 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 of {0}"
.format(e.errno, e.strerror)) .format(service_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False return False

13
ee/core/shellexec.py

@ -24,10 +24,9 @@ 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}"
.format(e.errno, e.strerror)) .format(command))
Log.debug(self, "Unable to execute command \ {0}{1}" Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
.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 +36,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}".format(filepath))
.format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.debug(self, "Unable to edit file \ {0}{1}"
.format(e.errno, e.strerror))
sys.exit(1) sys.exit(1)

6
setup.py

@ -14,6 +14,12 @@ for name in glob.glob('config/plugins.d/*.conf'):
for name in glob.glob('ee/cli/templates/*.mustache'): for name in glob.glob('ee/cli/templates/*.mustache'):
templates.insert(1, name) templates.insert(1, name)
if not os.path.exists('/var/log/ee/'):
os.makedirs('/var/log/ee/')
if not os.path.exists('/var/lib/ee/'):
os.makedirs('/var/lib/ee/')
setup(name='ee', setup(name='ee',
version='3.0', version='3.0',
description=('EasyEngine is the commandline tool to manage your Websites' description=('EasyEngine is the commandline tool to manage your Websites'

Loading…
Cancel
Save