Exemple #1
0
 def __init__(self, db_file):
     self._log = util.get_syslog_logger("db")
     if os.path.isfile(db_file):
         self._log.info("found database file {}".format(db_file))
         new_db = False
     else:
         self._log.info("database file not found, creating {}".format(db_file))
         new_db = True
     self._conn = sqlite3.connect(db_file)
     self._cursor = self._conn.cursor()
     self._cursor.execute('PRAGMA foreign_keys = ON;')
     self._conn.commit()
     if new_db:
         db_version = 0
     else:
         db_version = self.get_db_version()
     self._log.info("DB version is {}".format(db_version))
     v = db_version
     for t in _schema[db_version:]:
         v = v + 1
         self._log.debug("upgrading schema to version {}".format(v))
         for q in t:
             self._log.info("  {}".format(q))
             self._cursor.execute(q)
     self._conn.commit()
     db_version = self.get_db_version()
     assert db_version == v
     self._common_player_fields = ( 'username', 'first_name', 'last_name', 'email', 'home_phone', 'work_phone', 'cell_phone', 'company', 'ladder', 'active', 'initial_points', 'location', 'wlocation', 'note', 'tournament_qualified_override', 'a_promotion', 'b_promotion', 'c_promotion' )
     self._translated_player_fields = { 'player_id' : 'id' }
     self._common_account_fields = ( 'username', )
     self._translated_account_fields = { 'account_id' : 'id' }
     self._common_match_fields = ('challenger_id', 'opponent_id', 'winner_id', 'cpoints', 'opoints', 'cgames', 'ogames', 'date', 'retired', 'forfeited', 'season_id')
     self._translated_match_fields = { }
     self._special_match_fields = {'since': {'field': 'date', 'operator': '>='}}
     self._ladder_weights = {'a': 3, 'b': 2, 'c':1, 'unranked':0}
Exemple #2
0
Fichier : db.py Projet : ajdlvw/jim
 def __init__(self, db_file):
     self._log = util.get_syslog_logger("db")
     if os.path.isfile(db_file):
         self._log.info("found database file {}".format(db_file))
         new_db = False
     else:
         self._log.info("database file not found, creating {}".format(db_file))
         new_db = True
     self._conn = sqlite3.connect(db_file)
     self._cursor = self._conn.cursor()
     self._cursor.execute('PRAGMA foreign_keys = ON;')
     self._conn.commit()
     if new_db:
         db_version = 0
     else:
         db_version = self.get_db_version()
     self._log.info("DB version is {}".format(db_version))
     v = db_version
     for t in _schema[db_version:]:
         v = v + 1
         self._log.debug("upgrading schema to version {}".format(v))
         for q in t:
             self._log.info("  {}".format(q))
             self._cursor.execute(q)
     # hacky fixer:
     #  BOOLEAN NOT NULL DEFAULT FALSE fields won't match
     #  boolean types when queried from Python SQLITE3 API
     #  when the field is not explicitly set (probably a bug)
     #  In other words, default value does not behave consistently
     #  when used with Python SQLITE 3 API
     #  This quirk will fix the problem by writing back
     #  the boolean False wherever we see the string-FALSE (which
     #  comes from default field)
     self._log.debug("running hacky database fixer for default boolean fields")
     self._cursor.execute("UPDATE matches SET tournament=? where tournament='FALSE'", (False,))
     self._cursor.execute("UPDATE matches SET disputed=? where disputed='FALSE'", (False,))
     self._cursor.execute("UPDATE matches SET pending=? where pending='FALSE'", (False,))
     self._cursor.execute("UPDATE seasons SET kicked=? where kicked='TRUE'", (True,))
     self._conn.commit()
     db_version = self.get_db_version()
     assert db_version == v
     self._common_player_fields = ( 'username', 'first_name', 'last_name', 'email', 'home_phone', 'work_phone', 'cell_phone', 'company', 'ladder', 'active', 'initial_points', 'location', 'wlocation', 'note', 'tournament_qualified_override', 'a_promotion', 'b_promotion', 'c_promotion' )
     self._translated_player_fields = { 'player_id' : 'id' }
     self._common_account_fields = ( 'username', )
     self._translated_account_fields = { 'account_id' : 'id' }
     self._common_match_fields = ('ladder', 'challenger_id', 'opponent_id', 'winner_id', 'cpoints', 'opoints', 'cgames', 'ogames', 'date', 'retired', 'forfeited', 'season_id', 'disputed', 'pending', 'tournament')
     self._translated_match_fields = { 'match_id' : 'id' }
     self._special_match_fields = {'since': {'field': 'date', 'operator': '>='}}
     self._ladder_weights = {'a': 3, 'b': 2, 'c':1, 'unranked':0}
Exemple #3
0
def do_main():
    global _log
    logging.basicConfig(level=logging.DEBUG)
    _log = util.get_syslog_logger("main")
    rules.init()
    config_file_list = [ os.path.dirname(os.path.realpath(__file__)) + '/jim.cfg', '/etc/jim.cfg', './jim.cfg' ]
    config_file_parser = ConfigParser.RawConfigParser()
    config_ok = True
    try:
        config_file_list = config_file_parser.read(config_file_list)
    except:
        _log.error("cannot parse configuration file(s)")
        config_ok = False
    if len(config_file_list) == 0:
        _log.error("no configuration file found")
        config_ok = False
    else:
        _log.info("using configuration files {}".format(config_file_list))
    if config_ok:
        cfg = read_config(config_file_parser)
        _log.info("server configuration: {}".format(cfg))
        _log.info("starting server")
        db_file = cfg.get('db_file')
        if db_file:
            database = db.Database(db_file)
        else:
            database = None
        news = cfg.get('news_file') 
        certs_path = cfg.get('certs_path')
        if certs_path:
            ssl_options = { 'certfile' : certs_path + '/cert.pem',
                            'keyfile': certs_path + '/key.pem' }
        else:
            ssl_options = util.test_ssl_options
        web.run_server(ssl_options = ssl_options, http_port = cfg.get('http_port'), https_port = cfg.get('https_port'), bounce_port = cfg.get('bounce_port'), html_root = cfg.get('html_root'), template_root = cfg.get('template_root'), database = database, news = news, bootstrap_token = cfg.get('bootstrap_token'), player_reports_matches = cfg.get('player_reports_matches'), autoreload = cfg.get('autoreload'))
        _log.info("server exited")
    else:
        _log.error("configuration error")
Exemple #4
0
def init():
    global _log
    _log = util.get_syslog_logger("rules")