Browse Source

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

bugfixes
harshadyeola 10 years ago
parent
commit
abcc106026
  1. 27
      ee/cli/plugins/clean.py
  2. 11
      ee/cli/plugins/stack.py
  3. 155
      ee/core/aptget.py
  4. 4
      ee/core/fileutils.py

27
ee/cli/plugins/clean.py

@ -4,6 +4,7 @@ from ee.core.services import EEService
from cement.core.controller import CementBaseController, expose from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook from cement.core import handler, hook
import os import os
import urllib.request
def clean_plugin_hook(app): def clean_plugin_hook(app):
@ -48,32 +49,30 @@ class EECleanController(CementBaseController):
@expose(hide=True) @expose(hide=True)
def clean_memcache(self): def clean_memcache(self):
print("in memcache..") if(EEAptGet.is_installed("memcached")):
pkg = EEAptGet() self.app.log.info("memcache is installed")
if(pkg.is_installed("memcached")):
print("memcache is installed...")
EEService.restart_service(self, "memcached") EEService.restart_service(self, "memcached")
print("Cleaning memcache..") self.app.log.info("Cleaning memcache..")
else: else:
print("memcache is not installed..") self.app.log.info("memcache is not installed")
@expose(hide=True) @expose(hide=True)
def clean_fastcgi(self): def clean_fastcgi(self):
if(os.path.isdir("/var/run/nginx-cache")): if(os.path.isdir("/var/run/nginx-cache")):
print("Cleaning fastcgi...") self.app.log.info("Cleaning fastcgi...")
EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*") EEShellExec.cmd_exec(self, "rm -rf /var/run/nginx-cache/*")
else: else:
print("Error occur while Cleaning fastcgi..") self.app.log.info("Error occur while Cleaning fastcgi..")
@expose(hide=True) @expose(hide=True)
def clean_opcache(self): def clean_opcache(self):
try: try:
print("Cleaning opcache.... ") self.app.log.info("Cleaning opcache.... ")
EEShellExec.cmd_exec(self, "wget --no-check-certificate --spider" wp = urllib.request.urlopen(" https://127.0.0.1:22222/cache"
" -q https://127.0.0.1:22222/cache/opcache" "/opcache/opgui.php?page=reset").read()
"/opgui.php?page=reset") except Exception as e:
except OSError: self.app.log.info("Unable to clean opacache\n {0}{1}"
print("Unable to clean opache..") .format(e.errno, e.strerror))
def load(app): def load(app):

11
ee/cli/plugins/stack.py

@ -707,7 +707,6 @@ class EEStackController(CementBaseController):
@expose() @expose()
def install(self, packages=[], apt_packages=[]): def install(self, packages=[], apt_packages=[]):
pkg = EEAptGet()
if self.app.pargs.web: if self.app.pargs.web:
self.app.log.debug("Setting apt_packages variable for Nginx ,PHP" self.app.log.debug("Setting apt_packages variable for Nginx ,PHP"
" ,MySQL ") " ,MySQL ")
@ -798,9 +797,9 @@ class EEStackController(CementBaseController):
self.pre_pref(apt_packages) self.pre_pref(apt_packages)
if len(apt_packages): if len(apt_packages):
self.app.log.debug("Updating apt-cache") self.app.log.debug("Updating apt-cache")
pkg.update() EEAptGet.update()
self.app.log.debug("Installing all apt_packages") self.app.log.debug("Installing all apt_packages")
pkg.install(apt_packages) EEAptGet.install(apt_packages)
if len(packages): if len(packages):
self.app.log.debug("Downloading all packages") self.app.log.debug("Downloading all packages")
EEDownload.download(self, packages) EEDownload.download(self, packages)
@ -809,7 +808,6 @@ class EEStackController(CementBaseController):
@expose() @expose()
def remove(self): def remove(self):
pkg = EEAptGet()
apt_packages = [] apt_packages = []
packages = [] packages = []
@ -857,13 +855,12 @@ class EEStackController(CementBaseController):
if len(apt_packages): if len(apt_packages):
self.app.log.debug("Removing apt_packages") self.app.log.debug("Removing apt_packages")
pkg.remove(self, apt_packages) EEAptGet.remove(apt_packages)
if len(packages): if len(packages):
EEFileUtils.remove(self, packages) EEFileUtils.remove(self, packages)
@expose() @expose()
def purge(self): def purge(self):
pkg = EEAptGet()
apt_packages = [] apt_packages = []
packages = [] packages = []
@ -910,7 +907,7 @@ class EEStackController(CementBaseController):
] ]
if len(apt_packages): if len(apt_packages):
pkg.remove(apt_packages, purge=True) EEAptGet.remove(apt_packages, purge=True)
if len(packages): if len(packages):
EEFileUtils.remove(self, packages) EEFileUtils.remove(self, packages)

155
ee/core/aptget.py

@ -3,35 +3,36 @@ import apt
import sys import sys
class EEAptGet: class EEAptGet():
"""Generic apt-get intialisation""" """Generic apt-get intialisation"""
def __init__(self): def update():
self.cache = apt.Cache()
self.fprogress = apt.progress.text.AcquireProgress()
self.iprogress = apt.progress.base.InstallProgress()
def update(self):
"""Similar to apt-get update""" """Similar to apt-get update"""
# self.app.log.debug("Update cache") # app.log.debug("Update cache")
self.cache.update(self.fprogress) cache = apt.Cache()
self.cache.open() fprogress = apt.progress.text.AcquireProgress()
iprogress = apt.progress.base.InstallProgress()
cache.update(fprogress)
cache.close()
def upgrade(self, packages): def upgrade(packages):
"""Similar to apt-get update""" """Similar to apt-get update"""
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
iprogress = apt.progress.base.InstallProgress()
my_selected_packages = [] my_selected_packages = []
# Cache Initialization # Cache Initialization
if not self.cache: if not cache:
self.cache = apt.Cache() cache = apt.Cache()
# Cache Read # Cache Read
self.cache.open() cache.open()
for package in packages: for package in packages:
pkg = self.cache[package] pkg = cache[package]
# Check Package Installed # Check Package Installed
if pkg.is_installed: if pkg.is_installed:
# Check Package is Upgradeble # Check Package is Upgradeble
if pkg.is_upgradable: if pkg.is_upgradable:
with self.cache.actiongroup(): with cache.actiongroup():
# Mark Package for Upgrade # Mark Package for Upgrade
pkg.mark_upgrade() pkg.mark_upgrade()
my_selected_packages.append(pkg.installed) my_selected_packages.append(pkg.installed)
@ -49,31 +50,34 @@ class EEAptGet:
print("{pkg_install_count} newly installed." print("{pkg_install_count} newly installed."
.format(pkg_upgrade_count=len(my_selected_packages))) .format(pkg_upgrade_count=len(my_selected_packages)))
print("Need to get {req_download} bytes of archives" print("Need to get {req_download} bytes of archives"
.format(req_download=self.cache.required_download)) .format(req_download=cache.required_download))
print("After this operation, {space} bytes of" print("After this operation, {space} bytes of"
"additional disk space will be used." "additional disk space will be used."
.format(space=self.cache.required_space)) .format(space=cache.required_space))
try: try:
# Commit changes in cache (actually install) # Commit changes in cache (actually install)
self.cache.commit(self.fprogress, self.iprogress) cache.commit(fprogress, iprogress)
except Exception as e: except Exception as e:
print("package installation failed. [{err}]" print("package installation failed. [{err}]"
.format(err=str(e))) .format(err=str(e)))
return(False) return(False)
return(True) return(True)
def install(self, packages): def install(packages):
"""Installation of packages""" """Installation of packages"""
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
iprogress = apt.progress.base.InstallProgress()
my_selected_packages = [] my_selected_packages = []
# Cache Initialization # Cache Initialization
if not self.cache: if not cache:
self.cache = apt.Cache() cache = apt.Cache()
# Cache Read # Cache Read
self.cache.open() cache.open()
for package in packages: for package in packages:
try: try:
pkg = self.cache[package] pkg = cache[package]
except KeyError as e: except KeyError as e:
continue continue
# Check Package Installed # Check Package Installed
@ -90,63 +94,68 @@ class EEAptGet:
.format(package_name=pkg.shortname, .format(package_name=pkg.shortname,
package_ver=pkg.installed)) package_ver=pkg.installed))
else: else:
with self.cache.actiongroup(): with cache.actiongroup():
# Mark Package for Installation # Mark Package for Installation
pkg.mark_install() pkg.mark_install()
my_selected_packages.append(pkg.name) my_selected_packages.append(pkg.name)
# Check if packages available for install. # Check if packages available for install.
if self.cache.install_count > 0: if cache.install_count > 0:
print("The following NEW packages will be installed:" print("The following NEW packages will be installed:"
"\n {pkg_name}" "\n {pkg_name}"
.format(pkg_name=my_selected_packages)) .format(pkg_name=my_selected_packages))
print("{pkg_install_count} newly installed." print("{pkg_install_count} newly installed."
.format(pkg_install_count=self.cache.install_count)) .format(pkg_install_count=cache.install_count))
print("Need to get {req_download} bytes of archives" print("Need to get {req_download} bytes of archives"
.format(req_download=self.cache.required_download)) .format(req_download=cache.required_download))
print("After this operation, {space} bytes of" print("After this operation, {space} bytes of"
"additional disk space will be used." "additional disk space will be used."
.format(space=self.cache.required_space)) .format(space=cache.required_space))
try: try:
# Commit changes in cache (actually install) # Commit changes in cache (actually install)
self.cache.commit(self.fprogress, self.iprogress) cache.commit(fprogress, iprogress)
except Exception as e: except Exception as e:
print("package installation failed. [{err}]" print("package installation failed. [{err}]"
.format(err=str(e))) .format(err=str(e)))
return(False) return(False)
cache.close()
cache.close()
return(True) return(True)
def __dependencies_loop(self, deplist, pkg, onelevel=False): def remove(packages, auto=True, purge=False):
""" Loops through pkg's dependencies. def __dependencies_loop(cache, deplist, pkg, onelevel=True):
Returns a list with every package found. """ """ Loops through pkg's dependencies.
if not self.cache: Returns a list with every package found. """
self.cache = apt.Cache() print("Inside")
if onelevel: if onelevel:
onelevellist = [] onelevellist = []
if not pkg.is_installed: if not pkg.is_installed:
return return
for depf in pkg.installed.dependencies: for depf in pkg.installed.dependencies:
for dep in depf: for dep in depf:
if (dep.name in self.cache and not self.cache[dep.name] if (dep.name in cache and not cache[dep.name]
in deplist): in deplist):
deplist.append(self.cache[dep.name]) deplist.append(cache[dep.name])
self.__dependencies_loop(deplist, self.cache[dep.name]) __dependencies_loop(cache, deplist, cache[dep.name])
if onelevel: if onelevel:
if dep.name in self.cache: if dep.name in cache:
onelevellist.append(self.cache[dep.name]) onelevellist.append(cache[dep.name])
if onelevel: if onelevel:
return onelevellist return onelevellist
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
iprogress = apt.progress.base.InstallProgress()
def remove(self, packages, auto=True, purge=False):
my_selected_packages = [] my_selected_packages = []
# Cache Initialization # Cache Initialization
if not self.cache: if not cache:
self.cache = apt.Cache() cache = apt.Cache()
# Cache Read # Cache Read
self.cache.open() cache.open()
for package in packages: for package in packages:
print("processing", package) print("processing", package)
package = self.cache[package] package = cache[package]
if not package.is_installed: if not package.is_installed:
print("Package '{package_name}' is not installed," print("Package '{package_name}' is not installed,"
" so not removed." " so not removed."
@ -162,8 +171,8 @@ class EEAptGet:
# 2) We sequentially remove every package in list # 2) We sequentially remove every package in list
# - via is_auto_installed we check if we can safely remove it # - via is_auto_installed we check if we can safely remove it
deplist = [] deplist = []
onelevel = self.__dependencies_loop(deplist, package, onelevel = __dependencies_loop(cache, deplist, package,
onelevel=True) onelevel=True)
# Mark for deletion the first package, to fire up auto_removable # Mark for deletion the first package, to fire up auto_removable
# Purge? # Purge?
if purge: if purge:
@ -201,34 +210,42 @@ class EEAptGet:
pkg.mark_auto(auto=False) pkg.mark_auto(auto=False)
# Check if packages available for remove/update. # Check if packages available for remove/update.
if self.cache.delete_count > 0: if cache.delete_count > 0:
# self.app.log.debug('packages will be REMOVED ') # app.log.debug('packages will be REMOVED ')
print("The following packages will be REMOVED:" print("The following packages will be REMOVED:"
"\n {pkg_name}" "\n {pkg_name}"
.format(pkg_name=my_selected_packages)) .format(pkg_name=my_selected_packages))
print("{pkg_remove_count} to remove." print("{pkg_remove_count} to remove."
.format(pkg_remove_count=self.cache.delete_count)) .format(pkg_remove_count=cache.delete_count))
# self.app.log.debug('bytes disk space will be freed') # app.log.debug('bytes disk space will be freed')
print("After this operation, {space} bytes disk spac" print("After this operation, {space} bytes disk spac"
"e will be freed.".format(space=self.cache.required_space)) "e will be freed.".format(space=cache.required_space))
try: try:
self.cache.commit(self.fprogress, self.iprogress) cache.commit(fprogress, iprogress)
except Exception as e: except Exception as e:
# self.app.log.error('Sorry, package installation failed ') # app.log.error('Sorry, package installation failed ')
print("Sorry, package installation failed [{err}]" print("Sorry, package installation failed [{err}]"
.format(err=str(e))) .format(err=str(e)))
cache.close()
return(False) return(False)
cache.close()
return(True) return(True)
def is_installed(self, package): def is_installed(package):
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
iprogress = apt.progress.base.InstallProgress()
# Cache Initialization # Cache Initialization
if not self.cache: if not cache:
self.cache = apt.Cache() cache = apt.Cache()
# Cache Read # Cache Read
self.cache.open() cache.open()
pkg = self.cache[package] pkg = cache[package]
# Check Package Installed # Check Package Installed
if pkg.is_installed: if pkg.is_installed:
cache.close()
return True return True
else: else:
cache.close()
return False return False

4
ee/core/fileutils.py

@ -15,15 +15,13 @@ class EEFileUtils():
def remove(self, filelist): def remove(self, filelist):
for file in filelist: for file in filelist:
if os.path.isfile(file): if os.path.isfile(file):
self.app.log.debug('Removing file')
self.app.log.info("Removing "+os.path.basename(file)+" ...") self.app.log.info("Removing "+os.path.basename(file)+" ...")
os.remove(file) os.remove(file)
self.app.log.debug('file Removed') self.app.log.debug('file Removed')
self.app.log.info("Done") self.app.log.info("Done")
if os.path.isdir(file): if os.path.isdir(file):
try: try:
self.app.log.debug('Removing file') print("Removing "+os.path.basename(file)+"...")
print("Removing "+os.path.basename(file)+" ...")
shutil.rmtree(file) shutil.rmtree(file)
self.app.log.info("Done") self.app.log.info("Done")
except shutil.Error as e: except shutil.Error as e:

Loading…
Cancel
Save