Blob Blame History Raw
From 4de0fc40cca5c2cc004b954ef3a19438bb0a5b8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
Date: Tue, 23 Jul 2013 12:37:12 +0100
Subject: [PATCH] Use updated parallel install versions of epel package

Use sqlalchemy >= 0.6.3 WebOb >= 1.0 Routes >= 1.12.3 PasteDeploy >= 1.5.0
and depend on the parallel installable
versions of these packages to satisfy those requirements.

Delve into pkg_resources a little to get it to modify sys.path,
so that our parallel installed egg takes precedence over the
system default module versions.
---
 glance/__init__.py |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/glance/__init__.py b/glance/__init__.py
index b6d314b..86ec0ab 100644
--- a/glance/__init__.py
+++ b/glance/__init__.py
@@ -18,3 +18,31 @@
 import gettext
 
 gettext.install('glance', unicode=1)
+
+import sys
+import pkg_resources
+
+# If there is a conflicting non egg module,
+# i.e. an older standard system module installed,
+# then replace it with this requirement
+def replace_dist(requirement):
+    try:
+        return pkg_resources.require(requirement)
+    except pkg_resources.VersionConflict:
+        e = sys.exc_info()[1]
+        dist=e.args[0]
+        req=e.args[1]
+        if dist.key == req.key and not dist.location.endswith('.egg'):
+            del pkg_resources.working_set.by_key[dist.key]
+            # We assume there is no need to adjust sys.path
+            # and the associated pkg_resources.working_set.entries
+            return pkg_resources.require(requirement)
+
+replace_dist("SQLALchemy >= 0.6.3")
+replace_dist("WebOb >= 1.0")
+replace_dist("Routes >= 1.12.3")
+
+replace_dist("PasteDeploy >= 1.5.0")
+# This hack is needed because replace_dist() results in
+# the standard paste module path being at the start of __path__.
+# TODO: See can we get pkg_resources to do the right thing directly