当前位置: 首页>>代码示例>>Python>>正文


Python Config.get_db_name方法代码示例

本文整理汇总了Python中config.config.Config.get_db_name方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get_db_name方法的具体用法?Python Config.get_db_name怎么用?Python Config.get_db_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config.config.Config的用法示例。


在下文中一共展示了Config.get_db_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_connection

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_db_name [as 别名]
def get_connection():
  config = Config()
  mysql_config = {
    'user': config.get_db_user(),
    'password': config.get_db_password(),
    'host': config.get_db_host(),
    'database': config.get_db_name()
  }
  return mysql.connector.connect(**mysql_config)
开发者ID:jiangtyd,项目名称:melee_scripts,代码行数:11,代码来源:db.py

示例2: Config

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_db_name [as 别名]
import os
import sys

from bson.objectid import ObjectId
from pymongo import MongoClient

# add root directory to python path
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../../'))

from config.config import Config
import model as M

config = Config()
mongo_client = MongoClient(host=config.get_mongo_url())

DATABASE_NAME = config.get_db_name()

TOURNAMENTS_COLLECTION_NAME = 'tournaments'
PENDING_TOURNAMENTS_COLLECTION_NAME = 'pending_tournaments'
RAW_FILES_COLLECTION_NAME = 'raw_files'

tournaments_col = mongo_client[DATABASE_NAME][TOURNAMENTS_COLLECTION_NAME]
pending_tournaments_col = mongo_client[DATABASE_NAME][PENDING_TOURNAMENTS_COLLECTION_NAME]
raw_files_col = mongo_client[DATABASE_NAME][RAW_FILES_COLLECTION_NAME]

for t in tournaments_col.find():
    if 'raw' in t:
        raw_data = unicode(t['raw'])

        raw_file = {'_id': ObjectId(),
                    'data': raw_data}
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:33,代码来源:remove_raw.py

示例3: validate

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_db_name [as 别名]
def validate(fix=False):
    config = Config()
    mongo_client = MongoClient(host=config.get_mongo_url())
    database_name = config.get_db_name()

    # db collections
    players_col = mongo_client[database_name][M.Player.collection_name]
    tournaments_col = mongo_client[database_name][M.Tournament.collection_name]
    rankings_col = mongo_client[database_name][M.Ranking.collection_name]
    users_col = mongo_client[database_name][M.User.collection_name]
    pending_tournaments_col = mongo_client[database_name][M.PendingTournament.collection_name]
    merges_col = mongo_client[database_name][M.Merge.collection_name]
    sessions_col = mongo_client[database_name][M.Session.collection_name]
    raw_files_col = mongo_client[database_name][M.RawFile.collection_name]
    regions_col = mongo_client[database_name][M.Region.collection_name]

    # get sets of ids for cross-referencing
    player_ids = set([p.get('_id') for p in players_col.find()])
    tournament_ids = set([t.get('_id') for t in tournaments_col.find()])
    ranking_ids = set([r.get('_id') for r in rankings_col.find()])
    user_ids = set([u.get('_id') for u in users_col.find()])
    pending_tournament_ids = set([pt.get('_id') for pt in pending_tournaments_col.find()])
    merge_ids = set([m.get('_id') for m in merges_col.find()])
    raw_file_ids = set([rf.get('_id')
        for rf in raw_files_col.find({}, {'data': 0})])
    region_ids = set([r.get('_id') for r in regions_col.find()])

    # Player checks
    for p in players_col.find():
        player = M.Player.load(p, context='db')
        error_header = '[ERROR player "{}" ({})]'.format(player.id, player.name)
        modified = False

        # check: player valid
        valid, validate_errors = player.validate()
        if not valid:
            print error_header, validate_errors

        # check: player regions are all valid regions
        for r in player.regions:
            if r not in region_ids:
                print error_header, 'invalid region {}'.format(r)
        if fix:
            # fix: remove invalid regions from player regions
            if any([r not in region_ids for r in player.regions]):
                modified = True
                player.regions = [r for r in player.regions if r in region_ids]


        # check: ratings all have valid regions
        for r in player.ratings.keys():
            if r not in region_ids:
                print error_header, 'invalid rating region {}'.format(r)
                if fix:
                    # fix: remove rating from player
                    del player.ratings[r]
                    modified = True

        # check: merge_parent is real player if exists
        if player.merge_parent is not None:
            if player.merge_parent not in player_ids:
                print error_header, 'invalid merge_parent {}'.format(player.merge_parent)
                if fix:
                    # fix: set merge_parent to None, unset merged
                    player.merge_parent = None
                    player.merged = False

        # check: merge_children are real players
        for mc in player.merge_children:
            if mc not in player_ids:
                print error_header, 'invalid merge_child {}'.format(mc)
        if fix:
            # fix: remove child from merge_children
            if any([mc not in player_ids for mc in player.merge_children]):
                modified = True
                player.merge_children = [mc for mc in player.merge_children if mc in player_ids]

        if fix and modified:
            print error_header, 'fixing player..'
            players_col.update({'_id': player.id}, player.dump(context='db'))


    # Tournament checks
    for t in tournaments_col.find():
        tournament = M.Tournament.load(t, context='db')
        error_header = '[ERROR tournament "{}" ({})]'.format(tournament.id, tournament.name)
        modified = False

        # check: tournament valid
        valid, validate_errors = tournament.validate()
        if not valid:
            print error_header, validate_errors
            if fix:
                # fix: set players equal to set of players in matches
                modified = True
                tournament.players = list({match.winner for match in tournament.matches} | \
                              {match.loser for match in tournament.matches})
                tournament.orig_ids = list(tournament.players)

        # check: tournament empty
#.........这里部分代码省略.........
开发者ID:garsh0p,项目名称:garpr,代码行数:103,代码来源:validate_db.py


注:本文中的config.config.Config.get_db_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。