summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-04-26 12:40:32 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-04-26 12:40:32 -0500
commit944df5470f9d30717baccf7b716fd4847b31da27 (patch)
tree1211b8f65d13ff0934b1f3f5a5ada3112ea5a8dd
parent25576cd076d66dfed4bbd98ce1bbb3bc86a6230e (diff)
downloadbcfg2-944df5470f9d30717baccf7b716fd4847b31da27.tar.gz
bcfg2-944df5470f9d30717baccf7b716fd4847b31da27.tar.bz2
bcfg2-944df5470f9d30717baccf7b716fd4847b31da27.zip
Consolidate PY3K compatibility libraries
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
-rw-r--r--src/lib/Bcfg2Py3k.py (renamed from src/lib/Server/Reports/py3kcompat.py)0
-rwxr-xr-xsrc/lib/Server/Reports/importscript.py4
-rw-r--r--src/lib/Server/Reports/settings.py3
-rw-r--r--src/lib/Server/Snapshots/__init__.py3
-rw-r--r--src/lib/Server/Snapshots/model.py18
-rw-r--r--tools/create-debian-pkglist-gp.py6
-rwxr-xr-xtools/create-debian-pkglist.py6
-rwxr-xr-xtools/export.py2
-rwxr-xr-xtools/pkgmgr_gen.py2
-rwxr-xr-xtools/pkgmgr_update.py2
-rw-r--r--tools/py3kcompat.py24
11 files changed, 28 insertions, 42 deletions
diff --git a/src/lib/Server/Reports/py3kcompat.py b/src/lib/Bcfg2Py3k.py
index b334c4466..b334c4466 100644
--- a/src/lib/Server/Reports/py3kcompat.py
+++ b/src/lib/Bcfg2Py3k.py
diff --git a/src/lib/Server/Reports/importscript.py b/src/lib/Server/Reports/importscript.py
index 0766ffa94..1781e2fac 100755
--- a/src/lib/Server/Reports/importscript.py
+++ b/src/lib/Server/Reports/importscript.py
@@ -34,8 +34,8 @@ import logging
import Bcfg2.Logger
import platform
-# Compatibility imports
-from py3kcompat import ConfigParser
+# Compatibility import
+from Bcfg2.Bcfg2Py3k import ConfigParser
def build_reason_kwargs(r_ent):
diff --git a/src/lib/Server/Reports/settings.py b/src/lib/Server/Reports/settings.py
index 0b9d25776..5a9e4ae4b 100644
--- a/src/lib/Server/Reports/settings.py
+++ b/src/lib/Server/Reports/settings.py
@@ -1,7 +1,8 @@
import django
+# Compatibility import
+from Bcfg2.Bcfg2Py3k import ConfigParser
# Django settings for bcfg2 reports project.
-from py3kcompat import ConfigParser
c = ConfigParser()
c.read(['/etc/bcfg2.conf', '/etc/bcfg2-web.conf'])
diff --git a/src/lib/Server/Snapshots/__init__.py b/src/lib/Server/Snapshots/__init__.py
index a4d8fadbc..7c901adb2 100644
--- a/src/lib/Server/Snapshots/__init__.py
+++ b/src/lib/Server/Snapshots/__init__.py
@@ -2,7 +2,8 @@ __all__ = ['models', 'db_from_config', 'setup_session']
import sqlalchemy
import sqlalchemy.orm
-import ConfigParser
+# Compatibility import
+from Bcfg2.Bcfg2Py3k import ConfigParser
def db_from_config(cfile):
diff --git a/src/lib/Server/Snapshots/model.py b/src/lib/Server/Snapshots/model.py
index 130d3e8c2..a2395d168 100644
--- a/src/lib/Server/Snapshots/model.py
+++ b/src/lib/Server/Snapshots/model.py
@@ -1,3 +1,4 @@
+import sys
from sqlalchemy import Table, Column, Integer, Unicode, ForeignKey, Boolean, \
DateTime, UnicodeText, desc
import datetime
@@ -6,6 +7,13 @@ from sqlalchemy.orm import relation, backref
from sqlalchemy.ext.declarative import declarative_base
+def u_str(string)
+ if sys.hexversion >= 0x03000000:
+ return string
+ else:
+ return unicode(string)
+
+
class Uniquer(object):
force_rt = True
@@ -103,10 +111,10 @@ class Metadata(Base):
@classmethod
def from_metadata(cls, mysession, mymetadata):
- client = Client.by_value(mysession, name=unicode(mymetadata.hostname))
+ client = Client.by_value(mysession, name=u_str(mymetadata.hostname))
m = cls(client=client)
for group in mymetadata.groups:
- m.groups.append(Group.by_value(mysession, name=unicode(group)))
+ m.groups.append(Group.by_value(mysession, name=u_str(group)))
for connector in mymetadata.connectors:
data = getattr(mymetadata, connector)
if not isinstance(data, dict):
@@ -115,9 +123,9 @@ class Metadata(Base):
if not isinstance(value, str):
continue
m.keyvals.append(ConnectorKeyVal.by_value(mysession,
- connector=unicode(connector),
- key=unicode(key),
- value=unicode(value)))
+ connector=u_str(connector),
+ key=u_str(key),
+ value=u_str(value)))
return m
diff --git a/tools/create-debian-pkglist-gp.py b/tools/create-debian-pkglist-gp.py
index 23c4127bd..cefb8f3fb 100644
--- a/tools/create-debian-pkglist-gp.py
+++ b/tools/create-debian-pkglist-gp.py
@@ -10,9 +10,9 @@ import sys
import subprocess
# Compatibility imports
-from py3kcompat import StringIO
-from py3kcompat import ConfigParser
-from py3kcompat import urlopen
+from Bcfg2.Bcfg2Py3k import StringIO
+from Bcfg2.Bcfg2Py3k import ConfigParser
+from Bcfg2.Bcfg2Py3k import urlopen
def debug(msg):
'''print debug messages'''
diff --git a/tools/create-debian-pkglist.py b/tools/create-debian-pkglist.py
index 91732aae3..8e1210582 100755
--- a/tools/create-debian-pkglist.py
+++ b/tools/create-debian-pkglist.py
@@ -12,9 +12,9 @@ import re
import sys
# Compatibility imports
-from py3kcompat import StringIO
-from py3kcompat import ConfigParser
-from py3kcompat import urlopen
+from Bcfg2.Bcfg2Py3k import StringIO
+from Bcfg2.Bcfg2Py3k import ConfigParser
+from Bcfg2.Bcfg2Py3k import urlopen
apt_pkg.init()
diff --git a/tools/export.py b/tools/export.py
index e28b8a6e0..d637c166c 100755
--- a/tools/export.py
+++ b/tools/export.py
@@ -9,7 +9,7 @@ from subprocess import Popen, PIPE
import sys
# Compatibility import
-from py3kcompat import formatdate
+from Bcfg2.Bcfg2Py3k import formatdate
pkgname = 'bcfg2'
ftphost = 'terra.mcs.anl.gov'
diff --git a/tools/pkgmgr_gen.py b/tools/pkgmgr_gen.py
index 3ae6ae948..03d36dfc0 100755
--- a/tools/pkgmgr_gen.py
+++ b/tools/pkgmgr_gen.py
@@ -24,7 +24,7 @@ import xml.sax
from xml.sax.handler import ContentHandler
# Compatibility imports
-from py3kcompat import urljoin
+from Bcfg2.Bcfg2Py3k import urljoin
def info(object, spacing=10, collapse=1):
diff --git a/tools/pkgmgr_update.py b/tools/pkgmgr_update.py
index 49514bd11..05d645786 100755
--- a/tools/pkgmgr_update.py
+++ b/tools/pkgmgr_update.py
@@ -22,7 +22,7 @@ import rpm
import sys
# Compatibility imports
-from py3kcompat import urljoin
+from Bcfg2.Bcfg2Py3k import urljoin
try:
from lxml.etree import parse, tostring
diff --git a/tools/py3kcompat.py b/tools/py3kcompat.py
deleted file mode 100644
index b334c4466..000000000
--- a/tools/py3kcompat.py
+++ /dev/null
@@ -1,24 +0,0 @@
-try:
- from email.Utils import formatdate
-except ImportError:
- from email.utils import formatdate
-
-# urllib imports
-try:
- from urllib import urlopen
-except ImportError:
- from urllib.request import urlopen
-try:
- from urlparse import urljoin
-except ImportError:
- from urllib.parse import urljoin
-
-try:
- from cStringIO import StringIO
-except ImportError:
- from io import StringIO
-
-try:
- import ConfigParser
-except ImportError:
- import configparser as ConfigParser