Browse Source

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

bugfixes
gau1991 10 years ago
parent
commit
2c258a8a72
  1. 4
      ee/cli/plugins/clean.py
  2. 4
      ee/core/download.py
  3. 2
      ee/core/extract.py
  4. 54
      ee/core/fileutils.py
  5. 6
      ee/core/git.py
  6. 13
      ee/core/services.py
  7. 6
      ee/core/shellexec.py

4
ee/cli/plugins/clean.py

@ -57,8 +57,8 @@ class EECleanController(CementBaseController):
else: else:
Log.error(self, "Memcache not installed") Log.error(self, "Memcache not installed")
except Exception as e: except Exception as e:
Log.error(self, "Unable to restart memcached")
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to restart memcached")
@expose(hide=True) @expose(hide=True)
def clean_fastcgi(self): def clean_fastcgi(self):
@ -75,8 +75,8 @@ class EECleanController(CementBaseController):
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")
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to clean opacache")
def load(app): def load(app):

4
ee/core/download.py

@ -22,9 +22,9 @@ 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.debug(self, "[{err}]".format(err=str(e.reason)))
Log.error(self, "Unable to donwload file, {0}" Log.error(self, "Unable to donwload file, {0}"
.format(filename)) .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. {0}" Log.error(self, "Package download failed. {0}"
@ -32,8 +32,8 @@ class EEDownload():
Log.debug(self, "[{err}]".format(err=str(e.reason))) 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.debug(self, "{0}{1}".format(e.errno, e.strerror))
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} ".format(pkg_name)) "the expected amount \{0} ".format(pkg_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False return False

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

54
ee/core/fileutils.py

@ -24,9 +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 ')
Log.debug(self, "{err}".format(err=str(e.reason))) Log.debug(self, "{err}".format(err=str(e.reason)))
sys.exit(1) Log.error(self, 'Unable to Remove file ')
def create_symlink(self, paths, errormsg=''): def create_symlink(self, paths, errormsg=''):
src = paths[0] src = paths[0]
@ -35,9 +34,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 ")
Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1) Log.error(self, "Unable to create symbolic link ...\n ")
else: else:
Log.debug(self, "Destination: {0} exists".format(dst)) Log.debug(self, "Destination: {0} exists".format(dst))
@ -45,21 +43,20 @@ 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")
Log.debug(self, "{0}{1}".format(e.errno, e.strerror)) Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
sys.exit(1) Log.error(self, "Unable to reomove symbolic link ...\n")
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.debug(self, "{0}".format(e))
Log.error(self, 'Unable to copy file from {0} to {1}' Log.error(self, 'Unable to copy file from {0} to {1}'
.format(src, dest)) .format(src, dest))
Log.debug(self, "{0}".format(e))
except IOError as e: except IOError as e:
Log.debug(self, "{e}".format(e.strerror))
Log.error(self, "Unable to copy file from {0} to {1}" Log.error(self, "Unable to copy file from {0} to {1}"
.fromat(src, dest)) .fromat(src, dest))
Log.debug(self, "{e}".format(e.strerror))
def searchreplace(self, fnm, sstr, rstr): def searchreplace(self, fnm, sstr, rstr):
try: try:
@ -67,26 +64,24 @@ class EEFileUtils():
print(line.replace(sstr, rstr), end='') print(line.replace(sstr, rstr), end='')
fileinput.close() fileinput.close()
except Exception as e: except Exception as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to search {0} and replace {1} {2}" Log.error(self, "Unable to search {0} and replace {1} {2}"
.format(fnm, sstr, rstr)) .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.debug(self, "{err}".format(err=str(e.reason)))
Log.error(self, 'Unable to move file from {0} to {1}' Log.error(self, 'Unable to move file from {0} to {1}'
.format(src, dst)) .format(src, dst))
Log.debug(self, "{err}".format(err=str(e.reason)))
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 {0}'.format(path))
Log.debug(self, "{err}".format(err=e.strerror)) Log.debug(self, "{err}".format(err=e.strerror))
sys.exit(1) Log.error(self, 'Unable to Change Directory {0}'.format(path))
def chown(self, path, user, group, recursive=False): def chown(self, path, user, group, recursive=False):
try: try:
@ -101,13 +96,11 @@ 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(path))
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
sys.exit(1) Log.error(self, "Unable to change owner : {0}".format(path))
except Exception as e: except Exception as e:
Log.error(self, "Unable to change owner : {0} ".format(path))
Log.debug(self, "{0}".format(e)) Log.debug(self, "{0}".format(e))
sys.exit(1) Log.error(self, "Unable to change owner : {0} ".format(path))
def chmod(self, path, perm, recursive=False): def chmod(self, path, perm, recursive=False):
try: try:
@ -120,17 +113,15 @@ 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(path))
Log.debug(self, "{0}".format(e.strerror)) Log.debug(self, "{0}".format(e.strerror))
sys.exit(1) Log.error(self, "Unable to change owner : {0}".format(path))
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} ".format(path))
Log.debug(self, "{0}".format(e.strerror)) Log.debug(self, "{0}".format(e.strerror))
sys.exit(1) Log.error(self, "Unable to create directory {0} ".format(path))
def isexist(self, path): def isexist(self, path):
try: try:
@ -139,9 +130,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}".format(path))
Log.debug(self, "{0}".format(e.strerror)) Log.debug(self, "{0}".format(e.strerror))
sys.exit(1) Log.error(self, "Unable to check path {0}".format(path))
def grep(self, fnm, sstr): def grep(self, fnm, sstr):
try: try:
@ -149,9 +139,9 @@ 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}{1}" Log.debug(self, "{0}".format(e.strerror))
.format(e.strerror, "[FAIL]")) Log.error(self, "Unable to Search string {0} in {1}"
sys.exit(1) .format(sstr, fnm))
def rm(self, path): def rm(self, path):
if EEFileUtils.isexist(self, path): if EEFileUtils.isexist(self, path):
@ -161,10 +151,10 @@ class EEFileUtils():
else: else:
os.remove(path) os.remove(path)
except shutil.Error as e: except shutil.Error as e:
Log.error(self, "Unable to remove directory : {0} {1}" Log.debug(self, "{0}".format(e))
.format(path, e)) Log.error(self, "Unable to remove directory : {0} "
sys.exit(1) .format(path))
except OSError as e: except OSError as e:
Log.error(self, "Unable to remove file : {0} {1}" Log.debug(self, "{0}".format(e))
.format(path, e)) Log.error(self, "Unable to remove file : {0} "
sys.exit(1) .format(path))

6
ee/core/git.py

@ -21,10 +21,9 @@ class EEGit:
.format(path)) .format(path))
git.init(path) git.init(path)
except ErrorReturnCode as e: except ErrorReturnCode as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to git init at {0}" Log.error(self, "Unable to git init at {0}"
.format(path)) .format(path))
Log.error(self, "{0}".format(e))
sys.exit(1)
status = git.status("-s") status = git.status("-s")
if len(status.splitlines()) > 0: if len(status.splitlines()) > 0:
try: try:
@ -33,10 +32,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.debug(self, "{0}".format(e))
Log.error(self, "Unable to git commit at {0} " Log.error(self, "Unable to git commit at {0} "
.format(path)) .format(path))
Log.debug(self, "{0}".format(e))
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))

13
ee/core/services.py

@ -23,9 +23,9 @@ class EEService():
else: else:
Log.error(self, retcode[1]) Log.error(self, retcode[1])
except OSError as e: except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Failed to start service {0}" Log.error(self, "Failed to start service {0}"
.format(service_name)) .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):
@ -39,9 +39,9 @@ class EEService():
else: else:
return False return False
except OSError as e: except OSError as e:
Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
Log.error(self, "Failed to stop service : {0}" Log.error(self, "Failed to stop service : {0}"
.format(service_name)) .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):
@ -51,9 +51,9 @@ class EEService():
Log.info(self, "restart : {0:10}{1}" Log.info(self, "restart : {0:10}{1}"
.format(service_name, "[OK]")) .format(service_name, "[OK]"))
except OSError as e: except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Failed to restart services \{0}" Log.error(self, "Failed to restart services \{0}"
.format(service_name)) .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:
@ -67,8 +67,8 @@ class EEService():
.format(service_name, "[OK]")) .format(service_name, "[OK]"))
return True return True
else: else:
Log.error(self, "reload : {0}".format(service_name))
Log.debug("{0}".format(retcode[1])) Log.debug("{0}".format(retcode[1]))
Log.error(self, "reload : {0}".format(service_name))
return False return False
retcode = subprocess.getstatusoutput('service {0} reload' retcode = subprocess.getstatusoutput('service {0} reload'
@ -80,10 +80,9 @@ class EEService():
else: else:
return False return False
except OSError as e: except OSError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Failed to reload service {0}" Log.error(self, "Failed to reload service {0}"
.format(service_name)) .format(service_name))
Log.debug(self, "{0}".format(e))
sys.exit(1)
def get_service_status(self, service_name): def get_service_status(self, service_name):
try: try:
@ -99,7 +98,7 @@ class EEService():
else: else:
return False return False
except OSError as e: except OSError as e:
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
Log.error(self, "Unable to get services status of {0}" Log.error(self, "Unable to get services status of {0}"
.format(service_name)) .format(service_name))
Log.debug(self, "{0}{1}".format(e.errno, e.strerror))
return False return False

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

Loading…
Cancel
Save