[Blends-commit] [SCM] website branch, master, updated. d2dbc2cbba010c14db1a2af1c3ca8b8ba49eff72
Ole Streicher
ole at aip.de
Fri Apr 29 14:27:03 UTC 2016
The following commit has been merged in the master branch:
commit c56d55bcadd318bb4840ad1fca8c5baae4b5c055
Author: Ole Streicher <ole at aip.de>
Date: Fri Apr 29 15:04:05 2016 +0200
Use list of connection parameters instead of stacked try/catches
Also, include the public UDD mirror as last possibility
diff --git a/webtools/blendstasktools.py b/webtools/blendstasktools.py
index d344642..0c533f9 100644
--- a/webtools/blendstasktools.py
+++ b/webtools/blendstasktools.py
@@ -268,29 +268,33 @@ def GetDependencies2Use(dependencystatus=[], max_order='prospective'):
logger.error("No valid dependencystatus in", dependencystatus)
return use_dependencystatus
-###########################################################################################
-# Define several prepared statements to query UDD
-try:
- conn = psycopg2.connect(host="localhost", port=PORT, user="guest",
- database="udd")
-except psycopg2.OperationalError as err:
+###############################################################################
+connection_pars = [
+ {'host': 'localhost', 'port': PORT, 'user': 'guest', 'database': 'udd'},
+ {'service': 'udd'},
+ {'host': 'localhost', 'port': DEFAULTPORT, 'user': 'guest', 'database': 'udd'},
+
+ # Hmmm, I observed a really strange behaviour on one of my machines where
+ # connecting to localhost does not work but 127.0.0.1 works fine. No idea
+ # why ... but this should do the trick for the moment
+ {'host': '127.0.0.1', 'port': DEFAULTPORT, 'user': 'guest', 'database': 'udd'},
+
+ # Public UDD mirror as last resort
+ {'host': 'public-udd-mirror.xvm.mit.edu', 'port': 5432,
+ 'user': 'public-udd-mirror', 'password': 'public-udd-mirror', 'database': 'udd'},
+]
+conn = None
+for par in connection_pars:
try:
- conn = psycopg2.connect("service=udd")
+ conn = psycopg2.connect(**par)
+ break
except psycopg2.OperationalError as err:
- # logger not known at this state: logger.warning
- stderr.write("Service=udd seems not to be installed on this host.\tMessage: %s\n" % (str(err)))
- try:
- conn = psycopg2.connect(host="localhost", port=DEFAULTPORT,
- user="guest", database="udd")
- except psycopg2.OperationalError:
- # Hmmm, I observed a really strange behaviour on one of my
- # machines where connecting to localhost does not work but
- # 127.0.0.1 works fine. No idea why ... but this should
- # do the trick for the moment
- conn = psycopg2.connect(host="127.0.0.1", port=DEFAULTPORT,
- user="guest", database="udd")
-conn.set_client_encoding('utf-8')
+ continue
+if conn is None:
+ raise err
+
+conn.set_client_encoding('utf-8')
curs = conn.cursor()
# uddlog = open('logs/uddquery.log', 'w')
@@ -305,6 +309,7 @@ def _execute_udd_query(query):
except psycopg2.DataError as err:
stderr.write("%s; query was\n%s\n" % (str(err), query))
+# Define several prepared statements to query UDD
query = """PREPARE query_pkgs (text[],text[],text) AS
SELECT * FROM blends_query_packages($1,$2,$3) AS (
package text, distribution text, release text, component text, version debversion,
diff --git a/webtools/blendstasktools_udd.py b/webtools/blendstasktools_udd.py
index 36b9e6e..5558f69 100644
--- a/webtools/blendstasktools_udd.py
+++ b/webtools/blendstasktools_udd.py
@@ -264,24 +264,31 @@ def GetDependencies2Use(dependencystatus=[], max_order='prospective'):
logger.error("No valid dependencystatus in", dependencystatus)
return use_dependencystatus
-###########################################################################################
-# Define several prepared statements to query UDD
-try:
- conn = psycopg2.connect(host="localhost",port=PORT,user="guest",database="udd")
-except psycopg2.OperationalError as err:
- try:
- conn = psycopg2.connect("service=udd")
- except psycopg2.OperationalError as err:
- # logger not known at this state: logger.warning
- stderr.write("Service=udd seems not to be installed on this host.\tMessage: %s" % (str(err)))
+###############################################################################
+connection_pars = [
+ {'host': 'localhost', 'port': PORT, 'user': 'guest', 'database': 'udd'},
+ {'service': 'udd'},
+ {'host': 'localhost', 'port': DEFAULTPORT, 'user': 'guest', 'database': 'udd'},
+
+ # Hmmm, I observed a really strange behaviour on one of my machines where
+ # connecting to localhost does not work but 127.0.0.1 works fine. No idea
+ # why ... but this should do the trick for the moment
+ {'host': '127.0.0.1', 'port': DEFAULTPORT, 'user': 'guest', 'database': 'udd'},
+
+ # Public UDD mirror as last resort
+ {'host': 'public-udd-mirror.xvm.mit.edu', 'port': 5432,
+ 'user': 'public-udd-mirror', 'password': 'public-udd-mirror', 'database': 'udd'},
+]
+conn = None
+for par in connection_pars:
try:
- conn = psycopg2.connect(host="localhost",port=DEFAULTPORT,user="guest",database="udd")
- except psycopg2.OperationalError:
- # Hmmm, I observed a really strange behaviour on one of my machines where connecting to
- # localhost does not work but 127.0.0.1 works fine. No idea why ... but this should
- # do the trick for the moment
- conn = psycopg2.connect(host="127.0.0.1",port=DEFAULTPORT,user="guest",database="udd")
-
+ conn = psycopg2.connect(**par)
+ break
+ except psycopg2.OperationalError as err:
+ continue
+
+if conn is None:
+ raise err
conn.set_client_encoding('utf-8')
curs = conn.cursor()
# uddlog = open('logs/uddquery.log', 'w')
--
Static and dynamic websites for Debian Pure Blends
More information about the Blends-commit
mailing list