예제 #1
0
파일: queries.py 프로젝트: w9jds/Pyfa
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
파일: queries.py 프로젝트: tigeryi1998/Pyfa
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
예제 #5
0
파일: queries.py 프로젝트: IslayTzash/Pyfa
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
예제 #6
0
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
예제 #7
0
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
예제 #8
0
파일: queries.py 프로젝트: tigeryi1998/Pyfa
def getFitList(eager=None):
    eager = processEager(eager)
    with sd_lock:
        fits = removeInvalid(
            saveddata_session.query(Fit).options(*eager).all())

    return fits
예제 #9
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #10
0
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
예제 #11
0
파일: queries.py 프로젝트: Sectoid/Pyfa
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
예제 #12
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #13
0
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
예제 #14
0
파일: queries.py 프로젝트: IslayTzash/Pyfa
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
예제 #15
0
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
예제 #16
0
파일: queries.py 프로젝트: meldi44/Pyfa
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
예제 #17
0
파일: queries.py 프로젝트: copyliu/Pyfa
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
예제 #18
0
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
예제 #19
0
파일: queries.py 프로젝트: xmb666/Pyfa
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
예제 #20
0
파일: queries.py 프로젝트: meldi44/Pyfa
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()
예제 #21
0
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()
예제 #22
0
파일: queries.py 프로젝트: tigeryi1998/Pyfa
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
예제 #23
0
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
예제 #24
0
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
예제 #25
0
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
예제 #26
0
파일: queries.py 프로젝트: copyliu/Pyfa
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
예제 #27
0
파일: queries.py 프로젝트: meldi44/Pyfa
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
예제 #28
0
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
예제 #29
0
파일: queries.py 프로젝트: copyliu/Pyfa
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
예제 #30
0
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
예제 #31
0
파일: queries.py 프로젝트: copyliu/Pyfa
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
예제 #32
0
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
예제 #33
0
파일: queries.py 프로젝트: blitzmann/Pyfa
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
예제 #34
0
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
예제 #35
0
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
예제 #36
0
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
예제 #37
0
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
예제 #38
0
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
예제 #39
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #40
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #41
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #42
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #43
0
파일: queries.py 프로젝트: Sectoid/Pyfa
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
예제 #44
0
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
예제 #45
0
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
예제 #46
0
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
예제 #47
0
파일: fleet.py 프로젝트: a-tal/Pyfa
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
예제 #48
0
파일: queries.py 프로젝트: copyliu/Pyfa
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
예제 #49
0
파일: queries.py 프로젝트: Sectoid/Pyfa
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
예제 #50
0
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
예제 #51
0
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
예제 #52
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #53
0
파일: queries.py 프로젝트: Sectoid/Pyfa
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
예제 #54
0
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
예제 #55
0
파일: queries.py 프로젝트: DaManDOH/Pyfa
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
예제 #56
0
파일: queries.py 프로젝트: Dennovin/Pyfa
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
예제 #57
0
파일: queries.py 프로젝트: Dennovin/Pyfa
def getCharacterList(eager=None):
    eager = processEager(eager)
    with sd_lock:
        characters = saveddata_session.query(Character).options(*eager).all()
    return characters
예제 #58
0
파일: queries.py 프로젝트: Dennovin/Pyfa
def getDamagePatternList(eager=None):
    eager = processEager(eager)
    with sd_lock:
        patterns = saveddata_session.query(DamagePattern).options(*eager).all()
    return patterns
예제 #59
0
파일: queries.py 프로젝트: Dennovin/Pyfa
def getFleetList(eager=None):
    eager = processEager(eager)
    with sd_lock:
        fleets = saveddata_session.query(Fleet).options(*eager).all()
    return fleets