def getVariations(itemids, groupIDs=None, where=None, eager=None): for itemid in itemids: if not isinstance(itemid, int): raise TypeError("All passed item IDs must be integers") # Get out if list of provided IDs is empty if len(itemids) == 0: return [] itemfilter = or_(*(metatypes_table.c.parentTypeID == itemid for itemid in itemids)) filter = processWhere(itemfilter, where) joinon = items_table.c.typeID == metatypes_table.c.typeID vars = gamedata_session.query(Item).options(*processEager(eager)).join( (metatypes_table, joinon)).filter(filter).all() if vars: return vars elif groupIDs: itemfilter = or_(*(groups_table.c.groupID == groupID for groupID in groupIDs)) filter = processWhere(itemfilter, where) joinon = items_table.c.groupID == groups_table.c.groupID vars = gamedata_session.query(Item).options(*processEager(eager)).join( (groups_table, joinon)).filter(filter).all() return vars
def getMetaGroup(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: metaGroup = gamedata_session.query(MetaGroup).get(lookfor) else: metaGroup = gamedata_session.query(MetaGroup).options( *processEager(eager)).filter(MetaGroup.ID == lookfor).first() elif isinstance(lookfor, str): if lookfor in metaGroupNameMap: id = metaGroupNameMap[lookfor] if eager is None: metaGroup = gamedata_session.query(MetaGroup).get(id) else: metaGroup = gamedata_session.query(MetaGroup).options( *processEager(eager)).filter(MetaGroup.ID == id).first() else: # MetaGroup names are unique, so we can use first() instead of one() metaGroup = gamedata_session.query(MetaGroup).options( *processEager(eager)).filter( MetaGroup.name == lookfor).first() if metaGroup is not None: metaGroupNameMap[lookfor] = metaGroup.ID else: raise TypeError("Need integer or string as argument") return metaGroup
def getUser(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: user = saveddata_session.query(User).get(lookfor) else: eager = processEager(eager) with sd_lock: user = saveddata_session.query(User).options(*eager).filter(User.ID == lookfor).first() elif isinstance(lookfor, str): eager = processEager(eager) with sd_lock: user = saveddata_session.query(User).options(*eager).filter(User.username == lookfor).first() else: raise TypeError("Need integer or string as argument") return user
def countFitsWithShip(lookfor, ownerID=None, where=None, eager=None): """ Get all the fits using a certain ship. If no user is passed, do this for all users. """ if ownerID is not None and not isinstance(ownerID, int): raise TypeError("OwnerID must be integer") if isinstance(lookfor, int): filter = Fit.shipID == lookfor elif isinstance(lookfor, list): if len(lookfor) == 0: return 0 filter = Fit.shipID.in_(lookfor) else: raise TypeError( "You must supply either an integer or ShipID must be integer") if ownerID is not None: filter = and_(filter, Fit.ownerID == ownerID) filter = processWhere(filter, where) eager = processEager(eager) with sd_lock: count = saveddata_session.query(Fit).options( *eager).filter(filter).count() return count
def getCrestCharacter(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: character = saveddata_session.query(CrestChar).get(lookfor) else: eager = processEager(eager) with sd_lock: character = saveddata_session.query(CrestChar).options(*eager).filter(CrestChar.ID == lookfor).first() elif isinstance(lookfor, basestring): eager = processEager(eager) with sd_lock: character = saveddata_session.query(CrestChar).options(*eager).filter(CrestChar.name == lookfor).first() else: raise TypeError("Need integer or string as argument") return character
def countFitsWithShip(lookfor, ownerID=None, where=None, eager=None): """ Get all the fits using a certain ship. If no user is passed, do this for all users. """ if ownerID is not None and not isinstance(ownerID, int): raise TypeError("OwnerID must be integer") if isinstance(lookfor, int): filter = Fit.shipID == lookfor elif isinstance(lookfor, list): if len(lookfor) == 0: return 0 filter = Fit.shipID.in_(lookfor) else: raise TypeError("You must supply either an integer or ShipID must be integer") if ownerID is not None: filter = and_(filter, Fit.ownerID == ownerID) filter = processWhere(filter, where) eager = processEager(eager) with sd_lock: count = saveddata_session.query(Fit).options(*eager).filter(filter).count() return count
def getImplantSet(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: pattern = saveddata_session.query(ImplantSet).get(lookfor) else: eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(ImplantSet).options(*eager).filter(TargetResists.ID == lookfor).first() elif isinstance(lookfor, basestring): eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(ImplantSet).options(*eager).filter(TargetResists.name == lookfor).first() else: raise TypeError("Improper argument") return pattern
def getFitList(eager=None): eager = processEager(eager) with sd_lock: fits = removeInvalid( saveddata_session.query(Fit).options(*eager).all()) return fits
def getDamagePattern(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: pattern = saveddata_session.query(DamagePattern).get(lookfor) else: eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(DamagePattern).options(*eager).filter(DamagePattern.ID == lookfor).first() elif isinstance(lookfor, basestring): eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(DamagePattern).options(*eager).filter(DamagePattern.name == lookfor).first() else: raise TypeError("Need integer or string as argument") return pattern
def getTargetResists(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: pattern = saveddata_session.query(TargetResists).get(lookfor) else: eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(TargetResists).options(*eager).filter(TargetResists.ID == lookfor).first() elif isinstance(lookfor, basestring): eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(TargetResists).options(*eager).filter(TargetResists.name == lookfor).first() else: raise TypeError("Need integer or string as argument") return pattern
def getCharactersForUser(lookfor, eager=None): if isinstance(lookfor, int): eager = processEager(eager) with sd_lock: characters = saveddata_session.query(Character).options(*eager).filter(Character.ownerID == lookfor).all() else: raise TypeError("Need integer as argument") return characters
def getImplantSet(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: pattern = saveddata_session.query(ImplantSet).get(lookfor) else: eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(ImplantSet).options(*eager).filter( TargetProfile.ID == lookfor).first() elif isinstance(lookfor, str): eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(ImplantSet).options(*eager).filter(TargetProfile.name == lookfor).first() else: raise TypeError("Improper argument") return pattern
def getMarketGroup(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: marketGroup = gamedata_session.query(MarketGroup).get(lookfor) else: marketGroup = gamedata_session.query(MarketGroup).options(*processEager(eager)).filter(MarketGroup.ID == lookfor).first() else: raise TypeError("Need integer as argument") return marketGroup
def getAlphaClone(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: item = gamedata_session.query(AlphaClone).get(lookfor) else: item = gamedata_session.query(AlphaClone).options(*processEager(eager)).filter(AlphaClone.ID == lookfor).first() else: raise TypeError("Need integer as argument") return item
def getDamagePattern(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: pattern = saveddata_session.query(DamagePattern).get(lookfor) else: eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(DamagePattern).options( *eager).filter(DamagePattern.ID == lookfor).first() elif isinstance(lookfor, str): eager = processEager(eager) with sd_lock: pattern = saveddata_session.query(DamagePattern).options( *eager).filter(DamagePattern.rawName == lookfor).first() else: raise TypeError("Need integer or string as argument") return pattern
def getItemsByCategory(filter, where=None, eager=None): if isinstance(filter, int): filter = Category.ID == filter elif isinstance(filter, basestring): filter = Category.name == filter else: raise TypeError("Need integer or string as argument") filter = processWhere(filter, where) return gamedata_session.query(Item).options(*processEager(eager)).join(Item.group, Group.category).filter(filter).all()
def getRecentFits(ownerID=None, where=None, eager=None): eager = processEager(eager) with sd_lock: q = select( (Fit.ID, Fit.shipID, Fit.name, Fit.modified, Fit.created, Fit.timestamp, Fit.notes)).order_by(desc(Fit.modified), desc(Fit.timestamp)).limit(50) fits = eos.db.saveddata_session.execute(q).fetchall() return fits
def getCharacter(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sqlAlchemy.sd_lock: character = sqlAlchemy.saveddata_session.query(eds_Characters).get(lookfor) else: eager = processEager(eager) with sqlAlchemy.sd_lock: character = sqlAlchemy.saveddata_session.query(eds_Characters).options(*eager).filter( eds_Characters.ID == lookfor).first() elif isinstance(lookfor, basestring): eager = processEager(eager) with sqlAlchemy.sd_lock: try: character = sqlAlchemy.saveddata_session.query(eds_Characters).filter(eds_Characters.savedName == lookfor).first() except AttributeError: character = sqlAlchemy.saveddata_session.query(eds_Characters).first() else: raise TypeError("Need integer or string as argument") return character
def getGroup(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: group = sqlAlchemy.gamedata_session.query(Group).get(lookfor) else: group = sqlAlchemy.gamedata_session.query(Group).options(*processEager(eager)).filter(Group.ID == lookfor).first() elif isinstance(lookfor, basestring): if lookfor in groupNameMap: id = groupNameMap[lookfor] if eager is None: group = sqlAlchemy.gamedata_session.query(Group).get(id) else: group = sqlAlchemy.gamedata_session.query(Group).options(*processEager(eager)).filter(Group.ID == id).first() else: # Group names are unique, so we can use first() instead of one() group = sqlAlchemy.gamedata_session.query(Group).options(*processEager(eager)).filter(Group.name == lookfor).first() groupNameMap[lookfor] = group.ID else: raise TypeError("Need integer or string as argument") return group
def getItem(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: item = sqlAlchemy.gamedata_session.query(Item).get(lookfor) else: item = sqlAlchemy.gamedata_session.query(Item).options(*processEager(eager)).filter(Item.ID == lookfor).first() elif isinstance(lookfor, basestring): if lookfor in itemNameMap: id = itemNameMap[lookfor] if eager is None: item = sqlAlchemy.gamedata_session.query(Item).get(id) else: item = sqlAlchemy.gamedata_session.query(Item).options(*processEager(eager)).filter(Item.ID == id).first() else: # Item names are unique, so we can use first() instead of one() item = sqlAlchemy.gamedata_session.query(Item).options(*processEager(eager)).filter(Item.name == lookfor).first() itemNameMap[lookfor] = item.ID else: raise TypeError("Need integer or string as argument") return item
def getItem(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: item = gamedata_session.query(Item).get(lookfor) else: item = gamedata_session.query(Item).options(*processEager(eager)).filter(Item.ID == lookfor).first() elif isinstance(lookfor, basestring): if lookfor in itemNameMap: id = itemNameMap[lookfor] if eager is None: item = gamedata_session.query(Item).get(id) else: item = gamedata_session.query(Item).options(*processEager(eager)).filter(Item.ID == id).first() else: # Item names are unique, so we can use first() instead of one() item = gamedata_session.query(Item).options(*processEager(eager)).filter(Item.name == lookfor).first() itemNameMap[lookfor] = item.ID else: raise TypeError("Need integer or string as argument") return item
def getCategory(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: category = gamedata_session.query(Category).get(lookfor) else: category = gamedata_session.query(Category).options(*processEager(eager)).filter(Category.ID == lookfor).first() elif isinstance(lookfor, basestring): if lookfor in categoryNameMap: id = categoryNameMap[lookfor] if eager is None: category = gamedata_session.query(Category).get(id) else: category = gamedata_session.query(Category).options(*processEager(eager)).filter(Category.ID == id).first() else: # Category names are unique, so we can use first() instead of one() category = gamedata_session.query(Category).options(*processEager(eager)).filter(Category.name == lookfor).first() categoryNameMap[lookfor] = category.ID else: raise TypeError("Need integer or string as argument") return category
def getGroup(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: group = gamedata_session.query(Group).get(lookfor) else: group = gamedata_session.query(Group).options(*processEager(eager)).filter(Group.ID == lookfor).first() elif isinstance(lookfor, basestring): if lookfor in groupNameMap: id = groupNameMap[lookfor] if eager is None: group = gamedata_session.query(Group).get(id) else: group = gamedata_session.query(Group).options(*processEager(eager)).filter(Group.ID == id).first() else: # Group names are unique, so we can use first() instead of one() group = gamedata_session.query(Group).options(*processEager(eager)).filter(Group.name == lookfor).first() groupNameMap[lookfor] = group.ID else: raise TypeError("Need integer or string as argument") return group
def getItems(itemIDs, eager=None): if not isinstance(itemIDs, (tuple, list, set)) or not all( isinstance(t, int) for t in itemIDs): raise TypeError("Need iterable of integers as argument") if eager is None: items = get_gamedata_session().query(Item).filter( Item.ID.in_(itemIDs)).all() else: items = get_gamedata_session().query(Item).options( *processEager(eager)).filter(Item.ID.in_(itemIDs)).all() return items
def getAttributeInfo(attr, eager=None): if isinstance(attr, basestring): filter = AttributeInfo.name == attr elif isinstance(attr, int): filter = AttributeInfo.ID == attr else: raise TypeError("Need integer or string as argument") try: result = gamedata_session.query(AttributeInfo).options(*processEager(eager)).filter(filter).one() except exc.NoResultFound: result = None return result
def getDynamicItem(itemID, eager=None): try: if isinstance(itemID, int): if eager is None: result = gamedata_session.query(DynamicItem).filter(DynamicItem.ID == itemID).one() else: result = gamedata_session.query(DynamicItem).options(*processEager(eager)).filter(DynamicItem.ID == itemID).one() else: raise TypeError("Need integer as argument") except exc.NoResultFound: result = None return result
def getAttributeInfo(attr, eager=None): if isinstance(attr, basestring): filter_ = AttributeInfo.name == attr elif isinstance(attr, int): filter_ = AttributeInfo.ID == attr else: raise TypeError("Need integer or string as argument") try: result = sqlAlchemy.gamedata_session.query(AttributeInfo).options(*processEager(eager)).filter(filter_).one() except exc.NoResultFound: result = None return result
def getFit(lookfor, eager=None): if isinstance(lookfor, int): if eager is None: with sd_lock: fit = saveddata_session.query(Fit).get(lookfor) else: eager = processEager(eager) with sd_lock: fit = saveddata_session.query(Fit).options(*eager).filter(Fit.ID == fitID).first() else: raise TypeError("Need integer as argument") return fit
def getWing(wingID, eager=None): if isinstance(wingID, int): if eager is None: with sd_lock: wing = saveddata_session.query(Wing).get(wingID) else: eager = processEager(eager) with sd_lock: wing = saveddata_session.query(Wing).options(*eager).filter(Wing.ID == wingID).first() else: raise TypeError("Need integer as argument") return wing
def getSquad(squadID, eager=None): if isinstance(squadID, int): if eager is None: with sd_lock: squad = saveddata_session.query(Squad).get(squadID) else: eager = processEager(eager) with sd_lock: squad = saveddata_session.query(Squad).options(*eager).filter(Fleet.ID == squadID).first() else: raise TypeError("Need integer as argument") return squad
def searchFits(nameLike, where=None, eager=None): if not isinstance(nameLike, basestring): raise TypeError("Need string as argument") # Prepare our string for request nameLike = u"%{0}%".format(sqlizeString(nameLike)) #Add any extra components to the search to our where clause filter = processWhere(Fit.name.like(nameLike, escape="\\"), where) eager = processEager(eager) with sd_lock: fits = saveddata_session.query(Fit).options(*eager).filter(filter).all() return fits
def getFitsWithModules(typeIDs, eager=None): """ Get all the fits that have typeIDs fitted to them """ if not hasattr(typeIDs, "__iter__"): typeIDs = (typeIDs,) eager = processEager(eager) with sd_lock: fits = removeInvalid(saveddata_session.query(Fit).join(Module).options(*eager).filter(Module.itemID.in_(typeIDs)).all()) return fits
def getVariations(itemids, where=None, eager=None): for itemid in itemids: if not isinstance(itemid, int): raise TypeError("All passed item IDs must be integers") # Get out if list of provided IDs is empty if len(itemids) == 0: return [] itemfilter = or_(*(metatypes_table.c.parentTypeID == itemid for itemid in itemids)) filter = processWhere(itemfilter, where) joinon = items_table.c.typeID == metatypes_table.c.typeID vars = gamedata_session.query(Item).options(*processEager(eager)).join((metatypes_table, joinon)).filter(filter).all() return vars
def searchSkills(nameLike, where=None, eager=None): if not isinstance(nameLike, str): raise TypeError("Need string as argument") items = gamedata_session.query(Item).options(*processEager(eager)).join(Item.group, Group.category) for token in nameLike.split(' '): token_safe = "%{0}%".format(sqlizeNormalString(token)) if where is not None: items = items.filter(and_(Item.name.like(token_safe, escape="\\"), Category.ID == 16, where)) else: items = items.filter(and_(Item.name.like(token_safe, escape="\\"), Category.ID == 16)) items = items.limit(100).all() return items
def getFleet(fleetID, eager=None): if isinstance(fleetID, int): if eager is None: with sqlAlchemy.sd_lock: fleet = sqlAlchemy.saveddata_session.query(Fleet).get(fleetID) else: eager = processEager(eager) with sqlAlchemy.sd_lock: fleet = sqlAlchemy.saveddata_session.query(Fleet).options( *eager).filter(Fleet.ID == fleetID).first() else: raise TypeError("Need integer as argument") return fleet
def searchSkills(nameLike, where=None, eager=None): if not isinstance(nameLike, basestring): raise TypeError("Need string as argument") items = gamedata_session.query(Item).options(*processEager(eager)).join(Item.group, Group.category) for token in nameLike.split(' '): token_safe = u"%{0}%".format(sqlizeString(token)) if where is not None: items = items.filter(and_(Item.name.like(token_safe, escape="\\"), Category.ID == 16, where)) else: items = items.filter(and_(Item.name.like(token_safe, escape="\\"), Category.ID == 16)) items = items.limit(100).all() return items
def getSsoCharacter(lookfor, clientHash, eager=None): filter = SsoCharacter.client == clientHash if isinstance(lookfor, int): filter = and_(filter, SsoCharacter.ID == lookfor) elif isinstance(lookfor, str): filter = and_(filter, SsoCharacter.characterName == lookfor) else: raise TypeError("Need integer or string as argument") eager = processEager(eager) with sd_lock: character = saveddata_session.query(SsoCharacter).options(*eager).filter(filter).first() return character
def getVariations(itemids, where=None, eager=None): for itemid in itemids: if not isinstance(itemid, int): raise TypeError("All passed item IDs must be integers") # Get out if list of provided IDs is empty if len(itemids) == 0: return [] itemfilter = or_(*(Mapper.Items.metatypes_table.c.parentTypeID == itemid for itemid in itemids)) filter = processWhere(itemfilter, where) joinon = Mapper.Items.items_table.c.typeID == Mapper.Items.metatypes_table.c.typeID vars = sqlAlchemy.gamedata_session.query(Item).options(*processEager(eager)).join( (Mapper.Items.metatypes_table, joinon)).filter( filter).all() return vars
def searchItems(nameLike, where=None, join=None, eager=None): if not isinstance(nameLike, basestring): raise TypeError("Need string as argument") # Prepare our string for request nameLike = u"%{0}%".format(sqlizeString(nameLike)) if join is None: join = tuple() if not hasattr(join, "__iter__"): join = (join,) filter = processWhere(Item.name.like(nameLike, escape="\\"), where) items = gamedata_session.query(Item).options(*processEager(eager)).join(*join).filter(filter).all() return items
def getRecentFits(ownerID=None, where=None, eager=None): eager = processEager(eager) with sd_lock: q = select(( Fit.ID, Fit.shipID, Fit.name, Fit.modified, Fit.created, Fit.timestamp, Fit.notes )).order_by(desc(Fit.modified), desc(Fit.timestamp)).limit(50) fits = eos.db.saveddata_session.execute(q).fetchall() return fits
def searchItems(nameLike, where=None, join=None, eager=None): if not isinstance(nameLike, basestring): raise TypeError("Need string as argument") if join is None: join = tuple() if not hasattr(join, "__iter__"): join = (join,) items = gamedata_session.query(Item).options(*processEager(eager)).join(*join) for token in nameLike.split(' '): token_safe = u"%{0}%".format(sqlizeString(token)) items = items.filter(and_(Item.name.like(token_safe, escape="\\"), where)) items = items.limit(100).all() return items
def getBoosterFits(ownerID=None, where=None, eager=None): """ Get all the fits that are flagged as a boosting ship If no user is passed, do this for all users. """ if ownerID is not None and not isinstance(ownerID, int): raise TypeError("OwnerID must be integer") filter = Fit.booster == 1 if ownerID is not None: filter = and_(filter, Fit.ownerID == ownerID) filter = processWhere(filter, where) eager = processEager(eager) with sd_lock: fits = saveddata_session.query(Fit).options(*eager).filter(filter).all() return fits
def countFitsWithShip(shipID, ownerID=None, where=None, eager=None): """ Get all the fits using a certain ship. If no user is passed, do this for all users. """ if isinstance(shipID, int): if ownerID is not None and not isinstance(ownerID, int): raise TypeError("OwnerID must be integer") filter = Fit.shipID == shipID if ownerID is not None: filter = and_(filter, Fit.ownerID == ownerID) filter = processWhere(filter, where) eager = processEager(eager) with sd_lock: count = saveddata_session.query(Fit).options(*eager).filter(filter).count() else: raise TypeError("ShipID must be integer") return count
def getCharacterList(eager=None): eager = processEager(eager) with sd_lock: characters = saveddata_session.query(Character).options(*eager).all() return characters
def getDamagePatternList(eager=None): eager = processEager(eager) with sd_lock: patterns = saveddata_session.query(DamagePattern).options(*eager).all() return patterns
def getFleetList(eager=None): eager = processEager(eager) with sd_lock: fleets = saveddata_session.query(Fleet).options(*eager).all() return fleets