diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/base/data_set.py | 10 | ||||
-rw-r--r-- | wqflask/utility/logger.py | 24 | ||||
-rw-r--r-- | wqflask/utility/tools.py | 13 |
3 files changed, 31 insertions, 16 deletions
diff --git a/wqflask/base/data_set.py b/wqflask/base/data_set.py index ffc5917a..c70738f7 100644 --- a/wqflask/base/data_set.py +++ b/wqflask/base/data_set.py @@ -711,12 +711,14 @@ class PhenotypeDataSet(DataSet): this_trait.LRS_location_value = 1000000 if this_trait.lrs: - result = g.db.execute(""" + query = """ select Geno.Chr, Geno.Mb from Geno, Species where Species.Name = %s and Geno.Name = %s and Geno.SpeciesId = Species.Id - """, (species, this_trait.locus)).fetchone() + """ % (species, this_trait.locus) + logger.sql(query) + result = g.db.execute(query).fetchone() if result: if result[0] and result[1]: @@ -1172,9 +1174,9 @@ def geno_mrna_confidentiality(ob): #logger.debug("dataset_table [%s]: %s" % (type(dataset_table), dataset_table)) query = '''SELECT Id, Name, FullName, confidentiality, - AuthorisedUsers FROM %s WHERE Name = %%s''' % (dataset_table) + AuthorisedUsers FROM %s WHERE Name = "%s"''' % (dataset_table,ob.name) logger.sql(query) - result = g.db.execute(query, ob.name) + result = g.db.execute(query) (dataset_id, name, diff --git a/wqflask/utility/logger.py b/wqflask/utility/logger.py index c62ea2fe..86ee1c52 100644 --- a/wqflask/utility/logger.py +++ b/wqflask/utility/logger.py @@ -32,7 +32,7 @@ from inspect import isfunction from pprint import pformat as pf from inspect import stack -from utility.tools import LOG_LEVEL, LOG_SQL, LOG_FORMAT +from utility.tools import LOG_LEVEL, LOG_LEVEL_DEBUG, LOG_SQL, LOG_FORMAT class GNLogger: """A logger class with some additional functionality, such as @@ -48,9 +48,13 @@ class GNLogger: """Set the undelying log level""" self.logger.setLevel(value) - def debug(self,*args): - """Call logging.debug for multiple args""" - self.collect(self.logger.debug,*args) + def debug(self,level=0,*args): + """Call logging.debug for multiple args. Use level=num to filter on +LOG_LEVEL_DEBUG. + + """ + if level <= LOG_LEVEL_DEBUG: + self.collect(self.logger.debug,*args) def info(self,*args): """Call logging.info for multiple args""" @@ -71,16 +75,20 @@ class GNLogger: if self.logger.getEffectiveLevel() < 30: self.collectf(self.logger.debug,*args) - def debugf(self,*args): + def debugf(self,level=0,*args): """Call logging.debug for multiple args lazily""" # only evaluate function when logging - if self.logger.getEffectiveLevel() < 20: - self.collectf(self.logger.debug,*args) + if level <= LOG_LEVEL_DEBUG: + if self.logger.getEffectiveLevel() < 20: + self.collectf(self.logger.debug,*args) def sql(self, sqlcommand, fun = None): """Log SQL command, optionally invoking a timed fun""" if LOG_SQL: - self.info(stack()[1][3],sqlcommand) + caller = stack()[1][3] + if caller in ['fetchone','fetch1','fetchall']: + caller = stack()[2][3] + self.info(caller,sqlcommand) if fun: result = fun(sqlcommand) if LOG_SQL: diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py index 93b1fa51..bb8241f5 100644 --- a/wqflask/utility/tools.py +++ b/wqflask/utility/tools.py @@ -43,12 +43,13 @@ def get_setting(command_id,guess=None): # ---- Check whether environment exists logger.debug("Looking for "+command_id+"\n") command = value(os.environ.get(command_id)) - if command == None or command == "": + if command is None or command == "": # ---- Check whether setting exists in app command = value(app.config.get(command_id)) - if command == None: + if command is None: command = value(guess) - if command == None or command == "": + if command is None or command == "": + print command raise Exception(command_id+' setting unknown or faulty (update default_settings.py?).') logger.debug("Set "+command_id+"="+str(command)) return command @@ -61,7 +62,11 @@ def get_setting_bool(id): def get_setting_int(id): v = get_setting(id) - return int(v) + if isinstance(v, str): + return int(v) + if v is None: + return 0 + return v def valid_bin(bin): if os.path.islink(bin) or valid_file(bin): |