def _test(): """Test function""" import sys import apt from apt.debfile import DebPackage win = gtk.Window() apt_progress = GtkAptProgress() win.set_title("GtkAptProgress Demo") win.add(apt_progress) apt_progress.show() win.show() cache = apt.cache.Cache(apt_progress.open) pkg = cache["xterm"] if pkg.is_installed: pkg.mark_delete() else: pkg.mark_install() apt_progress.show_terminal(True) try: cache.commit(apt_progress.acquire, apt_progress.install) except Exception as exc: print >> sys.stderr, "Exception happened:", exc if len(sys.argv) > 1: deb = DebPackage(sys.argv[1], cache) deb.install(apt_progress.dpkg_install) win.connect("destroy", gtk.main_quit) gtk.main()
class DebFile(): # the deb file which user selected debfile = '' path = '' name = '' version = '' installedsize = -1 description = '' def __init__(self, path): self.debfile = DebPackage(path) self.get_deb_info() self.path = path # check if the deb file is installable def is_installable(self): return self.debfile.check() # get missing dependencies def get_missing_deps(self): return self.debfile.missing_deps # get deb file name, version, installedsize, description def get_deb_info(self): self.name = self.debfile._sections["Package"] self.version = self.debfile._sections["Version"] self.installedsize = int(self.debfile._sections["Installed-Size"]) self.description = self.debfile._sections["Description"] # install the deb file def install_deb(self): self.debfile.install(AptProcess(self.debfile.pkgname))
def install_debfile(self, path, kwargs=None): debfile = DebPackage(path) pkgName = debfile._sections["Package"] try: debfile.install(AptProcess(self.dbus_service,pkgName,AppActions.INSTALLDEBFILE)) except Exception, e: print e print "install debfile err"
def deb_install(): try: deb = resource_get('deb') d = DebPackage(deb) d.install() set_state('elasticsearch.installed') except CalledProcessError: status_set('error', 'Elasticsearch could not be installed with package')
class DebFile(): # the deb file which user selected debfile = '' path = '' name = '' version = '' installedsize = -1 description = '' def __init__(self, path): self.debfile = DebPackage(path) self.get_deb_info() self.path = path # check if the deb file is installable @property def is_installable(self): return self.debfile.check() # get missing dependencies def get_missing_deps(self): self.debfile.check() #do check for get missing_deps return self.debfile.missing_deps # get deb file name, version, installedsize, description def get_deb_info(self): try: self.name = self.debfile._sections["Package"] except: self.name = "" try: self.version = self.debfile._sections["Version"] except: self.version = "" try: self.installedsize = int( float(self.debfile._sections["Installed-Size"])) except: try: self.installedsize = int(float(self.debfile._sections["Size"])) except: self.installedsize = 0 try: self.description = self.debfile._sections["Description"] except: self.description = "" # install the deb file def install_deb(self): self.debfile.install(AptProcess(self.debfile.pkgname))
def install_debfile(self, path, kwargs=None): if not os.path.isfile(path): raise WorkitemError(4, "%s is unreadable file" % path) try: debfile = DebPackage(path) except IOError: raise WorkitemError(4, "%s is unreadable file" % path) except Exception as e: raise WorkitemError(5, e) self.cache.open() pkgName = debfile._sections["Package"] debfile.check( ) #do debfile.check for the next to do debfile.missing_deps if 0 == len(debfile.missing_deps): # try: res = debfile.install() if res: raise WorkitemError(6, "package manager failed") else: kwarg = { "apt_appname": pkgName, "apt_percent": str(200), "action": str(AppActions.INSTALLDEBFILE), } self.dbus_service.software_apt_signal("apt_finish", kwarg) if pkgName == "ubuntu-kylin-software-center" and AppActions.INSTALLDEBFILE == "upgrade": pass else: self.dbus_service.set_uksc_not_working() else: raise WorkitemError(6, "dependence not be satisfied")
def installdeb(self, pkg): """ Install the Debian package. :param pkg: The path to the package to install :type pkg: str """ # Get the DebPackage object and the filename dpkg = DebPackage(filename=pkg, cache=self.cache) pkg_name = basename(pkg) # Look for package conflicts if not dpkg.check_conflicts(): self.feedback.block(dpkg.conflicts, 'CONFLICT') self.feedback.error( 'Cannot install package <{0}>, conflicts with:'.format( pkg_name)) return False # Get any version in cache cache_version = dpkg.compare_to_version_in_cache() action = 'Installed' # Not installed if cache_version == dpkg.VERSION_NONE: self.feedback.info('Package <{0}> not installed'.format(pkg_name)) # Upgrading if cache_version == dpkg.VERSION_OUTDATED: return self.feedback.info( 'Package <{0}> has newer version installed'.format(pkg_name)) # Same version if cache_version == dpkg.VERSION_SAME: return self.feedback.info( 'Package <{0}> already installed'.format(pkg_name)) # Installed is newer if cache_version == dpkg.VERSION_NEWER: self.feedback.info( 'Package <{0}> outdated, upgrading'.format(pkg_name)) action = 'Updated' # Install the package dpkg.install() self.feedback.success('{0}: {1}'.format(action, pkg_name))
def installdeb(self, pkg): """ Install the Debian package. :param pkg: The path to the package to install :type pkg: str """ # Get the DebPackage object and the filename dpkg = DebPackage(filename=pkg, cache=self.cache) pkg_name = basename(pkg) # Look for package conflicts if not dpkg.check_conflicts(): self.feedback.block(dpkg.conflicts, 'CONFLICT') self.feedback.error('Cannot install package <{0}>, conflicts with:'.format(pkg_name)) return False # Get any version in cache cache_version = dpkg.compare_to_version_in_cache() action = 'Installed' # Not installed if cache_version == dpkg.VERSION_NONE: self.feedback.info('Package <{0}> not installed'.format(pkg_name)) # Upgrading if cache_version == dpkg.VERSION_OUTDATED: self.feedback.info('Package <{0}> outdated, upgrading'.format(pkg_name)) action = 'Updated' # Same version if cache_version == dpkg.VERSION_SAME: return self.feedback.info('Package <{0}> already installed'.format(pkg_name)) # Installed is newer if cache_version == dpkg.VERSION_NEWER: return self.feedback.info('Package <{0}> has newer version installed'.format(pkg_name)) # Install the package dpkg.install() self.feedback.success('{0}: {1}'.format(action, pkg_name))
def install_debfile(self, path, sender=None): print("####install deb file: ", path) # path = "".join([chr(character) for character in path]) # add by zhangxin for chinese .deb path 11.19 granted = self.auth_with_policykit(sender, PACKAGES_MANAGER_TOOLS) if not granted: kwarg = { "appname": path, "action": AppActions.INSTALLDEBFILE, } self.software_auth_signal("auth_cancel", kwarg) return False else: kwarg = { "appname": path, "action": AppActions.INSTALLDEBFILE, } self.software_auth_signal("auth_ensure", kwarg) #print("send auth signal") if not os.path.isfile(path): raise WorkitemError(4, "%s is unreadable file" % path) try: debfile = DebPackage(path) except IOError: raise WorkitemError(4, "%s is unreadable file" % path) except Exception as e: raise WorkitemError(5, e) #self.cache.open() pkgName = debfile._sections["Package"] debfile.check( ) #do debfile.check for the next to do debfile.missing_deps if 0 == len(debfile.missing_deps): # try: res = debfile.install() if res: kwarg = { "apt_appname": pkgName, "apt_percent": str(-200), "action": str(AppActions.INSTALLDEBFILE), } self.software_apt_signal("apt_finish", kwarg) raise WorkitemError(6, "package manager failed") else: kwarg = { "apt_appname": pkgName, "apt_percent": str(200), "action": str(AppActions.INSTALLDEBFILE), } self.software_apt_signal("apt_finish", kwarg) else: raise WorkitemError(16, "dependence not be satisfied") return True
def install_debfile(self, path, sender=None): # print("####install deb file: ", path) # 开启密码认证机制 granted = self.auth_with_policykit(sender, PACKAGES_MANAGER_TOOLS) if not granted: kwarg = { "appname": path, "action": AppActions.INSTALLDEBFILE, } self.software_auth_signal("auth_cancel", kwarg) return False else: kwarg = { "appname": path, "action": AppActions.INSTALLDEBFILE, } self.software_auth_signal("auth_ensure", kwarg) #print("send auth signal") if not os.path.isfile(path): raise WorkitemError(4, "%s is unreadable file" % path) try: debfile = DebPackage(path) except IOError: raise WorkitemError(4, "%s is unreadable file" % path) except Exception as e: raise WorkitemError(5, e) #self.cache.open() #获取软件包名 pkgName = debfile._sections["Package"] debfile.check( ) #do debfile.check for the next to do debfile.missing_deps # print("len:%s" % len(debfile.missing_deps)) # 安装源中存在的依赖包 if len(debfile.missing_deps) != 0: for deb in debfile.missing_deps: pkg = self.get_pkg_by_name(deb) # print("lj.pkg:%s" %pkg) pkg.mark_install() try: self.cache.commit( FetchProcess(self, deb, AppActions.INSTALL_ONE), None) except apt.cache.LockFailedException: raise WorkitemError(3, "package manager is running.") #安装软件包 res = debfile.install() if res: kwarg = { "apt_appname": pkgName, "apt_percent": str(-200), "action": str(AppActions.INSTALLDEBFILE), } self.software_apt_signal("apt_finish", kwarg) raise WorkitemError(6, "package manager failed") else: kwarg = { "apt_appname": pkgName, "apt_percent": str(200), "action": str(AppActions.INSTALLDEBFILE), } self.software_apt_signal("apt_finish", kwarg) # else: # kwarg = {"apt_appname": pkgName, # "apt_percent": str(-200), # "action": str(AppActions.INSTALLDEBFILE), # } # self.software_apt_signal("apt_error", kwarg) # raise WorkitemError(16, "dependence not be satisfied") return True
def deb_install(): deb = resource_get('deb') d = DebPackage(deb) d.install() set_state('elasticsearch.installed')
from apt.debfile import DebPackage win = gtk.Window() apt_progress = GtkAptProgress() win.set_title("GtkAptProgress Demo") win.add(apt_progress) apt_progress.show() win.show() cache = apt.cache.Cache(apt_progress.open) pkg = cache["xterm"] if pkg.is_installed: pkg.mark_delete() else: pkg.mark_install() apt_progress.show_terminal(True) try: cache.commit(apt_progress.acquire, apt_progress.install) except Exception, exc: print >> sys.stderr, "Exception happened:", exc if len(sys.argv) > 1: deb = DebPackage(sys.argv[1], cache) deb.install(apt_progress.dpkg_install) win.connect("destroy", gtk.main_quit) gtk.main() if __name__ == "__main__": _test() # vim: ts=4 et sts=4