From d4248706e46ba65d5b2a05e2ac1a16421bfd1e32 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Mon, 1 Feb 2010 22:31:00 +0000 Subject: [PATCH] remove surplus get_logger calls, tidy up log messages some more --- pyfpdb/Database.py | 12 ++++++------ pyfpdb/HUD_main.py | 15 +++++++-------- pyfpdb/Hand.py | 9 ++++++--- pyfpdb/HandHistoryConverter.py | 8 ++++++-- pyfpdb/fpdb.py | 3 +++ pyfpdb/fpdb_import.py | 2 +- 6 files changed, 29 insertions(+), 20 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index e7c01231..77ae30f6 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -227,7 +227,7 @@ class Database: def __init__(self, c, sql = None): - log = Configuration.get_logger("logging.conf", "db", log_dir=c.dir_log) + #log = Configuration.get_logger("logging.conf", "db", log_dir=c.dir_log) log.debug("Creating Database instance, sql = %s" % sql) self.config = c self.__connected = False @@ -239,6 +239,7 @@ class Database: self.db_server = db_params['db-server'] self.database = db_params['db-databaseName'] self.host = db_params['db-host'] + self.db_path = '' # where possible avoid creating new SQL instance by using the global one passed in if sql is None: @@ -388,9 +389,9 @@ class Database: log.info("Creating directory: '%s'" % (self.config.dir_database)) os.mkdir(self.config.dir_database) database = os.path.join(self.config.dir_database, database) - log.info("Connecting to SQLite: %(database)s" % {'database':database}) - print "Connecting to SQLite: %(database)s" % {'database':database} - self.connection = sqlite3.connect(database, detect_types=sqlite3.PARSE_DECLTYPES ) + self.db_path = database + log.info("Connecting to SQLite: %(database)s" % {'database':self.db_path}) + self.connection = sqlite3.connect(self.db_path, detect_types=sqlite3.PARSE_DECLTYPES ) sqlite3.register_converter("bool", lambda x: bool(int(x))) sqlite3.register_adapter(bool, lambda x: "1" if x else "0") self.connection.create_function("floor", 1, math.floor) @@ -791,11 +792,10 @@ class Database: def get_player_id(self, config, site, player_name): c = self.connection.cursor() - print "get_player_id: player_name =", player_name, type(player_name) + #print "get_player_id: player_name =", player_name, type(player_name) p_name = Charset.to_utf8(player_name) c.execute(self.sql.query['get_player_id'], (p_name, site)) row = c.fetchone() - print "player id =", row if row: return row[0] else: diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index c792d802..f7979552 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -51,9 +51,6 @@ import gobject # FreePokerTools modules import Configuration -log = Configuration.get_logger("logging.conf", config = 'hud') -log.debug("%s logger initialized." % "hud") - import Database from HandHistoryConverter import getTableTitleRe @@ -66,6 +63,10 @@ elif os.name == 'nt': import Hud +# logger is set up in __init__, create temp logger here +log = Configuration.get_logger("logging.conf", config = 'hud') + + class HUD_main(object): """A main() object to own both the read_stdin thread and the gui.""" # This class mainly provides state for controlling the multiple HUDs. @@ -74,9 +75,10 @@ class HUD_main(object): try: print "HUD_main: starting ..." self.db_name = db_name - self.config = Configuration.Config(file=options.config, dbname=options.dbname) + self.config = Configuration.Config(file=options.config, dbname=db_name) log = Configuration.get_logger("logging.conf", "hud", log_dir=self.config.dir_log) - log.debug("starting ...") + log.info("HUD_main starting") + log.info("Using db name = %s" % (db_name)) self.hud_dict = {} self.hud_params = self.config.get_hud_ui_parameters() @@ -295,9 +297,6 @@ class HUD_main(object): if __name__== "__main__": - log.info("HUD_main starting") - log.info("Using db name = %s" % (options.dbname)) - # start the HUD_main object hm = HUD_main(db_name = options.dbname) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 0f69121a..9bec209b 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -21,7 +21,6 @@ import re import sys import traceback -import logging import os import os.path from decimal import Decimal @@ -30,12 +29,16 @@ import time,datetime from copy import deepcopy import pprint +import logging +# logging has been set up in fpdb.py or HUD_main.py, use their settings: +log = logging.getLogger("parser") + + import Configuration from Exceptions import * import DerivedStats import Card -log = Configuration.get_logger("logging.conf", "parser") class Hand(object): @@ -50,7 +53,7 @@ class Hand(object): def __init__(self, config, sitename, gametype, handText, builtFrom = "HHC"): self.config = config - log = Configuration.get_logger("logging.conf", "db", log_dir=self.config.dir_log) + #log = Configuration.get_logger("logging.conf", "db", log_dir=self.config.dir_log) self.sitename = sitename self.siteId = self.SITEIDS[sitename] self.stats = DerivedStats.DerivedStats(self) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 45760ee6..fa1805e0 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -30,6 +30,11 @@ from xml.dom.minidom import Node import time import datetime +import logging +# logging has been set up in fpdb.py or HUD_main.py, use their settings: +log = logging.getLogger("parser") + + import Hand import Tourney from Exceptions import FpdbParseError @@ -38,7 +43,6 @@ import Configuration import gettext gettext.install('fpdb') -log = Configuration.get_logger("logging.conf", "parser") import pygtk import gtk @@ -65,7 +69,7 @@ out_path (default '-' = sys.stdout) follow : whether to tail -f the input""" self.config = config - log = Configuration.get_logger("logging.conf", "parser", log_dir=self.config.dir_log) + #log = Configuration.get_logger("logging.conf", "parser", log_dir=self.config.dir_log) log.info("HandHistory init - %s subclass, in_path '%s'; out_path '%s'" % (self.sitename, in_path, out_path) ) self.index = index diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index c11301a9..5bef3503 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -721,6 +721,9 @@ class fpdb: err_msg = None try: self.db = Database.Database(self.config, sql = self.sql) + if self.db.get_backend_name() == 'SQLite': + # tell sqlite users where the db file is + print "Connected to SQLite: %(database)s" % {'database':self.db.db_path} except Exceptions.FpdbMySQLAccessDenied: err_msg = "MySQL Server reports: Access denied. Are your permissions set correctly?" except Exceptions.FpdbMySQLNoDatabase: diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 8ba0da34..8b3f71cd 100755 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -68,7 +68,7 @@ class Importer: self.config = config self.sql = sql - log = Configuration.get_logger("logging.conf", "importer", log_dir=self.config.dir_log) + #log = Configuration.get_logger("logging.conf", "importer", log_dir=self.config.dir_log) self.filelist = {} self.dirlist = {} self.siteIds = {}