Example #1
0
 def apt_remove(self, package_names):
     '''package_names -- package names concatenated by comma (,)'''
     for pkg_name in package_names.split(','):
         if self.apt_cache.has_key(pkg_name):
             pkg = self.apt_cache[pkg_name]
         else:
             raise AptPackageNotExistError(pkg_name)
         pkg.mark_delete()
     self.unlock_apt_pkg_global_lock()
     self.apt_cache.commit(self.apt_progress.fetch,
                           self.apt_progress.install)
     apt_pkg.PkgSystemLock()
Example #2
0
 def apt_install_local(self, package_path):
     deb = apt.debfile.DebPackage(package_path, self.apt_cache)
     if not deb.check(): raise LocalDebPackageResolutionError
     self.unlock_apt_pkg_global_lock()
     (install, remove, unauth) = deb.required_changes
     for name in install:
         self.apt_cache[name].mark_install()
     for name in remove:
         self.apt_cache[name].mark_delete()
     self.apt_cache.commit(self.apt_progress.fetch,
                           self.apt_progress.install)
     deb.install(self.apt_progress.dpkg_install)
     apt_pkg.PkgSystemLock()
Example #3
0
 def apt_lock_cache(self):
     try:
         # /var/lib/apt/lists/lock,
         # locked by apt-get update
         self.lock1_fd = self.lock_apt(
             apt_pkg.Config.FindDir("Dir::State::Lists"))
         # /var/cache/apt/archives/lock,
         # try the lock in /var/cache/apt/archive/lock first
         # this is because apt-get install will hold it all the time
         # while the dpkg lock is briefly given up before dpkg is
         # forked off. this can cause a race (LP: #437709)
         self.lock2_fd = self.lock_apt(
             apt_pkg.Config.FindDir("Dir::Cache::Archives"))
         apt_pkg.PkgSystemLock()
     except SystemError, e:
         print "ERROR [SystemError]: Can NOT lock apt cache (apt_pkg.PkgSystemLock - %s)" % e
         return False
Example #4
0
 def apt_lock_cache(self):
     # /var/lib/apt/lists/lock,
     # locked by apt-get update
     self.lock1_fd = self.lock_apt(
         apt_pkg.Config.FindDir("Dir::State::Lists"))
     # /var/cache/apt/archives/lock,
     # try the lock in /var/cache/apt/archive/lock first
     # this is because apt-get install will hold it all the time
     # while the dpkg lock is briefly given up before dpkg is
     # forked off. this can cause a race (LP: #437709)
     self.lock2_fd = self.lock_apt(
         apt_pkg.Config.FindDir("Dir::Cache::Archives"))
     try:
         apt_pkg.PkgSystemLock()
     except SystemError:
         raise CannotLockAptCacheError('apt_pkg.PkgSystemLock')
     self.holding_apt_lock = True
Example #5
0
                print "ERROR: Package %s does NOT exist" % pkg_name
                return False
            pkg.mark_install()
        try:
            self.unlock_apt_pkg_global_lock()
            self.apt_cache.commit(self.apt_progress.fetch,
                                  self.apt_progress.install)
        #except apt.cache.FetchFailedException, e:
        #    print "ERROR [apt.cache.FetchFailedException]: Can NOT download package (%s)" % e
        #    return False
        except Exception, e:
            print "ERROR: Can NOT install package(s) %s (%s)" % (package_names,
                                                                 e)
            return False
        finally:
            apt_pkg.PkgSystemLock()
        return True

    def apt_install_local(self, package_path):
        try:
            deb = apt.debfile.DebPackage(package_path, self.apt_cache)
        except SystemError, e:
            print "ERROR [SystemError]: %s" % e
            return 1
        if not deb.check():
            print "ERROR: Local debian package resolution error"
            return False
        self.unlock_apt_pkg_global_lock()
        (install, remove, unauth) = deb.required_changes
        for name in install:
            self.apt_cache[name].mark_install()