Add error handler for http connection

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
Hiroshi Miura
2019-03-15 08:29:12 +09:00
parent 4c1bde3d7a
commit 4f830a92bb
3 changed files with 66 additions and 41 deletions

View File

@@ -20,8 +20,11 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import xml.etree.ElementTree as ElementTree
import logging
import requests
import traceback
import xml.etree.ElementTree as ElementTree
from six import StringIO
class QtPackage:
@@ -65,7 +68,15 @@ class QtArchives:
# Get packages index
update_xml_url = "{0}Updates.xml".format(archive_url)
try:
r = requests.get(update_xml_url)
except requests.exceptions.ConnectionError as e:
print("Caught download error: %s" % e.args)
exc_buffer = StringIO()
traceback.print_exc(file=exc_buffer)
logging.error('Download error:\n%s', exc_buffer.getvalue())
raise e
else:
self.update_xml = ElementTree.fromstring(r.text)
for packageupdate in self.update_xml.iter("PackageUpdate"):
name = packageupdate.find("Name").text

View File

@@ -20,17 +20,19 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import logging
import os
import platform
import sys
from multiprocessing.dummy import Pool
import traceback
import requests
from six import StringIO
from multiprocessing.dummy import Pool
if sys.version_info.major == 3:
from subprocess import run
else:
from subprocess import call as run
NUM_PROCESS = 3
@@ -44,7 +46,15 @@ class QtInstaller:
url = package.get_url()
sys.stdout.write("\033[K")
print("-Downloading {}...".format(url))
try:
r = requests.get(url, stream=True)
except requests.exceptions.ConnectionError as e:
print("Caught download error: %s" % e.args)
exc_buffer = StringIO()
traceback.print_exc(file=exc_buffer)
logging.error('Uncaught exception in worker process:\n%s', exc_buffer.getvalue())
raise e
else:
with open(archive, 'wb') as fd:
for chunk in r.iter_content(chunk_size=8196):
fd.write(chunk)
@@ -92,5 +102,9 @@ class QtInstaller:
if 'QT_EDITION' in line:
line = 'QT_EDITION = OpenSource'
f.write(line)
except IOError:
pass
except IOError as e:
print("Configuration file generation error: %s" % e.args)
exc_buffer = StringIO()
traceback.print_exc(file=exc_buffer)
logging.error('Error happened when writing configuration files:\n%s', exc_buffer.getvalue())
raise e

View File

@@ -20,7 +20,7 @@ setup(name='aqtinstall',
author='Hioshi Miura',
author_email='miurahr@linux.com',
packages=["aqt"],
install_requires=['requests'],
install_requires=['requests', 'six'],
extras_require={
'dev': [
'pytest',