backend/common/Makefile | 3 +-
backend/common/rhnMail.py | 7 ++---
backend/common/rhnTB.py | 26 +++++++++------------
backend/common/stringutils.py | 29 ++++++++++++++++++++++++
backend/satellite_tools/sync_handlers.py | 3 +-
backend/server/action_extra_data/configfiles.py | 5 +---
backend/server/importlib/debPackage.py | 4 +--
backend/server/importlib/headerSource.py | 3 +-
backend/server/rhnSQL/driver_cx_Oracle.py | 8 +++---
backend/server/rhnSQL/sql_base.py | 7 -----
backend/server/rhnServer/server_certificate.py | 8 ++----
backend/spacewalk-backend.spec | 10 +++++++-
rel-eng/packages/spacewalk-backend | 2 -
13 files changed, 71 insertions(+), 44 deletions(-)
New commits:
commit c76bdce4339c262ff1025e20dc70599ef9d96426
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Oct 18 17:49:08 2013 +0200
Automatic commit of package [spacewalk-backend] release [2.1.29-1].
diff --git a/backend/spacewalk-backend.spec b/backend/spacewalk-backend.spec
index 44ab6ee..438aace 100644
--- a/backend/spacewalk-backend.spec
+++ b/backend/spacewalk-backend.spec
@@ -11,7 +11,7 @@ Name: spacewalk-backend
Summary: Common programs needed to be installed on the Spacewalk servers/proxies
Group: Applications/Internet
License: GPLv2
-Version: 2.1.28
+Version: 2.1.29
Release: 1%{?dist}
URL:
https://fedorahosted.org/spacewalk
Source0:
https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -628,6 +628,13 @@ rm -f %{rhnconf}/rhnSecret.py*
%{pythonrhnroot}/satellite_tools/exporter/xmlWriter.py*
%changelog
+* Fri Oct 18 2013 Michael Mraka <michael.mraka(a)redhat.com> 2.1.29-1
+- include stringutils into package
+- replace encode/decode with to_string/to_unicode
+- 891880 - reuse stringutils functions
+- 891880 - make sure we put strings to fd.write()
+- 1020910 - use sha1 to compare checksums
+
* Tue Oct 15 2013 Michael Mraka <michael.mraka(a)redhat.com> 2.1.28-1
- python pgsql tests: made easier Jenkins integration
diff --git a/rel-eng/packages/spacewalk-backend b/rel-eng/packages/spacewalk-backend
index 37e8bc2..b8c4508 100644
--- a/rel-eng/packages/spacewalk-backend
+++ b/rel-eng/packages/spacewalk-backend
@@ -1 +1 @@
-2.1.28-1 backend/
+2.1.29-1 backend/
commit 8c7ac8621dcddf6bcb8d1fb3fe9fe75a6ca0b23f
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Oct 18 17:26:44 2013 +0200
include stringutils into package
diff --git a/backend/common/Makefile b/backend/common/Makefile
index 50c2e38..e6ebcc3 100644
--- a/backend/common/Makefile
+++ b/backend/common/Makefile
@@ -27,7 +27,8 @@ SPACEWALK_FILES = __init__ \
rhn_deb \
rhn_mpm \
rhn_pkg \
- rhn_rpm
+ rhn_rpm \
+ stringutils
SCRIPTS = spacewalk-cfg-get
# check if we can build man pages
diff --git a/backend/spacewalk-backend.spec b/backend/spacewalk-backend.spec
index a4bbd9a..44ab6ee 100644
--- a/backend/spacewalk-backend.spec
+++ b/backend/spacewalk-backend.spec
@@ -512,6 +512,7 @@ rm -f %{rhnconf}/rhnSecret.py*
%{pythonrhnroot}/common/rhn_mpm.py*
%{pythonrhnroot}/common/rhn_pkg.py*
%{pythonrhnroot}/common/rhn_rpm.py*
+%{pythonrhnroot}/common/stringutils.py*
%files config-files-common
%doc LICENSE
commit f495b53debaec8289c53a233a230895dc74d1e80
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri May 3 18:32:25 2013 +0200
replace encode/decode with to_string/to_unicode
diff --git a/backend/satellite_tools/sync_handlers.py
b/backend/satellite_tools/sync_handlers.py
index 481d263..4d048c5 100644
--- a/backend/satellite_tools/sync_handlers.py
+++ b/backend/satellite_tools/sync_handlers.py
@@ -18,6 +18,7 @@ import types
import string
import sys
+from spacewalk.common.stringutils import to_string
from spacewalk.server import rhnSQL
from spacewalk.server.importlib import channelImport, packageImport, errataImport, \
kickstartImport, importLib
@@ -598,7 +599,7 @@ def populate_channel_family_permissions(cert):
# default the org to 1 for channel families from cert
org_id = 1
- cf_name = cf_name.encode('utf-8')
+ cf_name = to_string(cf_name)
try:
old_max_tuple = cfps[(cf_name, org_id)]
except KeyError:
diff --git a/backend/server/action_extra_data/configfiles.py
b/backend/server/action_extra_data/configfiles.py
index fa62303..c232aa2 100644
--- a/backend/server/action_extra_data/configfiles.py
+++ b/backend/server/action_extra_data/configfiles.py
@@ -15,9 +15,9 @@
# config file-related error handling functions
#
-from types import UnicodeType
from spacewalk.common import rhnFlags
from spacewalk.common.rhnLog import log_debug, log_error
+from spacewalk.common.stringutils import to_string
from spacewalk.server import rhnSQL
from spacewalk.server.rhnServer import server_kickstart
@@ -269,8 +269,7 @@ def _add_result(action_config_revision_id, diff):
if diff:
blob_map = {'result': 'result'}
- if type(diff) == UnicodeType:
- diff = unicode.encode(diff,'utf-8')
+ diff = to_string(diff)
else:
blob_map = None
diff = None
diff --git a/backend/server/importlib/debPackage.py
b/backend/server/importlib/debPackage.py
index 99f5c90..b799e3b 100644
--- a/backend/server/importlib/debPackage.py
+++ b/backend/server/importlib/debPackage.py
@@ -22,7 +22,7 @@ import string
from importLib import Channel
from backendLib import gmtime, localtime
from types import IntType
-
+from spacewalk.common.stringutils import to_string
class debBinaryPackage(headerSource.rpmBinaryPackage):
@@ -62,7 +62,7 @@ class debBinaryPackage(headerSource.rpmBinaryPackage):
elif val:
# Convert to strings
if isinstance(val, unicode):
- val = unicode.encode(val, 'utf-8')
+ val = to_string(val)
else:
val = str(val)
elif val == []:
diff --git a/backend/server/importlib/headerSource.py
b/backend/server/importlib/headerSource.py
index 37026fd..7933d29 100644
--- a/backend/server/importlib/headerSource.py
+++ b/backend/server/importlib/headerSource.py
@@ -24,6 +24,7 @@ from importLib import File, Dependency, ChangeLog, Channel, \
from backendLib import gmtime, localtime
from types import ListType, TupleType, IntType, LongType, StringType
from spacewalk.common.rhnLog import log_debug
+from spacewalk.common.stringutils import to_string
class rpmPackage(IncompletePackage):
# Various mappings
@@ -65,7 +66,7 @@ class rpmPackage(IncompletePackage):
elif val:
# Convert to strings
if isinstance(val, unicode):
- val = unicode.encode(val, 'utf-8')
+ val = to_string(val)
else:
val = str(val)
elif val == []:
diff --git a/backend/server/rhnSQL/driver_cx_Oracle.py
b/backend/server/rhnSQL/driver_cx_Oracle.py
index 03575da..0af3df6 100644
--- a/backend/server/rhnSQL/driver_cx_Oracle.py
+++ b/backend/server/rhnSQL/driver_cx_Oracle.py
@@ -34,7 +34,7 @@ from spacewalk.server import rhnSQL
from spacewalk.common import rhnConfig
from spacewalk.common.rhnLog import log_debug, log_error
from spacewalk.common.rhnException import rhnException
-from sql_base import adjust_type
+from spacewalk.common.stringutils import to_string
from const import ORACLE
ORACLE_TYPE_MAPPING = [
@@ -154,7 +154,7 @@ class Cursor(sql_base.Cursor):
if not _p.has_key(k):
# Raise the fault ourselves
raise sql_base.SQLError(1008, 'Not all variables bound', k)
- params[k] = adjust_type(_p[k])
+ params[k] = to_string(_p[k])
# cx_Oracle expects the first arg to be the statement and no
# positional args:
@@ -194,7 +194,7 @@ class Cursor(sql_base.Cursor):
for i in xrange(item_count):
pdict = arr[i]
for k, v in kwargs.iteritems():
- pdict[k] = adjust_type(v[start+i])
+ pdict[k] = to_string(v[start+i])
# We clear self->bindVariables so that list of all nulls
# in the previous chunk which caused the type to be set to
@@ -326,7 +326,7 @@ class Procedure(sql_base.Procedure):
return self._call_proc_ret(args, ret_type=None)
def _call_proc_ret(self, args, ret_type=None):
- args = map(adjust_type, self._munge_args(args))
+ args = map(to_string, self._munge_args(args))
if ret_type:
for sqltype, db_type in self._type_mapping:
if isinstance(ret_type, sqltype):
diff --git a/backend/server/rhnSQL/sql_base.py b/backend/server/rhnSQL/sql_base.py
index f76c2e1..e1ce75a 100644
--- a/backend/server/rhnSQL/sql_base.py
+++ b/backend/server/rhnSQL/sql_base.py
@@ -28,13 +28,6 @@ import sys
import sql_types
import types
-def adjust_type(val):
- """ Adjust data types prior to calling execute(). """
- if isinstance(val, types.UnicodeType):
- # Represent it as UTF8
- return val.encode("UTF8")
- return val
-
def ociDict(names=None, row=None):
""" Create a dictionary from a row description and its values.
"""
data = {}
diff --git a/backend/server/rhnServer/server_certificate.py
b/backend/server/rhnServer/server_certificate.py
index 30ee545..5d2e3ed 100644
--- a/backend/server/rhnServer/server_certificate.py
+++ b/backend/server/rhnServer/server_certificate.py
@@ -26,6 +26,7 @@ import xmlrpclib
from spacewalk.common.rhnLog import log_debug, log_error
from spacewalk.common.rhnException import rhnFault
+from spacewalk.common.stringutils import to_string
from server_lib import getServerSecret
def gen_secret():
@@ -56,7 +57,7 @@ class Checksum:
else:
if type(arg) == type(0):
arg = str(arg)
- self.sum.update(arg.encode("utf-8"))
+ self.sum.update(to_string(arg))
def __repr__(self):
t = ""
for i in self.sum.digest()[:]:
@@ -141,10 +142,7 @@ class Certificate:
return -1
# Now decode this certificate
try:
- if isinstance(text_id, unicode):
- sysid, junk = xmlrpclib.loads(text_id.encode('utf-8'))
- else:
- sysid, junk = xmlrpclib.loads(text_id)
+ sysid, junk = xmlrpclib.loads(to_string(text_id))
except:
return -1
else:
commit c75009845c65d9a956238b46f52931c6fd2ae4c4
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri May 3 17:42:47 2013 +0200
891880 - reuse stringutils functions
diff --git a/backend/common/rhnMail.py b/backend/common/rhnMail.py
index 2059c59..684fced 100644
--- a/backend/common/rhnMail.py
+++ b/backend/common/rhnMail.py
@@ -20,6 +20,7 @@ import smtplib
from rhnConfig import CFG, PRODUCT_NAME
from rhn.connections import idn_pune_to_unicode
+from stringutils import to_string
# check if the headers have the minimum required fields
def __check_headers(h):
@@ -53,8 +54,6 @@ def send(headers, body, sender = None):
joined_headers += u"%s: %s\n" % (h, headers[h])
server = smtplib.SMTP('localhost')
- if not isinstance(body, unicode):
- body = body.decode('utf-8')
- msg = u"%s\n%s\n" % (joined_headers, body)
- server.sendmail(sender, toaddrs, msg.encode('utf-8'))
+ msg = "%s\n%s\n" % (to_string(joined_headers), to_string(body))
+ server.sendmail(sender, toaddrs, msg)
server.quit()
commit e8628e3b3decc8502f4914d9f60c1d5e1dee3bd6
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri May 3 17:13:55 2013 +0200
891880 - make sure we put strings to fd.write()
diff --git a/backend/common/rhnTB.py b/backend/common/rhnTB.py
index 209cac3..9c77f58 100644
--- a/backend/common/rhnTB.py
+++ b/backend/common/rhnTB.py
@@ -24,6 +24,7 @@ from rhn.connections import idn_pune_to_unicode
from rhnConfig import CFG, PRODUCT_NAME
from rhnLog import log_error
from rhnTranslate import _
+from stringutils import to_string
import rhnMail
import rhnFlags
@@ -44,7 +45,7 @@ def print_env(fd = sys.stderr):
el = dct.keys()
el.sort()
for k in el:
- fd.write("%s = %s\n" % (k, dct[k]))
+ fd.write("%s = %s\n" % (to_string(k), to_string(dct[k])))
def print_locals(fd = sys.stderr, tb = None):
@@ -70,13 +71,13 @@ def print_locals(fd = sys.stderr, tb = None):
frame.f_code.co_filename,
frame.f_lineno))
for key, value in frame.f_locals.items():
- fd.write("\t%20s = " % key)
+ fd.write("\t%20s = " % to_string(key))
# We have to be careful not to cause a new error in our error
# printer! Calling str() on an unknown object could cause an
# error we don't want.
# pylint: disable=W0702
try:
- s = str(value)
+ s = str(to_string(value))
except:
s = "<ERROR WHILE PRINTING VALUE>"
if len(s) > 100 * 1024:
@@ -98,7 +99,7 @@ def print_req(req, fd = sys.stderr):
kl = req.headers_in.keys()
kl.sort()
for k in kl:
- fd.write("\t%s: %s\n" % (k, req.headers_in[k]))
+ fd.write("\t%s: %s\n" % (to_string(k), to_string(req.headers_in[k])))
return 0
@@ -126,16 +127,16 @@ def Traceback(method = None, req = None, mail = 1, ostream =
sys.stderr,
exc = StringIO()
unicode_hostname = idn_pune_to_unicode(hostname)
- exc.write("Exception reported from %s\nTime: %s\n" % (unicode_hostname,
t))
- exc.write("Exception type %s\n" % (e_type,))
+ exc.write("Exception reported from %s\nTime: %s\n" %
(to_string(unicode_hostname), t))
+ exc.write("Exception type %s\n" % to_string(e_type))
if method:
- exc.write("Exception while handling function %s\n" % method)
+ exc.write("Exception while handling function %s\n" %
to_string(method))
# print information about the request being served
if req:
print_req(req, exc)
if extra:
- exc.write("Extra information about this error:\n%s\n" % extra)
+ exc.write("Extra information about this error:\n%s\n" %
to_string(extra))
# Print the traceback
exc.write("\nException Handler Information\n")
@@ -147,11 +148,8 @@ def Traceback(method = None, req = None, mail = 1, ostream =
sys.stderr,
# we always log it somewhere
if ostream:
- msg = exc.getvalue()
- if isinstance(msg, unicode):
- msg = msg.encode('utf-8')
- ostream.write("%s\n" % msg)
-
+ ostream.write(to_string(exc.getvalue()))
+ ostream.write("\n")
if mail:
# print the stack frames for the mail we send out
@@ -175,7 +173,7 @@ def Traceback(method = None, req = None, mail = 1, ostream =
sys.stderr,
}
QUIET_MAIL = QUIET_MAIL - 1 # count it no matter what
- outstring = exc.getvalue()
+ outstring = to_string(exc.getvalue())
#5/18/05 wregglej - 151158 Go through every string in the security list
# and censor it out of the debug information.
diff --git a/backend/common/stringutils.py b/backend/common/stringutils.py
new file mode 100644
index 0000000..b7d8715
--- /dev/null
+++ b/backend/common/stringutils.py
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 2013 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+
+from types import StringType, UnicodeType
+
+
+def to_unicode(obj):
+ if type(obj) == StringType:
+ return unicode(obj, 'utf8')
+ else:
+ return obj
+
+def to_string(obj):
+ if type(obj) == UnicodeType:
+ return obj.encode('utf8')
+ else:
+ return obj