[yum-commits] 6 commits - docs/yum.8 docs/yum.conf.5 yumcommands.py yum/config.py yum/Errors.py yum/__init__.py yummain.py yum/packages.py yum/sqlitesack.py yum/yumRepo.py

James Antill james at osuosl.org
Wed May 21 22:33:58 UTC 2014


 docs/yum.8        |    2 -
 docs/yum.conf.5   |    5 +++
 yum/Errors.py     |   11 ++++++-
 yum/__init__.py   |    7 ++---
 yum/config.py     |    2 +
 yum/packages.py   |    9 ++++--
 yum/sqlitesack.py |   12 +++++---
 yum/yumRepo.py    |   75 ++++++++++++++++++++++++++++--------------------------
 yumcommands.py    |    3 +-
 yummain.py        |   12 ++++++++
 10 files changed, 89 insertions(+), 49 deletions(-)

New commits:
commit 6e64b142014dc3c5489aed7966f0948948054fb7
Author: James Antill <james at and.org>
Date:   Wed May 21 18:29:28 2014 -0400

    Check for existance, so mock etc. is happy.

diff --git a/yummain.py b/yummain.py
index ee8d632..24bbe6c 100755
--- a/yummain.py
+++ b/yummain.py
@@ -214,7 +214,8 @@ def main(args):
     if base.conf.usr_w_check:
         usrinstpath = base.conf.installroot + "/usr"
         usrinstpath = usrinstpath.replace('//', '/')
-        if not os.access(usrinstpath, os.W_OK):
+        if (os.path.exists(usrinstpath) and
+            not os.access(usrinstpath, os.W_OK)):
             logger.critical(_('No write access to %s directory') % usrinstpath)
             logger.critical(_('  Maybe this is an ostree image?'))
             logger.critical(_('  To disable you can use --setopt=usr_w_check=false'))
commit 507182919894e9bf75b08a75cb22c49d852c8278
Author: James Antill <james at and.org>
Date:   Wed May 21 15:14:55 2014 -0400

    Check /usr for writability before running a transaction.

diff --git a/docs/yum.conf.5 b/docs/yum.conf.5
index 4ec7689..c39544d 100644
--- a/docs/yum.conf.5
+++ b/docs/yum.conf.5
@@ -892,6 +892,11 @@ shouldn't be needed as yum should always solve or fail, however it has been
 observed that it can loop forever with very large system upgrades. Setting
 this to `0' (or "<forever>") makes yum try forever. Default is `100'.
 
+.IP
+\fBusr_w_check\fR
+Either `0' or `1'. Set this to `0' to disable the checking for writability on
+/usr in the installroot (when going into the depsolving stage). Default is `1'
+(perform the check).
 
 .SH "[repository] OPTIONS"
 .LP 
diff --git a/yum/config.py b/yum/config.py
index 7bb56d0..f0f4e96 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -906,6 +906,8 @@ class YumConf(StartupConf):
 
     check_config_file_age = BoolOption(True)
 
+    usr_w_check = BoolOption(True)
+
     _reposlist = []
 
     def dump(self):
diff --git a/yummain.py b/yummain.py
index fa76af8..ee8d632 100755
--- a/yummain.py
+++ b/yummain.py
@@ -209,6 +209,17 @@ def main(args):
             logger.critical(msg)
         if unlock(): return 200
         return 3
+
+    # Mainly for ostree, but might be useful for others.
+    if base.conf.usr_w_check:
+        usrinstpath = base.conf.installroot + "/usr"
+        usrinstpath = usrinstpath.replace('//', '/')
+        if not os.access(usrinstpath, os.W_OK):
+            logger.critical(_('No write access to %s directory') % usrinstpath)
+            logger.critical(_('  Maybe this is an ostree image?'))
+            logger.critical(_('  To disable you can use --setopt=usr_w_check=false'))
+            if unlock(): return 200
+            return 1
             
     # Depsolve stage
     verbose_logger.log(logginglevels.INFO_2, _('Resolving Dependencies'))
commit 550a6baaed1dc77185dd2f90d3e73feaf5de2ef2
Author: James Antill <james at and.org>
Date:   Tue May 20 14:20:24 2014 -0400

    Add repo= arguments to almost all RepoError raises, so we don't print unknown.

diff --git a/yum/__init__.py b/yum/__init__.py
index ac01435..bf13f40 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -924,7 +924,8 @@ class YumBase(depsolve.Depsolve):
                 continue
                 
             if not repo.ready():
-                raise Errors.RepoError, "Repository '%s' not yet setup" % repo
+                raise Errors.RepoError("Repository '%s' not yet setup" % repo,
+                                       repo=repo)
             try:
                 groupremote = repo.getGroupLocation()
             except Errors.RepoMDError, e:
@@ -2652,8 +2653,8 @@ much more problems).
                 return
         else:
             if self.conf.cache:
-                raise Errors.RepoError, \
-                _('Header not in local cache and caching-only mode enabled. Cannot download %s') % po.hdrpath
+                raise Errors.RepoError(_('Header not in local cache and caching-only mode enabled. Cannot download %s') % po.hdrpath,
+                                       repo=repo)
         
         if self.dsCallback: self.dsCallback.downloadHeader(po.name)
         
diff --git a/yum/packages.py b/yum/packages.py
index 9522235..eebeb9d 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -921,7 +921,8 @@ class YumAvailablePackage(PackageObject, RpmBase):
         try:
             hdr = rpmUtils.miscutils.hdrFromPackage(ts, rpmfile)
         except rpmUtils.RpmUtilsError:
-            raise Errors.RepoError, 'Package Header %s: RPM Cannot open' % self
+            raise Errors.RepoError('Package Header %s: RPM Cannot open' % self,
+                                   repo=self.repo)
         return hdr
         
     def returnLocalHeader(self):
@@ -933,9 +934,11 @@ class YumAvailablePackage(PackageObject, RpmBase):
                 hlist = rpm.readHeaderListFromFile(self.localHdr())
                 hdr = hlist[0]
             except (rpm.error, IndexError):
-                raise Errors.RepoError, 'Package Header %s: Cannot open' % self
+                raise Errors.RepoError('Package Header %s: Cannot open' % self,
+                                       repo=self.repo)
         else:
-            raise Errors.RepoError, 'Package Header %s: Not Available' % self
+            raise Errors.RepoError('Package Header %s: Not Available' % self,
+                                   repo=self.repo)
 
         return hdr
 
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 16b647f..4d91774 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -52,6 +52,8 @@ def catchSqliteException(func):
                     raise Errors.RepoError, str(e.message)
                 else:
                     raise Errors.RepoError, str(e)
+            #  Note that we can't easily get "repo" here, AFAIK. So we can't
+            # tell what failed.
             raise Errors.RepoError, str(e)
 
     newFunc.__name__ = func.__name__
@@ -748,7 +750,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             data = self._sql_MD('primary', repo, sql, (pkgKey,)).fetchone()
             if data is None:
                 msg = "pkgKey %s doesn't exist in repo %s" % (pkgKey, repo)
-                raise Errors.RepoError, msg
+                raise Errors.RepoError(msg, repo=repo)
             if exclude and self._pkgExcludedRKD(repo, pkgKey, data):
                 return None
             po = self.pc(repo, data)
@@ -817,7 +819,8 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             self.excludes[repo] = {}
 
         if dataobj is None:
-            raise Errors.RepoError, "Tried to add None %s to %s" % (datatype, repo)
+            raise Errors.RepoError("Tried to add None %s to %s" % (datatype, repo),
+                                   repo=repo)
 
         if datatype == 'metadata':
             self.primarydb[repo] = dataobj
@@ -827,7 +830,8 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             self.otherdb[repo] = dataobj
         else:
             # We can not handle this yet...
-            raise Errors.RepoError, "Sorry sqlite does not support %s in %s" % (datatype, repo)
+            raise Errors.RepoError("Sorry sqlite does not support %s in %s" % (datatype, repo),
+                                   repo=repo)
     
         self.added[repo].append(datatype)
 
@@ -956,7 +960,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             pri_pkgs = self._sql_MD_pkg_num('primary',   repo)
             fil_pkgs = self._sql_MD_pkg_num('filelists', repo)
             if pri_pkgs != fil_pkgs:
-                raise Errors.RepoError
+                raise Errors.RepoError('Check of Primary and Filelists sync. failed.', repo=repo)
             repo._checked_filelists_pkgs = True
 
         sql_params = []
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 35359e2..4d64dff 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -145,8 +145,9 @@ class YumPackageSack(packageSack.PackageSack):
         elif datatype in ['filelists', 'otherdata']:
             if repo in self.added:
                 if 'metadata' not in self.added[repo]:
-                    raise Errors.RepoError, '%s md for %s imported before primary' \
-                           % (datatype, repo.ui_id)
+                    raise Errors.RepoError('%s md for %s imported before primary' \
+                           % (datatype, repo.ui_id),
+                                           repo=self)
             current = 0
             for pkgid in dataobj:
                 current += 1
@@ -238,7 +239,8 @@ class YumPackageSack(packageSack.PackageSack):
                         db_un_fn = self._check_uncompressed_db_gen(repo,
                                                                    mydbtype)
                     if not db_un_fn: # Shouldn't happen?
-                        raise Errors.RepoError, '%s: Check uncompressed DB failed' % repo
+                        raise Errors.RepoError('%s: Check uncompressed DB failed' % repo,
+                                               repo=self)
 
                 dobj = repo.cacheHandler.open_database(db_un_fn)
 
@@ -252,7 +254,8 @@ class YumPackageSack(packageSack.PackageSack):
                 gen = mymdtype + '.xml'
                 ret = misc.repo_gen_decompress(xml, gen, cached=repo.cache)
                 if not ret:
-                    raise Errors.RepoError, '%s: Decompress DB failed' % repo
+                    raise Errors.RepoError('%s: Decompress DB failed' % repo,
+                                           repo=self)
                 xml = ret
                 # Convert XML => .sqlite
                 xmldata = repo.repoXML.getData(mymdtype)
@@ -492,7 +495,8 @@ class YumRepository(Repository, config.RepoConf):
         except (Errors.MiscError, EnvironmentError), e:
             if checksum_can_fail:
                 return None
-            raise Errors.RepoError, 'Error opening file for checksum: %s' % e
+            raise Errors.RepoError('Error opening file for checksum: %s' % e,
+                                   repo=self)
 
     def dump(self):
         output = '[%s]\n' % self.id
@@ -550,8 +554,8 @@ class YumRepository(Repository, config.RepoConf):
         """self-check the repo information  - if we don't have enough to move
            on then raise a repo error"""
         if len(self._urls) < 1 and not self.mediaid:
-            raise Errors.RepoError, \
-             'Cannot find a valid baseurl for repo: %s' % self.ui_id
+            raise Errors.RepoError('Cannot find a valid baseurl for repo: %s' %
+                                   self.ui_id, repo=self)
 
     def doProxyDict(self):
         if self._proxy_dict:
@@ -703,7 +707,7 @@ class YumRepository(Repository, config.RepoConf):
         except OSError, e:
             msg = "%s: %s %s: %s" % ("Error making cache directory",
                                      dpath, "error was", e)
-            raise Errors.RepoError, msg
+            raise Errors.RepoError(msg, repo=self)
 
     def dirSetup(self):
         """make the necessary dirs, if possible, raise on failure"""
@@ -887,7 +891,7 @@ class YumRepository(Repository, config.RepoConf):
                     if not os.path.exists(self.metalink_filename):
                         msg = ("Cannot retrieve metalink for repository: %s. "
                                "Please verify its path and try again" % self.ui_id )
-                        raise Errors.RepoError, msg
+                        raise Errors.RepoError(msg, repo=self)
                     #  Now, we have an old usable metalink, so we can't move to
                     # a newer repomd.xml ... or checksums won't match.
                     print "Could not get metalink %s error was\n%s: %s" % (url, e.args[0], misc.to_unicode(e.args[1]))                    
@@ -944,18 +948,16 @@ class YumRepository(Repository, config.RepoConf):
             copy_local = self.copy_local
 
         if local is None or relative is None:
-            raise Errors.RepoError, \
-                  "get request for Repo %s, gave no source or dest" % self.ui_id
+            raise Errors.RepoError("get request for Repo %s, gave no source or dest" % self.ui_id,
+                                   repo=self)
 
         if self.cache == 1:
             if os.path.exists(local): # FIXME - we should figure out a way
                 return local          # to run the checkfunc from here
 
             else: # ain't there - raise
-                raise Errors.RepoError, \
-                    "Caching enabled but no local cache of %s from %s" % (local,
-
-                           self.ui_id)
+                raise Errors.RepoError("Caching enabled but no local cache of %s from %s" % (local, self.ui_id),
+                                       repo=self)
 
         if url:
             (scheme, netloc, path, query, fragid) = urlparse.urlsplit(url)
@@ -977,11 +979,11 @@ class YumRepository(Repository, config.RepoConf):
             dirstat = os.statvfs(os.path.dirname(local))
             avail = dirstat.f_bavail * dirstat.f_bsize
             if avail < long(size):
-                raise Errors.RepoError, _('''\
+                raise Errors.RepoError(_('''\
 Insufficient space in download directory %s
     * free   %s
     * needed %s'''
-                ) % (os.path.dirname(local), format_number(avail), format_number(long(size)))
+                ) % (os.path.dirname(local), format_number(avail), format_number(long(size))), repo=self)
 
         if url and scheme != "media":
             ugopts = self._default_grabopts(cache=cache)
@@ -1004,9 +1006,7 @@ Insufficient space in download directory %s
             except URLGrabError, e:
                 self._del_dl_file(local, size)
                 errstr = "failed to retrieve %s from %s\nerror was %s" % (relative, self, e)
-                e = Errors.RepoError(errstr)
-                e.repo = self
-                raise e
+                raise Errors.RepoError(errstr, repo=self)
 
         else:
             headers = tuple(self.__headersListFromDict(cache=cache))
@@ -1025,9 +1025,7 @@ Insufficient space in download directory %s
                 self._del_dl_file(local, size)
                 errstr = "failure: %s from %s: %s" % (relative, self, e)
                 errors = getattr(e, 'errors', None)
-                e = Errors.NoMoreMirrorsRepoError(errstr, errors)
-                e.repo = self
-                raise e
+                raise Errors.NoMoreMirrorsRepoError(errstr, errors, repo=self)
 
         return result
     __get = _getFile
@@ -1062,7 +1060,7 @@ Insufficient space in download directory %s
             # Don't return as "success" when bad.
             msg = "Downloaded package %s, from %s, but it was invalid."
             msg = msg % (package, package.repo.id)
-            raise Errors.RepoError, msg
+            raise Errors.RepoError(msg, repo=self)
 
         return ret
 
@@ -1118,7 +1116,8 @@ Insufficient space in download directory %s
             return self._metadataCurrent
 
         if self.cache and not os.path.exists(self.metalink_filename):
-            raise Errors.RepoError, 'Cannot find metalink.xml file for %s' %self
+            raise Errors.RepoError('Cannot find metalink.xml file for %s' %self,
+                                   repo=self)
 
         if self.cache:
             self._metadataCurrent = True
@@ -1209,7 +1208,8 @@ Insufficient space in download directory %s
     def _cachingRepoXML(self, local):
         """ Should we cache the current repomd.xml """
         if self.cache and not os.path.exists(local):
-            raise Errors.RepoError, 'Cannot find repomd.xml file for %s' % self.ui_id
+            raise Errors.RepoError('Cannot find repomd.xml file for %s' % self.ui_id,
+                                   repo=self)
         if self.cache or self.metadataCurrent():
             return True
         return False
@@ -1237,7 +1237,8 @@ Insufficient space in download directory %s
             misc.unlink_f(tfname)
             if grab_can_fail:
                 return None
-            raise Errors.RepoError, 'Error downloading file %s: %s' % (local, e)
+            raise Errors.RepoError('Error downloading file %s: %s' % (local, e),
+                                   repo=self)
         except Errors.RepoError:
             misc.unlink_f(tfname)
             if grab_can_fail:
@@ -1252,8 +1253,9 @@ Insufficient space in download directory %s
             misc.unlink_f(tfname)
             if grab_can_fail:
                 return None
-            raise Errors.RepoError, 'Error renaming file %s to %s' % (result,
-                                                                      local)
+            raise Errors.RepoError('Error renaming file %s to %s' % (result,
+                                                                      local),
+                                   repo=self)
         return local
 
     def _parseRepoXML(self, local, parse_can_fail=None):
@@ -1265,7 +1267,8 @@ Insufficient space in download directory %s
                 parse_can_fail = 'old_repo_XML' in self._oldRepoMDData
             if parse_can_fail:
                 return None
-            raise Errors.RepoError, 'Error importing repomd.xml from %s: %s' % (self.ui_id, e)
+            raise Errors.RepoError('Error importing repomd.xml from %s: %s' % (self.ui_id, e),
+                                   repo=self)
 
     def _saveOldRepoXML(self, local):
         """ If we have an older repomd.xml file available, save it out. """
@@ -1292,7 +1295,8 @@ Insufficient space in download directory %s
         #  We still want the old data, so we don't download twice. So we
         # pretend everything is good until the revert.
         if not self.timestamp_check:
-            raise Errors.RepoError, "Can't download or revert repomd.xml for %s" % self.ui_id
+            raise Errors.RepoError("Can't download or revert repomd.xml for %s" % self.ui_id,
+                                   repo=self)
 
         if 'old_repo_XML' not in self._oldRepoMDData:
             self._oldRepoMDData = {}
@@ -1658,7 +1662,8 @@ Insufficient space in download directory %s
         except KeyboardInterrupt:
             self._revertOldRepoXML() # Undo metadata cookie?
             raise
-        raise Errors.RepoError, 'Bad loadRepoXML policy (for %s): %s' % (self.ui_id, self.mdpolicy)
+        raise Errors.RepoError('Bad loadRepoXML policy (for %s): %s' % (self.ui_id, self.mdpolicy),
+                               repo=self)
 
     def _getRepoXML(self):
         if self._repoXML:
@@ -1816,7 +1821,7 @@ Insufficient space in download directory %s
                 msg = "Caching enabled and local cache: %s does not match checksum" % local
             else:
                 msg = "Caching enabled but no local cache of %s from %s" % (local, self.ui_id)
-            raise Errors.RepoError, msg
+            raise Errors.RepoError(msg, repo=self)
 
         try:
             def checkfunc(obj):
@@ -1851,8 +1856,8 @@ Insufficient space in download directory %s
         except URLGrabError, e:
             if retrieve_can_fail:
                 return None
-            raise Errors.RepoError, \
-                "Could not retrieve %s matching remote checksum from %s" % (local, self.ui_id)
+            raise Errors.RepoError("Could not retrieve %s matching remote checksum from %s" % (local, self.ui_id),
+                                   repo=self)
         else:
             return local
 
commit 0ed9b3e7d7579ccb297981ebbb04b38c08365c08
Author: James Antill <james at and.org>
Date:   Tue May 20 14:20:03 2014 -0400

    Add repo argument to RepoError, so we can easily set it to tell which one.

diff --git a/yum/Errors.py b/yum/Errors.py
index 2c2f022..f69c061 100644
--- a/yum/Errors.py
+++ b/yum/Errors.py
@@ -74,17 +74,24 @@ class DepError(YumBaseError):
     pass
     
 class RepoError(YumBaseError):
-    pass
+    def __init__(self, value=None, repo=None):
+        Exception.__init__(self)
+        self.value = value
+        if repo is not None:
+            self.repo = repo
 
 class DuplicateRepoError(RepoError):
     pass
 
 # Have our own custom .value with all the mirror errors.
 class NoMoreMirrorsRepoError(RepoError):
-    def __init__(self, value=None, errors=None):
+    # Weird backcompat. on argument ordering.
+    def __init__(self, value=None, errors=None, repo=None):
         Exception.__init__(self)
         self._value = value
         self.errors = errors
+        if repo is not None:
+            self.repo = repo
 
     @property
     def value(self):
commit c279edbf7bbde564dab195cf96b6d8e4d4b3dd4b
Author: James Antill <james at and.org>
Date:   Tue Apr 29 15:51:04 2014 -0400

    Fix update-minimal typo from man page.

diff --git a/docs/yum.8 b/docs/yum.8
index 3f028f8..86df6b0 100644
--- a/docs/yum.8
+++ b/docs/yum.8
@@ -25,7 +25,7 @@ gnome\-packagekit application\&.
 .br 
 .I \fR * update-to [package1] [package2] [\&.\&.\&.]
 .br 
-.I \fR * minimal-update [package1] [package2] [\&.\&.\&.]
+.I \fR * update-minimal [package1] [package2] [\&.\&.\&.]
 .br 
 .I \fR * check\-update
 .br 
commit 345c783ba885c9a8c80b632b1b9d24ff99df95aa
Author: James Antill <james at and.org>
Date:   Tue Apr 29 15:49:13 2014 -0400

    Add upgrade-minimal typos from man page.

diff --git a/yumcommands.py b/yumcommands.py
index 74e4d86..b610f3a 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -4139,7 +4139,8 @@ class UpdateinfoCommand(YumCommand):
 
 class UpdateMinimalCommand(YumCommand):
     def getNames(self):
-        return ['update-minimal', 'upgrade-minimal']
+        return ['update-minimal', 'upgrade-minimal',
+                'minimal-update', 'minimal-upgrade']
 
     def getUsage(self):
         return "[PACKAGE-wildcard]"


More information about the Yum-commits mailing list