summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-04-26 10:14:43 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-04-26 10:19:52 -0500
commit7ed0493ee4af4ca14bb7642a29a66cd51f4d5836 (patch)
treed94042b8d8302da3d6989b720fe73cc9cd06e185 /tools
parente1c5dcea61d36c589b639e080a314c871b1b129f (diff)
downloadbcfg2-7ed0493ee4af4ca14bb7642a29a66cd51f4d5836.tar.gz
bcfg2-7ed0493ee4af4ca14bb7642a29a66cd51f4d5836.tar.bz2
bcfg2-7ed0493ee4af4ca14bb7642a29a66cd51f4d5836.zip
tools: Add full PY3K compatibility
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/create-debian-pkglist-gp.py12
-rwxr-xr-xtools/create-debian-pkglist.py12
-rwxr-xr-xtools/export.py4
-rwxr-xr-xtools/pkgmgr_gen.py9
-rwxr-xr-xtools/pkgmgr_update.py9
-rw-r--r--tools/py3kcompat.py24
-rw-r--r--tools/yum-listpkgs-xml.py4
7 files changed, 52 insertions, 22 deletions
diff --git a/tools/create-debian-pkglist-gp.py b/tools/create-debian-pkglist-gp.py
index b7f18bf1a..23c4127bd 100644
--- a/tools/create-debian-pkglist-gp.py
+++ b/tools/create-debian-pkglist-gp.py
@@ -1,18 +1,18 @@
#!/usr/bin/env python
'''Build debian/ubuntu package indexes'''
-__revision__ = '$Id: create-debian-pkglist.py 11778 2007-12-11 13:46:06Z guillaume $'
# Original code from Bcfg2 sources
import gzip
import os
-import urllib
-import cStringIO
import sys
-import ConfigParser
import subprocess
+# Compatibility imports
+from py3kcompat import StringIO
+from py3kcompat import ConfigParser
+from py3kcompat import urlopen
def debug(msg):
'''print debug messages'''
@@ -110,8 +110,8 @@ Source URLS: %s""" % (self.filename, self.groups, self.priority, self.architectu
url = "%s/dists/%s/%s/binary-%s/Packages.gz" % (source_url.url, source_url.distribution, section, arch)
debug("Processing url %s\n" % (url))
try:
- data = urllib.urlopen(url)
- buf = cStringIO.StringIO(''.join(data.readlines()))
+ data = urlopen(url)
+ buf = StringIO(''.join(data.readlines()))
reader = gzip.GzipFile(fileobj=buf)
for line in reader.readlines():
if line[:8] == 'Package:':
diff --git a/tools/create-debian-pkglist.py b/tools/create-debian-pkglist.py
index 1127f0448..91732aae3 100755
--- a/tools/create-debian-pkglist.py
+++ b/tools/create-debian-pkglist.py
@@ -6,14 +6,16 @@ __revision__ = '$Id$'
# Original code from Bcfg2 sources
import apt_pkg
-import ConfigParser
-import cStringIO
import gzip
import os
import re
-import urllib
import sys
+# Compatibility imports
+from py3kcompat import StringIO
+from py3kcompat import ConfigParser
+from py3kcompat import urlopen
+
apt_pkg.init()
@@ -143,8 +145,8 @@ Source URLS: %s""" % (self.filename, self.groups, self.priority, self.architectu
arch)
debug("Processing url %s\n" % (url))
try:
- data = urllib.urlopen(url)
- buf = cStringIO.StringIO(''.join(data.readlines()))
+ data = urlopen(url)
+ buf = StringIO(''.join(data.readlines()))
reader = gzip.GzipFile(fileobj=buf)
for line in reader.readlines():
if line[:8] == 'Package:':
diff --git a/tools/export.py b/tools/export.py
index d32ad3a60..e28b8a6e0 100755
--- a/tools/export.py
+++ b/tools/export.py
@@ -4,11 +4,13 @@
First attempt to make our export script more portable than export.sh
"""
-from email.Utils import formatdate
import fileinput
from subprocess import Popen, PIPE
import sys
+# Compatibility import
+from py3kcompat import formatdate
+
pkgname = 'bcfg2'
ftphost = 'terra.mcs.anl.gov'
ftpdir = '/mcs/ftp/pub/bcfg'
diff --git a/tools/pkgmgr_gen.py b/tools/pkgmgr_gen.py
index 9ce15b8c3..3ae6ae948 100755
--- a/tools/pkgmgr_gen.py
+++ b/tools/pkgmgr_gen.py
@@ -19,12 +19,13 @@ import optparse
import os
import rpm
import sys
-import urllib
-import urlparse
from lxml.etree import parse
import xml.sax
from xml.sax.handler import ContentHandler
+# Compatibility imports
+from py3kcompat import urljoin
+
def info(object, spacing=10, collapse=1):
"""Print methods and doc strings.
@@ -256,7 +257,7 @@ def loadRepos(repolist):
'''
packages = {}
for repo in repolist:
- url = urlparse.urljoin(repo, './repodata/repomd.xml')
+ url = urljoin(repo, './repodata/repomd.xml')
if options.verbose:
print("Loading repo metadata : %s" % url)
@@ -280,7 +281,7 @@ def loadRepos(repolist):
if property.tag.endswith('location'):
primaryhref = property.get('href')
- url = urlparse.urljoin(repo, './' + primaryhref)
+ url = urljoin(repo, './' + primaryhref)
if options.verbose:
print("Loading : %s" % url)
diff --git a/tools/pkgmgr_update.py b/tools/pkgmgr_update.py
index 319016599..49514bd11 100755
--- a/tools/pkgmgr_update.py
+++ b/tools/pkgmgr_update.py
@@ -20,8 +20,9 @@ import optparse
import os
import rpm
import sys
-import urlparse
-import urllib
+
+# Compatibility imports
+from py3kcompat import urljoin
try:
from lxml.etree import parse, tostring
@@ -197,7 +198,7 @@ def loadRepos(repolist):
"""
packages = {}
for repo in repolist:
- url = urlparse.urljoin(repo, './repodata/repomd.xml')
+ url = urljoin(repo, './repodata/repomd.xml')
try:
opener = pkgmgr_URLopener()
@@ -218,7 +219,7 @@ def loadRepos(repolist):
if property.tag.endswith('location'):
primaryhref = property.attrib['href']
- url = urlparse.urljoin(repo, './' + primaryhref)
+ url = urljoin(repo, './' + primaryhref)
if options.verbose:
print("Loading : %s" % url)
diff --git a/tools/py3kcompat.py b/tools/py3kcompat.py
new file mode 100644
index 000000000..b334c4466
--- /dev/null
+++ b/tools/py3kcompat.py
@@ -0,0 +1,24 @@
+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
diff --git a/tools/yum-listpkgs-xml.py b/tools/yum-listpkgs-xml.py
index 60d440ddf..2df5abbcd 100644
--- a/tools/yum-listpkgs-xml.py
+++ b/tools/yum-listpkgs-xml.py
@@ -39,6 +39,6 @@ yummain.cli.output.YumOutput.simpleList = mySimpleList
try:
sys.argv = [sys.argv[0], '-d', '0', 'list']
yummain.main(sys.argv[1:])
-except KeyboardInterrupt, e:
- print >> sys.stderr, "\n\nExiting on user cancel."
+except KeyboardInterrupt:
+ print("\n\nExiting on user cancel.", file=sys.stderr)
sys.exit(1)