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 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 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 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 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 getPrice(typeID): if isinstance(typeID, int): with sd_lock: price = saveddata_session.query(Price).get(typeID) else: raise TypeError("Need integer as argument") return price
def getMiscData(field): if isinstance(field, basestring): with sd_lock: data = saveddata_session.query(MiscData).get(field) else: raise TypeError("Need string as argument") return data
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 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 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 getSquadsIDsWithFitID(fitID): if isinstance(fitID, int): with sd_lock: squads = saveddata_session.query(squadmembers_table.c.squadID).filter(squadmembers_table.c.memberID == fitID).all() squads = tuple(entry[0] for entry in squads) return squads else: raise TypeError("Need integer as argument")
def getProjectedFits(fitID): if isinstance(fitID, int): with sd_lock: filter = and_(projectedFits_table.c.sourceID == fitID, Fit.ID == projectedFits_table.c.victimID) fits = saveddata_session.query(Fit).filter(filter).all() return fits else: raise TypeError("Need integer as argument")
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 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 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 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 getDamagePatternList(eager=None): eager = processEager(eager) with sd_lock: patterns = saveddata_session.query(DamagePattern).options(*eager).all() return patterns
def getSsoCharacters(clientHash, eager=None): eager = processEager(eager) with sd_lock: characters = saveddata_session.query(SsoCharacter).filter(SsoCharacter.client == clientHash).options(*eager).all() return characters
def clearPrices(): with sd_lock: deleted_rows = saveddata_session.query(Price).delete() commit() return deleted_rows
def clearOverrides(): with sd_lock: deleted_rows = saveddata_session.query(Override).delete() commit() return deleted_rows
def getAllOverrides(eager=None): return saveddata_session.query(Override).all()
def getFleetList(eager=None): eager = processEager(eager) with sd_lock: fleets = saveddata_session.query(Fleet).options(*eager).all() return fleets
def countAllFits(): with sd_lock: count = saveddata_session.query(Fit).count() return count
def getOverrides(itemID, eager=None): if isinstance(itemID, int): return saveddata_session.query(Override).filter( Override.itemID == itemID).all() else: raise TypeError("Need integer as argument")
def getTargetResistsList(eager=None): eager = processEager(eager) with sd_lock: patterns = saveddata_session.query(TargetResists).options(*eager).all() return patterns
def getImplantSetList(eager=None): eager = processEager(eager) with sd_lock: sets = saveddata_session.query(ImplantSet).options(*eager).all() return sets
def getCharacterList(eager=None): eager = processEager(eager) with sd_lock: characters = saveddata_session.query(Character).options(*eager).all() return characters
def clearDamagePatterns(): with sd_lock: deleted_rows = saveddata_session.query(DamagePattern).filter(DamagePattern.name != 'Uniform').delete() commit() return deleted_rows
def getOverrides(itemID, eager=None): if isinstance(itemID, int): return saveddata_session.query(Override).filter(Override.itemID == itemID).all() else: raise TypeError("Need integer as argument")
def clearTargetProfiles(): with sd_lock: deleted_rows = saveddata_session.query(TargetProfile).delete() commit() return deleted_rows
def getFitList(eager=None): eager = processEager(eager) with sd_lock: fits = removeInvalid(saveddata_session.query(Fit).options(*eager).all()) return fits