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/
[log]
[log.logging]
### 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
# level = info
level = debug
### 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`
# rotate = false
rotate = true
### 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
# max_files = 4
max_files = 7
[stack]

14
ee/cli/controllers/base.py

@ -31,17 +31,3 @@ class EEBaseController(CementBaseController):
#
# The 'default.mustache' file would be loaded from
# ``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:
label = 'ee'
# Log writing to file
defaults = init_defaults('ee', 'log.logging')
defaults['log.logging']['file'] = '/tmp/my.log'
config_defaults = defaults
# All built-in application bootstrapping (always run)

10
ee/cli/plugins/clean.py

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

14
ee/core/download.py

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

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

56
ee/core/fileutils.py

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

8
ee/core/git.py

@ -21,7 +21,9 @@ class EEGit:
.format(path))
git.init(path)
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)
status = git.status("-s")
if len(status.splitlines()) > 0:
@ -31,7 +33,9 @@ class EEGit:
git.add("--all")
git.commit("-am {0}".format(msg))
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)
else:
Log.debug(self, "EEGit: Path {0} not present".format(path))

11
ee/core/mysql.py

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

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

13
ee/core/shellexec.py

@ -24,10 +24,9 @@ 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}"
.format(command))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1)
def invoke_editor(self, filepath, errormsg=''):
@ -37,8 +36,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}".format(filepath))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
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'):
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',
version='3.0',
description=('EasyEngine is the commandline tool to manage your Websites'

Loading…
Cancel
Save