[Yum-devel] [PATCH] add uuid functionality so we can have additional info to work from trivially.

Seth Vidal skvidal at fedoraproject.org
Thu Feb 4 20:31:28 UTC 2010


---
 docs/yum.conf.5 |    6 ++++++
 yum/__init__.py |    8 ++++++--
 yum/config.py   |    5 ++++-
 yum/misc.py     |   24 ++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/docs/yum.conf.5 b/docs/yum.conf.5
index 494296e..cca3db7 100644
--- a/docs/yum.conf.5
+++ b/docs/yum.conf.5
@@ -744,6 +744,12 @@ This will be replaced with your base architecture in yum. For example, if
 your $arch is i686 your $basearch will be i386.
 
 .IP
+\fB$uuid\fR
+This will be replaced with a unique but persistent uuid for this machine. 
+The value that is first generated will be stored in /var/lib/yum/uuid and
+reused until this file is deleted.
+
+.IP
 \fB$YUM0-$YUM9\fR
 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
diff --git a/yum/__init__.py b/yum/__init__.py
index 1fe8889..968362c 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -104,6 +104,7 @@ class _YumPreBaseConf:
         self.syslog_device = '/dev/log'
         self.arch = None
         self.releasever = None
+        self.uuid = None
 
 class _YumCostExclude:
     """ This excludes packages that are in repos. of lower cost than the passed
@@ -236,7 +237,8 @@ class YumBase(depsolve.Depsolve):
         syslog_device   = self.preconf.syslog_device
         releasever = self.preconf.releasever
         arch = self.preconf.arch
-
+        uuid = self.preconf.uuid
+        
         if arch: # if preconf is setting an arch we need to pass that up
             self.arch.setup_arch(arch)
         else:
@@ -251,7 +253,9 @@ class YumBase(depsolve.Depsolve):
         startupconf = config.readStartupConfig(fn, root)
         startupconf.arch = arch
         startupconf.basearch = self.arch.basearch
-
+        if uuid:
+            startupconf.uuid = uuid
+        
         if startupconf.gaftonmode:
             global _
             _ = yum.i18n.dummy_wrapper
diff --git a/yum/config.py b/yum/config.py
index b43ce7c..aa1583d 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -40,6 +40,7 @@ if not _use_iniparse:
 import rpmUtils.transaction
 import Errors
 import types
+from misc import get_uuid
 
 # Alter/patch these to change the default checking...
 __pkgs_gpgcheck_default__ = False
@@ -832,6 +833,7 @@ def readStartupConfig(configfile, root):
     startupconf._parser = parser
     # setup the release ver here
     startupconf.releasever = _getsysver(startupconf.installroot, startupconf.distroverpkg)
+    startupconf.uuid = get_uuid(startupconf.installroot + '/var/lib/yum/uuid')
 
     return startupconf
 
@@ -850,7 +852,8 @@ def readMainConfig(startupconf):
     yumvars['basearch'] = startupconf.basearch
     yumvars['arch'] = startupconf.arch
     yumvars['releasever'] = startupconf.releasever
-
+    yumvars['uuid'] = startupconf.uuid
+    
     # Read [main] section
     yumconf = YumConf()
     yumconf.populate(startupconf._parser, 'main')
diff --git a/yum/misc.py b/yum/misc.py
index 3917a4f..4b0226b 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -921,3 +921,27 @@ def get_open_files(pid):
                 files.append(i)
 
     return files
+
+def get_uuid(savepath):
+    """create, store and return a uuid. If a stored one exists, report that
+       if it cannot be stored, return a random one"""
+    if os.path.exists(savepath):
+        return open(savepath, 'r').read()
+    else:
+        try:
+            from uuid import uuid4
+        except ImportError:
+            myid = open('/proc/sys/kernel/random/uuid', 'r').read()
+        else:
+            myid = str(uuid4())
+        
+        try:
+            sf = open(savepath, 'w')
+            sf.write(myid)
+            sf.flush()
+            sf.close()
+        except (IOError, OSError), e:
+            pass
+        
+        return myid
+        
-- 
1.6.6



More information about the Yum-devel mailing list