Browse Source

ee stack purge --mail pkgResolveProblem solved

bugfixes
harshadyeola 10 years ago
parent
commit
c3c8eccf1e
  1. 17
      ee/cli/plugins/stack.py
  2. 122
      ee/core/aptget.py
  3. 1
      ee/core/logging.py

17
ee/cli/plugins/stack.py

@ -919,7 +919,7 @@ class EEStackController(CementBaseController):
self.app.pargs.mysql = True
self.app.pargs.postfix = True
if not EEAptGet.is_installed('dovecot-core'):
if not EEAptGet.is_installed(self, 'dovecot-core'):
Log.debug(self, "Setting apt_packages variable for mail")
apt_packages = apt_packages + EEVariables.ee_mail
packages = packages + [["https://github.com/opensolutions/"
@ -938,13 +938,13 @@ class EEStackController(CementBaseController):
if self.app.pargs.nginx:
Log.debug(self, "Setting apt_packages variable for Nginx")
if not EEAptGet.is_installed('nginx-common'):
if not EEAptGet.is_installed(self, 'nginx-common'):
apt_packages = apt_packages + EEVariables.ee_nginx
else:
Log.info(self, "Nginx allready installed")
if self.app.pargs.php:
Log.debug(self, "Setting apt_packages variable for PHP")
if not EEAptGet.is_installed('php5-common'):
if not EEAptGet.is_installed(self, 'php5-fpm'):
apt_packages = apt_packages + EEVariables.ee_php
else:
Log.info(self, "PHP allready installed")
@ -956,7 +956,7 @@ class EEStackController(CementBaseController):
Log.info(self, "MySQL connection is allready alive")
if self.app.pargs.postfix:
Log.debug(self, "Setting apt_packages variable for PostFix")
if not EEAptGet.is_installed('postfix'):
if not EEAptGet.is_installed(self, 'postfix'):
apt_packages = apt_packages + EEVariables.ee_postfix
else:
Log.info(self, "Postfix is allready installed")
@ -1022,9 +1022,10 @@ class EEStackController(CementBaseController):
if len(apt_packages):
EESwap.add(self)
Log.debug(self, "Updating apt-cache")
EEAptGet.update()
EEAptGet.update(self)
Log.debug(self, "Installing all apt_packages")
EEAptGet.install(apt_packages)
print(apt_packages)
EEAptGet.install(self, apt_packages)
if len(packages):
Log.debug(self, "Downloading all packages")
EEDownload.download(self, packages)
@ -1095,7 +1096,7 @@ class EEStackController(CementBaseController):
if len(apt_packages):
Log.debug(self, "Removing apt_packages")
EEAptGet.remove(apt_packages)
EEAptGet.remove(self, apt_packages)
if len(packages):
EEFileUtils.remove(self, packages)
Log.info(self, "Successfully removed packages")
@ -1160,7 +1161,7 @@ class EEStackController(CementBaseController):
]
if len(apt_packages):
EEAptGet.remove(apt_packages, purge=True)
EEAptGet.remove(self, apt_packages, purge=True)
if len(packages):
EEFileUtils.remove(self, packages)
Log.info(self, "Successfully purged packages")

122
ee/core/aptget.py

@ -1,13 +1,16 @@
"""EasyEngine package installation using apt-get module."""
import apt
import apt_pkg
import sys
from ee.core.logging import Log
class EEAptGet():
"""Generic apt-get intialisation"""
def update():
def update(self):
"""Similar to apt-get update"""
# app.log.debug("Update cache")
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
@ -15,7 +18,7 @@ class EEAptGet():
cache.update(fprogress)
cache.close()
def upgrade(packages):
def upgrade(self, packages):
"""Similar to apt-get update"""
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
@ -63,7 +66,7 @@ class EEAptGet():
return(False)
return(True)
def install(packages):
def install(self, packages):
"""Installation of packages"""
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
@ -97,6 +100,7 @@ class EEAptGet():
with cache.actiongroup():
# Mark Package for Installation
pkg.mark_install()
pkg.mark_auto(auto=False)
my_selected_packages.append(pkg.name)
# Check if packages available for install.
@ -110,7 +114,7 @@ class EEAptGet():
.format(req_download=cache.required_download))
print("After this operation, {space} bytes of"
"additional disk space will be used."
.format(space=cache.required_space))
.format(space=cache.required_space/1e6))
try:
# Commit changes in cache (actually install)
cache.commit(fprogress, iprogress)
@ -122,7 +126,7 @@ class EEAptGet():
cache.close()
return(True)
def remove(packages, auto=True, purge=False):
def remove(self, packages, auto=False, purge=False):
def __dependencies_loop(cache, deplist, pkg, onelevel=True):
""" Loops through pkg's dependencies.
Returns a list with every package found. """
@ -132,15 +136,18 @@ class EEAptGet():
return
for depf in pkg.installed.dependencies:
for dep in depf:
if (dep.name in cache and not cache[dep.name]
in deplist):
deplist.append(cache[dep.name])
__dependencies_loop(cache, deplist, cache[dep.name])
if onelevel:
if dep.name in cache:
# if (dep.name in cache and not cache[dep.name]
# in deplist):
# deplist.append(cache[dep.name])
# __dependencies_loop(cache, deplist, cache[dep.name])
# if onelevel:
if dep.name in cache:
if (cache[dep.name].is_installed and
not cache[dep.name].is_auto_installed and
not cache[dep.name].marked_delete):
onelevellist.append(cache[dep.name])
if onelevel:
return onelevellist
# if onelevel:
return onelevellist
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
@ -154,68 +161,37 @@ class EEAptGet():
cache.open()
for package in packages:
print("processing", package)
package = cache[package]
if not package.is_installed:
print("Package '{package_name}' is not installed,"
" so not removed."
.format(package_name=package.name))
try:
pkg = cache[package]
except KeyError as e:
Log.debug(self, "{0}".format(e))
continue
if package.marked_delete:
my_selected_packages.append(package.name)
# Mark for deletion the first package, to fire up
# auto_removable Purge?
if purge:
package.mark_delete(purge=True)
else:
package.mark_delete(purge=False)
if not pkg.is_installed:
Log.info(self, "Package '{package_name}' is not installed,"
" so not removed."
.format(package_name=pkg.name))
continue
else:
my_selected_packages.append(package.name)
print(my_selected_packages)
# How logic works:
# 1) We loop trough dependencies's dependencies and add them to
# the list.
# 2) We sequentially remove every package in list
# - via is_auto_installed we check if we can safely remove it
deplist = []
onelevel = __dependencies_loop(cache, deplist, package,
onelevel=True)
# Mark for deletion the first package, to fire up
# auto_removable Purge?
my_selected_packages.append(pkg.name)
print(my_selected_packages)
# How logic works:
# 1) We loop trough dependencies's dependencies and add them to
# the list.
# 2) We sequentially remove every package in list
# - via is_auto_installed we check if we can safely remove it
deplist = []
onelevel = __dependencies_loop(cache, deplist, pkg,
onelevel=True)
# Mark for deletion the first package, to fire up
# auto_removable Purge?
packages = packages + onelevel
try:
if purge:
package.mark_delete(purge=True)
else:
package.mark_delete(purge=False)
# Also ensure we remove AT LEAST the first level of
# dependencies (that is, the actual package's dependencies).
if auto:
markedauto = []
for pkg in onelevel:
if (not pkg.marked_install and pkg.is_installed
and not pkg.is_auto_installed):
pkg.mark_auto()
markedauto.append(pkg)
for pkg in deplist:
if (not pkg.marked_install and pkg.is_installed and
pkg.is_auto_removable):
# Purge?
if purge:
pkg.mark_delete(purge=True)
else:
pkg.mark_delete(purge=False)
# Restore auted items
for pkg in markedauto:
if not pkg.marked_delete:
pkg.mark_auto(False)
pkg.mark_delete(purge=True)
else:
# We need to ensure that the onelevel packages are not
# marked as automatically installed, otherwise the user may
# drop them via autoremove or aptitude.
for pkg in onelevel:
if pkg.is_installed and pkg.is_auto_installed:
pkg.mark_auto(auto=False)
pkg.mark_delete(purge=False)
except SystemError as e:
Log.debug(self, "{0}".format(e))
Log.error(self, "Unable to purge packages.")
# Check if packages available for remove/update.
if cache.delete_count > 0:
@ -239,7 +215,7 @@ class EEAptGet():
cache.close()
return(True)
def is_installed(package):
def is_installed(self, package):
cache = apt.Cache()
fprogress = apt.progress.text.AcquireProgress()
iprogress = apt.progress.base.InstallProgress()
@ -258,6 +234,8 @@ class EEAptGet():
else:
cache.close()
return False
except KeyError as e:
Log.debug(self, "{0}".format(e))
except Exception as e:
cache.close()
return False

1
ee/core/logging.py

@ -12,6 +12,7 @@ class Log:
def error(self, msg):
self.app.log.error(Log.FAIL + msg + Log.ENDC)
self.app.close(1)
def info(self, msg):
self.app.log.info(Log.OKBLUE + msg + Log.ENDC)

Loading…
Cancel
Save