Browse Source

lib to apt-get

bugfixes
harshadyeola 10 years ago
parent
commit
3491337c69
  1. 107
      ee/core/aptget.py

107
ee/core/aptget.py

@ -4,47 +4,100 @@ import sys
class EEAptGet: class EEAptGet:
"""Generice apt-get intialisation""" """Generic apt-get intialisation"""
def __init__(self): def __init__(self):
self.cache = apt.cache.Cache() self.cache = apt.Cache()
self.fprogress = apt.progress.text.AcquireProgress()
self.iprogress = apt.progress.base.InstallProgress()
"""Installation of packages"""
def update(self): def update(self):
self.cache.update() """Similar to apt-get update"""
self.cache.update(self.fprogress)
pass pass
"""Installation of packages"""
def install(self, packages): def install(self, packages):
pkg = self.cache[packages] """Installation of packages"""
if pkg.is_installed: my_selected_packages = []
print("pkg already installed") # Cache Initialization
else: self.cache = apt.Cache()
pkg.mark_install() # Cache Read
try: self.cache.open()
self.cache.commit(apt.progress.TextFetchProgress(), for package in packages:
apt.progress.InstallProgress()) pkg = self.cache[package]
# Check Package Installed
if pkg.is_installed:
# Check Package is Upgradeble
if pkg.is_upgradable:
print("latest version of \'{package_name}\' available."
.format(package_name=pkg.installed))
else:
print("\'{package_name}-{package_ver.version}\'"
"already the newest version"
.format(package_name=pkg.name,
package_ver=pkg.installed))
else:
with self.cache.actiongroup():
# Mark Package for Installation
pkg.mark_install()
my_selected_packages.append(pkg.name)
# Check if packages available for install.
if self.cache.install_count > 0:
print("The following NEW packages will be installed:"
"\n {pkg_name}"
.format(pkg_name=my_selected_packages))
print("{pkg_install_count} newly installed."
.format(pkg_install_count=self.cache.install_count))
print("Need to get {req_download} bytes of archives"
.format(req_download=self.cache.required_download))
print("After this operation, {space} bytes of"
"additional disk space will be used."
.format(space=self.cache.required_space))
try:
# Commit changes in cache (actually install)
self.cache.commit(self.fprogress, self.iprogress)
except Exception as e: except Exception as e:
print("Sorry, package installation failed [{err}]" print("package installation failed[{err}]"
.format(err=str(e))) .format(err=str(e)))
"""Removal of packages""" def remove(self, packages, purge_value=False):
def remove(self, packages): """Removal of packages Similar to apt-get remove"""
pkg = self.cache[packages] self.__init__()
if pkg.is_installed: my_selected_packages = []
pkg.mark_delete() # apt cache Initialization
self.cache = apt.Cache()
# Read cache i.e package list
self.cache.open()
for package in packages:
pkg = self.cache[package]
# Check if packages installed
if pkg.is_installed:
with self.cache.actiongroup():
# Mark packages for delete
# Mark to purge package if purge_value is True
pkg.mark_delete(purge=purge_value)
my_selected_packages.append(pkg.name)
else:
print("Package '{package_name}' is not installed,"
" so not removed."
.format(package_name=packages))
# Check if packages available for remove/update.
if self.cache.delete_count > 0:
print("The following NEW packages will be REMOVED:"
"\n {pkg_name}"
.format(pkg_name=my_selected_packages))
print("{pkg_remove_count} to remove."
.format(pkg_remove_count=self.cache.delete_count))
print("After this operation, {space} bytes disk spac"
"e will be freed.".format(space=self.cache.required_space))
try: try:
self.cache.commit() self.cache.commit()
except Exception as e: except Exception as e:
print("Sorry, package installation failed [{err}]" print("Sorry, package installation failed [{err}]"
.format(err=str(e))) .format(err=str(e)))
else: def purge(self, packages):
print("pkg not installed") """Purging of packages similar to apt-get purge"""
self.remove(packages, purge_value=True)
"""Purging of packages"""
def purge():
# TODO Method to purge packages
pass

Loading…
Cancel
Save