diff --git a/requirements.txt b/requirements.txt index a29127f9..f3b58350 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ flask sqlalchemy +six fedmsg modulemd pyOpenSSL diff --git a/rida/config.py b/rida/config.py index 53ffcecc..d717ff36 100644 --- a/rida/config.py +++ b/rida/config.py @@ -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") diff --git a/rida/scm.py b/rida/scm.py index cc40c76d..6100a2e1 100644 --- a/rida/scm.py +++ b/rida/scm.py @@ -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