From 4287ac1c700b8d3e3a8de40e4ee9a33ea4374d29 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sun, 15 Oct 2017 13:14:40 +0200 Subject: [PATCH 1/3] Revert pypofile try block move Config file getting is allowed to fail. I didn't realize that it would not just use the default instead of excepting and getting caught. Sorry for that. --- python_apps/pypo/pypo/pypofile.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python_apps/pypo/pypo/pypofile.py b/python_apps/pypo/pypo/pypofile.py index 14c8fba9c..4cf78e9f9 100644 --- a/python_apps/pypo/pypo/pypofile.py +++ b/python_apps/pypo/pypo/pypofile.py @@ -61,11 +61,11 @@ class PypoFile(Thread): self.logger.info("copying from %s to local cache %s" % (src, dst)) CONFIG_SECTION = "general" + username = self._config.get(CONFIG_SECTION, 'api_key') + baseurl = self._config.get(CONFIG_SECTION, 'base_url') + port = self._config.get(CONFIG_SECTION, 'base_port', 80) + protocol = self._config.get(CONFIG_SECTION, 'protocol', str(("http", "https")[int(port) == 443])) try: - username = self._config.get(CONFIG_SECTION, 'api_key') - baseurl = self._config.get(CONFIG_SECTION, 'base_url') - port = self._config.get(CONFIG_SECTION, 'base_port', 80) - protocol = self._config.get(CONFIG_SECTION, 'protocol', str(("http", "https")[int(port) == 443])) host = [protocol, baseurl, port] url = "%s://%s:%s/rest/media/%s/download" % (host[0], From ace7e493f4346d5e6c17fc9f4311f88086daf819 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sun, 15 Oct 2017 13:46:40 +0200 Subject: [PATCH 2/3] Fix port and protocol default values Turns our bare ConfigObjects don't to default passing very automatically. --- python_apps/pypo/pypo/pypofile.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python_apps/pypo/pypo/pypofile.py b/python_apps/pypo/pypo/pypofile.py index 4cf78e9f9..d63252041 100644 --- a/python_apps/pypo/pypo/pypofile.py +++ b/python_apps/pypo/pypo/pypofile.py @@ -63,8 +63,12 @@ class PypoFile(Thread): CONFIG_SECTION = "general" username = self._config.get(CONFIG_SECTION, 'api_key') baseurl = self._config.get(CONFIG_SECTION, 'base_url') - port = self._config.get(CONFIG_SECTION, 'base_port', 80) - protocol = self._config.get(CONFIG_SECTION, 'protocol', str(("http", "https")[int(port) == 443])) + port = self._config.get(CONFIG_SECTION, 'base_port') + if not port: + port = 80 + protocol = self._config.get(CONFIG_SECTION, 'protocol') + if not protocol: + protocol = str(("http", "https")[int(port) == 443]) try: host = [protocol, baseurl, port] @@ -162,7 +166,7 @@ class PypoFile(Thread): def read_config_file(self, config_path): """Parse the application's config file located at config_path.""" - config = ConfigParser.SafeConfigParser() + config = ConfigParser.SafeConfigParser(allow_no_value=True) try: config.readfp(open(config_path)) except IOError as e: From bf5cfbcf560d8d6494c8f59b15b9710691f192cd Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sun, 15 Oct 2017 14:45:22 +0200 Subject: [PATCH 3/3] gracefully handle missing config option --- python_apps/pypo/pypo/pypofile.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python_apps/pypo/pypo/pypofile.py b/python_apps/pypo/pypo/pypofile.py index d63252041..edad6ff92 100644 --- a/python_apps/pypo/pypo/pypofile.py +++ b/python_apps/pypo/pypo/pypofile.py @@ -2,6 +2,7 @@ from threading import Thread from Queue import Empty +from ConfigParser import NoOptionError import logging import shutil @@ -63,14 +64,16 @@ class PypoFile(Thread): CONFIG_SECTION = "general" username = self._config.get(CONFIG_SECTION, 'api_key') baseurl = self._config.get(CONFIG_SECTION, 'base_url') - port = self._config.get(CONFIG_SECTION, 'base_port') - if not port: - port = 80 - protocol = self._config.get(CONFIG_SECTION, 'protocol') - if not protocol: - protocol = str(("http", "https")[int(port) == 443]) try: + port = self._config.get(CONFIG_SECTION, 'base_port') + except NoOptionError, e: + port = 80 + try: + protocol = self._config.get(CONFIG_SECTION, 'protocol') + except NoOptionError, e: + protocol = str(("http", "https")[int(port) == 443]) + try: host = [protocol, baseurl, port] url = "%s://%s:%s/rest/media/%s/download" % (host[0], host[1],