diff options
author | Sol Jerome <sol.jerome@gmail.com> | 2011-04-26 12:40:32 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2011-04-26 12:40:32 -0500 |
commit | 944df5470f9d30717baccf7b716fd4847b31da27 (patch) | |
tree | 1211b8f65d13ff0934b1f3f5a5ada3112ea5a8dd /src | |
parent | 25576cd076d66dfed4bbd98ce1bbb3bc86a6230e (diff) | |
download | bcfg2-944df5470f9d30717baccf7b716fd4847b31da27.tar.gz bcfg2-944df5470f9d30717baccf7b716fd4847b31da27.tar.bz2 bcfg2-944df5470f9d30717baccf7b716fd4847b31da27.zip |
Consolidate PY3K compatibility libraries
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Bcfg2Py3k.py (renamed from src/lib/Server/Reports/py3kcompat.py) | 0 | ||||
-rwxr-xr-x | src/lib/Server/Reports/importscript.py | 4 | ||||
-rw-r--r-- | src/lib/Server/Reports/settings.py | 3 | ||||
-rw-r--r-- | src/lib/Server/Snapshots/__init__.py | 3 | ||||
-rw-r--r-- | src/lib/Server/Snapshots/model.py | 18 |
5 files changed, 19 insertions, 9 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 |