summaryrefslogtreecommitdiff
path: root/jfr_playoff
diff options
context:
space:
mode:
Diffstat (limited to 'jfr_playoff')
-rw-r--r--jfr_playoff/data.py1
-rw-r--r--jfr_playoff/db.py28
-rw-r--r--jfr_playoff/matchinfo.py8
-rw-r--r--jfr_playoff/tournamentinfo.py8
4 files changed, 25 insertions, 20 deletions
diff --git a/jfr_playoff/data.py b/jfr_playoff/data.py
index c588610..a9c3a0c 100644
--- a/jfr_playoff/data.py
+++ b/jfr_playoff/data.py
@@ -1,4 +1,3 @@
-import mysql
from cached_property import cached_property
from jfr_playoff.db import PlayoffDB
diff --git a/jfr_playoff/db.py b/jfr_playoff/db.py
index 6825fd2..b7c3726 100644
--- a/jfr_playoff/db.py
+++ b/jfr_playoff/db.py
@@ -1,8 +1,5 @@
import sys
-import mysql.connector
-
-
class PlayoffDB(object):
db_cursor = None
@@ -11,6 +8,7 @@ class PlayoffDB(object):
def __init__(self, settings):
reload(sys)
sys.setdefaultencoding("latin1")
+ import mysql.connector
self.database = mysql.connector.connect(
user=settings['user'],
password=settings['pass'],
@@ -25,11 +23,23 @@ class PlayoffDB(object):
self.db_cursor.execute(sql.replace('#db#', db_name), params)
def fetch(self, db_name, sql, params):
- self.__execute_query(db_name, sql, params)
- row = self.db_cursor.fetchone()
- return row
+ import mysql.connector
+ try:
+ self.__execute_query(db_name, sql, params)
+ row = self.db_cursor.fetchone()
+ return row
+ except mysql.connector.Error as e:
+ raise IOError(
+ message=str(e), filename=db_name,
+ errno=e.errno, strerror=str(e))
def fetch_all(self, db_name, sql, params):
- self.__execute_query(db_name, sql, params)
- results = self.db_cursor.fetchall()
- return results
+ import mysql.connector
+ try:
+ self.__execute_query(db_name, sql, params)
+ results = self.db_cursor.fetchall()
+ return results
+ except mysql.connector.Error as e:
+ raise IOError(
+ message=str(e), filename=db_name,
+ errno=e.errno, strerror=str(e))
diff --git a/jfr_playoff/matchinfo.py b/jfr_playoff/matchinfo.py
index 538c67d..f65c23c 100644
--- a/jfr_playoff/matchinfo.py
+++ b/jfr_playoff/matchinfo.py
@@ -1,8 +1,6 @@
import re
from urlparse import urljoin
-import mysql
-
import jfr_playoff.sql as p_sql
from jfr_playoff.dto import Match, Team
from jfr_playoff.remote import RemoteUrl as p_remote
@@ -153,7 +151,7 @@ class MatchInfo:
raise KeyError('database not configured')
self.info.teams = self.__get_db_teams(
self.info.teams, not scores_fetched)
- except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ except (IOError, TypeError, IndexError, KeyError):
self.info.teams = self.__get_html_teams(
self.info.teams, not scores_fetched)
except (TypeError, IndexError, KeyError, IOError, ValueError):
@@ -242,7 +240,7 @@ class MatchInfo:
if self.database is None:
raise KeyError('database not configured')
boards_played, boards_to_play = self.__get_db_board_count()
- except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ except (IOError, TypeError, IndexError, KeyError):
try:
boards_played, boards_to_play = self.__get_html_board_count()
except (TypeError, IndexError, KeyError, IOError, ValueError):
@@ -287,7 +285,7 @@ class MatchInfo:
raise KeyError('database not configured')
self.info.link = self.__get_db_running_link(
link_match.group(1), link_match.group(2))
- except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ except (IOError, TypeError, IndexError, KeyError):
try:
self.info.link = self.__get_html_running_link()
except (TypeError, IndexError, KeyError, IOError, ValueError):
diff --git a/jfr_playoff/tournamentinfo.py b/jfr_playoff/tournamentinfo.py
index 90637bc..ee96214 100644
--- a/jfr_playoff/tournamentinfo.py
+++ b/jfr_playoff/tournamentinfo.py
@@ -1,8 +1,6 @@
from math import ceil
import re
-import mysql
-
import jfr_playoff.sql as p_sql
from jfr_playoff.remote import RemoteUrl as p_remote
@@ -118,7 +116,7 @@ class TournamentInfo:
teams = []
try:
teams = self.__get_db_results()
- except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ except (IOError, TypeError, IndexError, KeyError):
try:
teams = self.__get_html_results()
except (TypeError, IndexError, KeyError, IOError, ValueError):
@@ -132,7 +130,7 @@ class TournamentInfo:
def is_finished(self):
try:
return self.__get_db_finished()
- except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ except (IOError, TypeError, IndexError, KeyError):
try:
return self.__get_html_finished()
except (TypeError, IndexError, KeyError, IOError, ValueError):
@@ -142,7 +140,7 @@ class TournamentInfo:
def get_results_link(self, suffix='leaderb.html'):
try:
return self.__get_db_link(suffix)
- except (mysql.connector.Error, TypeError, IndexError, KeyError):
+ except (IOError, TypeError, IndexError, KeyError):
try:
return self.__get_html_link(suffix)
except (KeyError, ValueError):