Browse Source

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

bugfixes
gau1991 10 years ago
parent
commit
f98556dfaa
  1. 4
      ee/cli/main.py
  2. 2
      ee/cli/plugins/stack.py
  3. 8
      ee/cli/plugins/stack_services.py
  4. 100
      ee/core/aptget.py
  5. 16
      ee/core/services.py

4
ee/cli/main.py

@ -24,8 +24,8 @@ class EEApp(foundation.CementApp):
label = 'ee' label = 'ee'
# Log writing to file # Log writing to file
# defaults = init_defaults('ee', 'log.logging') defaults = init_defaults('ee', 'log.logging')
# defaults['log.logging']['file'] = '/tmp/my.log' defaults['log.logging']['file'] = '/tmp/my.log'
config_defaults = defaults config_defaults = defaults

2
ee/cli/plugins/stack.py

@ -414,7 +414,7 @@ class EEStackController(CementBaseController):
] ]
if len(apt_packages): if len(apt_packages):
pkg.purge(apt_packages) pkg.remove(apt_packages, purge=True)
if len(packages): if len(packages):
EEFileUtils.remove(packages) EEFileUtils.remove(packages)

8
ee/cli/plugins/stack_services.py

@ -34,7 +34,7 @@ class EEStackStatusController(CementBaseController):
else: else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
EEService.start_service(service) EEService.start_service(self, service)
@expose(help="stop stack services") @expose(help="stop stack services")
def stop(self): def stop(self):
@ -54,7 +54,7 @@ class EEStackStatusController(CementBaseController):
else: else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
EEService.stop_service(service) EEService.stop_service(self, service)
@expose(help="restart stack services") @expose(help="restart stack services")
def restart(self): def restart(self):
@ -74,7 +74,7 @@ class EEStackStatusController(CementBaseController):
else: else:
services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix'] services = services + ['nginx', 'php5-fpm', 'mysql', 'postfix']
for service in services: for service in services:
EEService.restart_service(service) EEService.restart_service(self, service)
@expose(help="get stack status") @expose(help="get stack status")
def status(self): def status(self):
@ -94,5 +94,5 @@ class EEStackStatusController(CementBaseController):
else: else:
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(service): if EEService.get_service_status(self, service):
print("{0}: Running".format(service)) print("{0}: Running".format(service))

100
ee/core/aptget.py

@ -1,6 +1,5 @@
"""EasyEngine package installation using apt-get module.""" """EasyEngine package installation using apt-get module."""
import apt import apt
import apt_pkg
import sys import sys
@ -110,29 +109,84 @@ class EEAptGet:
return(False) return(False)
return(True) return(True)
def remove(self, packages, purge_value=False): def __dependencies_loop(self, deplist, pkg, onelevel=False):
"""Removal of packages Similar to apt-get remove""" """ Loops through pkg's dependencies.
self.__init__() Returns a list with every package found. """
if not self.cache:
self.cache = apt.Cache()
if onelevel:
onelevellist = []
if not pkg.is_installed:
return
for depf in pkg.installed.dependencies:
for dep in depf:
if (dep.name in self.cache and not self.cache[dep.name]
in deplist):
deplist.append(self.cache[dep.name])
self.__dependencies_loop(deplist, self.cache[dep.name])
if onelevel:
if dep.name in self.cache:
onelevellist.append(self.cache[dep.name])
if onelevel:
return onelevellist
def remove(self, packages, auto=True, purge=False):
my_selected_packages = [] my_selected_packages = []
# apt cache Initialization
self.cache = apt.Cache()
# Read cache i.e package list
self.cache.open()
for package in packages: for package in packages:
pkg = self.cache[package] print("processing", package)
# Check if packages installed package = self.cache[package]
if pkg.is_installed and not pkg.marked_delete: if not package.is_installed:
with self.cache.actiongroup(): print("Package '{package_name}' is not installed,"
# Mark packages for delete " so not removed."
# Mark to purge package if purge_value is True .format(package_name=package.name))
pkg.mark_delete(purge=purge_value) continue
my_selected_packages.append(pkg.name) if package.marked_delete:
continue
else:
my_selected_packages.append(package.name)
# 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 = self.__dependencies_loop(deplist, package,
onelevel=True)
# Mark for deletion the first package, to fire up auto_removable
# Purge?
if purge:
package.mark_delete(purge=True)
else: else:
# Check If package not already marked for delete package.mark_delete(purge=False)
if not pkg.marked_delete: # Also ensure we remove AT LEAST the first level of dependencies
print("Package '{package_name}' is not installed," # (that is, the actual package's dependencies).
" so not removed." if auto:
.format(package_name=package)) 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)
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)
# Check if packages available for remove/update. # Check if packages available for remove/update.
if self.cache.delete_count > 0: if self.cache.delete_count > 0:
@ -150,7 +204,3 @@ class EEAptGet:
.format(err=str(e))) .format(err=str(e)))
return(False) return(False)
return(True) return(True)
def purge(self, packages):
"""Purging of packages similar to apt-get purge"""
return(self.remove(packages, purge_value=True))

16
ee/core/services.py

@ -11,19 +11,19 @@ class EEService():
# TODO method for services # TODO method for services
pass pass
def start_service(service_name): def start_service(self, service_name):
try: try:
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:
print("Started : {0}".format(service_name)) print("Started : {0}".format(service_name))
else: else:
print(retcode[1]) self.app.log.error(retcode[1])
except OSError as e: except OSError as e:
print("Execution failed:", e) self.app.log.error("Execution failed:", e)
return False return False
def stop_service(service_name): def stop_service(self, service_name):
try: try:
retcode = subprocess.getstatusoutput('service {0} stop' retcode = subprocess.getstatusoutput('service {0} stop'
.format(service_name)) .format(service_name))
@ -33,17 +33,17 @@ class EEService():
else: else:
return False return False
except OSError as e: except OSError as e:
print("Execution failed:", e) self.app.log.error("Execution failed:", e)
return False return False
def restart_service(service_name): def restart_service(self, service_name):
try: try:
EEService.stop_service(service_name) EEService.stop_service(service_name)
EEService.start_service(service_name) EEService.start_service(service_name)
except OSError as e: except OSError as e:
print("Execution failed:", e) self.app.log.error("Execution failed:", e)
def get_service_status(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))[0]

Loading…
Cancel
Save