Get things working on py2 as well as py3.

This commit is contained in:
Ralph Bean
2016-07-13 11:25:02 -04:00
parent 594555ae7a
commit 80cd8c3fad
3 changed files with 23 additions and 7 deletions

View File

@@ -26,10 +26,24 @@
"""Configuration handler functions."""
import os.path
import configparser
import json
try:
import configparser # py3
except ImportError:
import ConfigParser as configparser # py2
import six
from rida import logger
def asbool(value):
""" Cast config values to boolean. """
return six.text_type(value).lower() in [
'y', 'yes', 't', 'true', '1', 'on'
]
def from_file(filename=None):
"""Create the configuration instance from a file.
@@ -45,7 +59,7 @@ def from_file(filename=None):
raise IOError("The configuration file doesn't exist.")
cp = configparser.ConfigParser(allow_no_value=True)
cp.read(filename)
default = cp["DEFAULT"]
default = cp.defaults()
conf = Config()
conf.db = default.get("db")
conf.system = default.get("system")
@@ -57,9 +71,9 @@ def from_file(filename=None):
conf.koji_profile = default.get("koji_profile")
conf.scmurls = json.loads(default.get("scmurls"))
conf.rpms_default_repository = default.get("rpms_default_repository")
conf.rpms_allow_repository = default.getboolean("rpms_allow_repository")
conf.rpms_allow_repository = asbool(default.get("rpms_allow_repository"))
conf.rpms_default_cache = default.get("rpms_default_cache")
conf.rpms_allow_cache = default.getboolean("rpms_allow_cache")
conf.rpms_allow_cache = asbool(default.get("rpms_allow_cache"))
conf.ssl_certificate_file = default.get("ssl_certificate_file")
conf.ssl_certificate_key_file = default.get("ssl_certificate_key_file")

View File

@@ -27,7 +27,8 @@
"""SCM handler functions."""
import http.client
from six.moves import http_client
import os
import sys
import time
@@ -101,7 +102,7 @@ class SCM(object):
if chdir:
os.chdir(chdir)
os.execvp(path, args)
except: # XXX maybe switch to subprocess (python-3.5) where
except: # XXX maybe switch to subprocess (python-3.5) where
# we can check for return codes and timeouts
msg = ''.join(traceback.format_exception(*sys.exc_info()))
print(msg)
@@ -173,7 +174,7 @@ class SCM(object):
# XXX: If implementing special hacks for pagure.io or github.com, don't
# forget about possible forks -- start with self.repository.
if self.repository.startswith("-git://pkgs.fedoraproject.org/"):
hc = http.client.HTTPConnection("pkgs.fedoraproject.org")
hc = http_client.HTTPConnection("pkgs.fedoraproject.org")
hc.request("HEAD",
"/cgit/rpms/" + self.name + ".git/commit/?id=" + self.commit)
rc = hc.getresponse().code