Example #1
0
def get_generic(table, field, wherename, whereval):
    # XXX TODO caching
    db = get_db()
    db.execute('SELECT %s FROM %s WHERE %s = %%s'
               % (field, table, wherename),
               (whereval, ))
    return db.fetchone()[0]
Example #2
0
 def get(account_id):
     db = get_db()
     db.execute(
         "SELECT accountid, nickname, apiverified, characterid, "
         "charactername, corporationid, corporationname, allianceid, "
         "alliancename, ismoderator, reputation "
         "FROM osmium.accounts WHERE accountid = %s",
         (account_id,),
     )
     return Account(*db.fetchone())
Example #3
0
 def set_ship(self, ship_typeid):
     assert ship_typeid != None
     db = get_db()
     db.execute('SELECT invships.typename FROM osmium.invships '
                'JOIN eve.invtypes ON invtypes.typeid = invships.typeid '
                'WHERE invships.typeid = %s',
                (ship_typeid, ))
     if not db.rowcount:
         return False
     (typename, ) = db.fetchone()
     self.ship = {
         'typeid': ship_typeid,
         'typename': typename,
     }
     self.dogma_context.set_ship(ship_typeid)
     return True
Example #4
0
    def get_fit(loadout_id, revision=None):
        """Loads a loadout (with metadata) by loadout ID."""
        db = get_db()

        # TODO caching

        latest_revision = False
        if revision is None:
            db.execute('SELECT latestrevision '
                       'FROM osmium.loadoutslatestrevision '
                       'WHERE loadoutid = %s', (loadout_id, ))
            if not db.rowcount:
                return None
            (revision, ) = db.fetchone()
            latest_revision = True

        # TODO caching

        db.execute('SELECT accountid, viewpermission, editpermission, '
                   'visibility, passwordhash, privatetoken '
                   'FROM osmium.loadouts WHERE loadoutid = %s',
                   (loadout_id, ))
        if not db.rowcount:
            return None
        (account_id, view_permission, edit_permission,
         visibility, password_hash, private_token) = db.fetchone()

        db.execute('SELECT loadouthistory.fittinghash '
                   'FROM osmium.loadouthistory '
                   'WHERE loadoutid = %s AND revision = %s',
                   (loadout_id, revision))
        if not db.rowcount:
            return None
        (hash, ) = db.fetchone()

        fit = Fit.get_bare_fit(hash)
        fit.metadata.update({
            'loadoutid': loadout_id,
            'private_token': private_token,
            'viewpermission': view_permission,
            'editpermission': edit_permission,
            'visibility': visibility,
            'password': password_hash,
            'revision': revision,
            'accountid': account_id,
        })
        return fit
Example #5
0
    def get_bare_fit(fitting_hash):
        """Loads a fit (no metadata) from a fitting hash."""
        db = get_db()
        db.execute('SELECT name, description, evebuildnumber, hullid, '
                   '       creationdate, damageprofileid '
                   'FROM osmium.fittings '
                   'WHERE fittinghash = %s',
                   (fitting_hash, ))
        if not db.rowcount:
            return None
        (name, description, eve_build_number, hull_id, creation_date,
         damage_profile_id) = db.fetchone()

        fit = Fit(ship_typeid=hull_id)

        fit.metadata = {
            'hash': fitting_hash,
            'name': name,
            'description': description,
            'evebuildnumber': eve_build_number,
            'creation_date': creation_date,
        }

        db.execute(
            'SELECT tagname FROM osmium.fittingtags WHERE fittinghash = %s',
            (fitting_hash, ))
        fit.metadata['tags'] = [row[0] for row in db.fetchall()]

        if damage_profile_id:
            db.execute(
                'SELECT name, electromagnetic, explosive, kinetic, thermal '
                'FROM osmium.damageprofiles '
                'WHERE damageprofileid = %s',
                (damage_profile_id, ))
            if not db.rowcount:
                return None
            fit.set_damage_profile(*db.fetchone())


        db.execute('SELECT presetid, name, description '
                   'FROM osmium.fittingpresets '
                   'WHERE fittinghash = %s '
                   'ORDER BY presetid ASC',
                   (fitting_hash,))

        for (preset_id, name, description) in db.fetchall():
            preset = Preset(preset_id, name, description)
            fit.presets[preset_id] = preset
            fit.use_preset(preset_id)

            db.execute('SELECT index, typeid, state '
                       'FROM osmium.fittingmodules '
                       'WHERE fittinghash = %s AND presetid = %s '
                       'ORDER BY index ASC', (fitting_hash, preset_id))
            for (index, type, state) in db.fetchall():
                fit.add_module(index, type, state)

            db.execute('SELECT chargepresetid, name, description '
                       'FROM osmium.fittingchargepresets '
                       'WHERE fittinghash = %s AND presetid = %s '
                       'ORDER BY chargepresetid ASC',
                       (fitting_hash, preset_id))
            for (charge_preset_id, name, description) in db.fetchall():
                charge_preset = ChargePreset(charge_preset_id, name,
                                             description)
                preset.charge_presets[charge_preset_id] = charge_preset
                fit.use_charge_preset(charge_preset_id)

                db.execute('SELECT slottype, index, typeid '
                           'FROM osmium.fittingcharges '
                           'WHERE fittinghash = %s AND presetid = %s AND '
                           '      chargepresetid = %s '
                           'ORDER BY slottype ASC, index ASC',
                           (fitting_hash, preset_id, charge_preset_id))
                for (slottype, index, typeid) in db.fetchall():
                    fit.add_charge(slottype, index, typeid)

            db.execute('SELECT typeid '
                       'FROM osmium.fittingimplants '
                       'WHERE fittinghash = %s AND presetid = %s',
                       (fitting_hash, preset_id))
            for (implant, ) in db.fetchall():
                fit.add_implant(implant)


        db.execute('SELECT dronepresetid, name, description '
                   'FROM osmium.fittingdronepresets '
                   'WHERE fittinghash = %s '
                   'ORDER BY dronepresetid ASC',
                   (fitting_hash, ))
        for preset_id, name, description in db.fetchall():
            preset = DronePreset(preset_id, name, description)
            fit.drone_presets[preset_id] = preset
            fit.use_drone_preset(preset_id)

            db.execute('SELECT typeid, quantityinbay, quantityinspace '
                       'FROM osmium.fittingdrones '
                       'WHERE fittinghash = %s AND dronepresetid = %s',
                       (fitting_hash, preset_id))
            for typeid, inbay, inspace in db.fetchall():
                fit.add_drone(typeid, inbay, inspace)

        # TODO: fleet, remote, targets

        return fit