gracefully handle missing config option

This commit is contained in:
Lucas Bickel 2017-10-15 14:45:22 +02:00
parent ace7e493f4
commit bf5cfbcf56
1 changed files with 9 additions and 6 deletions

View File

@ -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],