From 449379d8c0f3437fdad3c8996dc5009a348078b0 Mon Sep 17 00:00:00 2001
From: Tomas Karasek <tomas.karasek@cern.ch>
Date: Tue, 27 Nov 2012 08:59:42 +0100
Subject: [PATCH] Added prettytable mock and patched specfile

---
 cloud-init.spec |   10 +++++++++-
 prettytable.py  |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletions(-)
 create mode 100644 prettytable.py

diff --git a/cloud-init.spec b/cloud-init.spec
index 08b1b8c..ba4af8b 100644
--- a/cloud-init.spec
+++ b/cloud-init.spec
@@ -14,6 +14,7 @@ URL:            http://launchpad.net/cloud-init
 Source0:        https://launchpad.net/cloud-init/trunk/%{version}/+download/cloud-init-%{version}.tar.gz
 Source1:        cloud-init-rhel.cfg
 Source2:        cloud-init-README.fedora
+Source3:        prettytable.py
 Patch0:         cloud-init-0.7.0-fedora.patch
 Patch999:       cloud-init-0.7.1-rhel.patch
 
@@ -26,6 +27,7 @@ BuildRequires:  python-setuptools-devel
 Requires:       e2fsprogs
 %else
 BuildRequires:  python26-devel
+BuildRequires:  python26-argparse
 BuildRequires:  python-setuptools
 Requires:       e4fsprogs
 %endif
@@ -33,7 +35,6 @@ Requires:       dmidecode
 Requires:       iproute
 Requires:       libselinux-python
 Requires:       net-tools
-Requires:       policycoreutils-python
 Requires:       procps
 Requires:       python-argparse
 %if 0%{?rhel} >= 6
@@ -42,6 +43,7 @@ Requires:       python-cheetah
 Requires:       python-configobj
 Requires:       python-prettytable
 Requires:       PyYAML
+Requires:       policycoreutils-python
 %else
 Requires:       python26-boto
 Requires:       python26-cheetah
@@ -82,6 +84,12 @@ mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/cloud
 # We supply our own config file since our software differs from Ubuntu's.
 cp -p %{SOURCE1} $RPM_BUILD_ROOT/%{_sysconfdir}/cloud/cloud.cfg
 
+
+# We supply our own prettytable in el5
+%if 0%{?rhel} <= 5
+cp -p %{SOURCE3} $RPM_BUILD_ROOT/%{python_sitelib}/cloudinit/prettytable.py
+%endif
+
 mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
 cp -p tools/21-cloudinit.conf $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
 
diff --git a/prettytable.py b/prettytable.py
new file mode 100644
index 0000000..7e8080b
--- /dev/null
+++ b/prettytable.py
@@ -0,0 +1,35 @@
+# vi: ts=4 expandtab
+#
+#    Copyright (C) 2012 CERN
+#
+#    Author: Tomas Karasek <tomas.karasek@cern.ch>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License version 3, as
+#    published by the Free Software Foundation.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Dummy class for EL5 where there's no prettytable for python26
+class PrettyTable:
+    def __init__(self, header):
+        self.header = header
+        self.rows = []
+
+    def add_row(self, row):
+        self.rows.append(row)
+
+    def get_string(self):
+        ret = ",".join(self.header)
+        ret += "\n============================"
+        for row in self.rows:
+            ret += "\n" + ", ".join([r.__str__() for r in row])
+        ret += "\n"
+        return ret
+
-- 
1.7.1

