コード例 #1
0
def get_wow_object(obj_id, is_id=False, is_item=False,
                   language=DEFAULT_LANG, src=SOURCE_DATASTORE,
                   cache={}, failover=False):
    ''' Interface into fetching wow object (item/spell) data.
    Uses memcachd and an optional local cache to keep down overhead. '''
    obj = None
    cachekey = _gen_cache_key(obj_id, is_item)

    # First check the cache
    if cache and cachekey in cache and cache[cachekey]:
        return cache[cachekey]

    # Next check memcache (non-test only)
    if src != SOURCE_TEST:
        obj = memcache.get(cachekey)
        if obj is not None:
            if obj == MEMCACHED_NOT_FOUND: return None
            return obj

    # Skip a lot of work if we're in test mode.
    if src == SOURCE_TEST:
        obj = get_test_object(obj_id, is_item)

    # if datastore is specified
    if src == SOURCE_DATASTORE:
        obj = get_datastore_object(obj_id, is_item)

    # if mmo-champion is specificied, or if fallback is allowed
    # and the datastore missed.
    if src == SOURCE_MMOCHAMPION or (not obj and failover):
        obj = get_mmochamp_object(obj_id, is_item)

    # Even on miss, update memcache to prevent repeat misses
    if src != SOURCE_TEST:
        # Update memcached
        if not obj:
            memcache.add(cachekey, MEMCACHED_NOT_FOUND, MEMCACHED_PARAM_MISS)
        else:
            memcache.add(cachekey, obj, MEMCACHED_PARAM_INFO)

    # Update local per-command cache before return
    cache[cachekey] = obj
    return obj
コード例 #2
0
    def get_spell(self, spell_id):
        spell = get_mmochamp_object(spell_id, is_item=False,
                                    language=self.language)
        if not spell or not spell.found():
            raise Exception("Spell not found!")
        
        data = {'spell_id': spell_id,
                'name':     spell.get_name(),
                'rank':     spell.get_rank(),
                'gcd':      spell.trips_gcd(),
                'self':     spell.self_only()}
        if not data['rank']: data['rank'] = ''

        # Only return if data is valid.
        if "name" in data               and \
               data["name"] is not None    and \
               "TEST" not in data["name"]  and \
               "OLD" not in data["name"]   and \
               "Alex" not in data["name"]:
            return data
        raise Exception("Not a useful spell.")
        return data
コード例 #3
0
    def get_item(self, item_id):
        item = get_mmochamp_object(item_id, is_item=True,
                                    language=self.language)
        if not item or not item.found():
            raise Exception("Spell not found!")
        
        data = {'item_id':  item_id,
                'name':     item.get_name(),
                'slot':     item.get_slot(),
                }

        # Look up if using this item triggers the GCD.
        data["gcd"] = False
        if data["name"] in GCD_ITEMS: data["gcd"] = GCD_ITEMS[data["name"]]
        # Only return if data is valid.
        if "name" in data                  and \
               data["name"] != ""          and \
               data["name"] is not None    and \
               "TEST" not in data["name"]  and \
               "OLD" not in data["name"]   and \
               "Alex" not in data["name"]:
            return data
        raise Exception("Not a useful .")
        return data