[Yum-devel] [PATCH 2/2] Add dynamic yumvars from the filesystem.

James Antill james at and.org
Fri Apr 9 20:00:48 UTC 2010


---
 docs/yum.conf.5 |   12 ++++++++++++
 yum/config.py   |   23 ++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/docs/yum.conf.5 b/docs/yum.conf.5
index fe195af..54e7bf9 100644
--- a/docs/yum.conf.5
+++ b/docs/yum.conf.5
@@ -769,6 +769,18 @@ These will be replaced with the value of the shell environment variable of
 the same name. If the shell environment variable does not exist then the
 configuration file variable will not be replaced.
 
+.LP
+As of 3.2.28, any file in <installroot>/<persistdir>/vars is turned into
+a variable named after the filename (or overrides any of the above varaibles).
+The obvious exception is that you cannot use these variables in the definition
+of persistdir itself.
+
+Note that no warnings/errors are given if the files are unreadable, so creating
+files that only root can read may be confusing for users.
+
+Also note that all new line characters are removed, as a convienience, but no
+other checking is performed on the data. This means it's possible to have bad
+character data in baseurl etc.
 
 .SH "FILES"
 .nf
diff --git a/yum/config.py b/yum/config.py
index d869a26..e13eb12 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -857,13 +857,15 @@ def readMainConfig(startupconf):
     yumvars['arch'] = startupconf.arch
     yumvars['releasever'] = startupconf.releasever
     yumvars['uuid'] = startupconf.uuid
+    # Note: We don't setup the FS yumvars here, because we want to be able to
+    #       use the core yumvars in persistdir. Which is the base of FS yumvars.
     
     # Read [main] section
     yumconf = YumConf()
     yumconf.populate(startupconf._parser, 'main')
 
     # Apply the installroot to directory options
-    for option in ('cachedir', 'logfile', 'persistdir'):
+    def _apply_installroot(yumconf, option):
         path = getattr(yumconf, option)
         ir_path = yumconf.installroot + path
         ir_path = ir_path.replace('//', '/') # os.path.normpath won't fix this and
@@ -871,6 +873,25 @@ def readMainConfig(startupconf):
         ir_path = varReplace(ir_path, yumvars)
         setattr(yumconf, option, ir_path)
     
+    _apply_installroot(yumconf, 'persistdir')
+
+    # Read the FS yumvars
+    try:
+        dir_fsvars = yumconf.persistdir + "/vars/"
+        fsvars = os.listdir(dir_fsvars)
+    except OSError:
+        fsvars = []
+    for fsvar in fsvars:
+        try:
+            val = open(dir_fsvars + fsvar).read().replace('\n', '')
+        except (OSError, IOError):
+            continue
+        yumvars[fsvar] = val
+
+    # These can use the above FS yumvars
+    for option in ('cachedir', 'logfile'):
+        _apply_installroot(yumconf, option)
+
     # Add in some extra attributes which aren't actually configuration values 
     yumconf.yumvar = yumvars
     yumconf.uid = 0
-- 
1.6.6.1



More information about the Yum-devel mailing list