def test_default_forms():
    """Check that each pokemon has one default form and each species has one
    default pokemon."""

    session = connect()

    q = session.query(tables.Pokemon)
    q = q.join(tables.PokemonForm)
    q = q.filter(tables.PokemonForm.is_default == True)
    q = q.options(lazyload('*'))
    q = q.group_by(tables.Pokemon)
    q = q.add_columns(func.count(tables.PokemonForm.id))

    for pokemon, num_default_forms in q:
        if num_default_forms == 0:
            raise AssertionError("pokemon %s has no default forms" %
                                 pokemon.name)
        elif num_default_forms > 1:
            raise AssertionError("pokemon %s has %d default forms" %
                                 (pokemon.name, num_default_forms))

    q = session.query(tables.PokemonSpecies)
    q = q.join(tables.Pokemon)
    q = q.filter(tables.Pokemon.is_default == True)
    q = q.options(lazyload('*'))
    q = q.group_by(tables.PokemonSpecies)
    q = q.add_columns(func.count(tables.Pokemon.id))

    for species, num_default_pokemon in q:
        if num_default_pokemon == 0:
            raise AssertionError("species %s has no default pokemon" %
                                 species.name)
        elif num_default_pokemon > 1:
            raise AssertionError("species %s has %d default pokemon" %
                                 (species.name, num_default_pokemon))
def main(argv):
    session = connect()
    for cls in tables.mapped_classes:
        for translation_class in cls.translation_classes:
            columns = translation_class.__table__.c
            md_columns = [c for c in columns if c.info.get('format') == 'markdown']
            if not md_columns:
                continue
            for row in session.query(translation_class):
                if row.local_language_id != english_id:
                    continue
                for column in md_columns:
                    markdown = getattr(row, column.name)
                    if not markdown:
                        continue
                    text = str(markdown)
                    # Make sure everything that remotely looks like a link is one
                    links = fuzzy_link_re.findall(text)
                    if not links:
                        continue
                    for link in links:
                        assert strict_link_re.findall(link), (strict_link_re.findall(link), [link])
                    # Do the replacement
                    context = '%s %s %s' % (translation_class.__name__, row.foreign_id, column.name)
                    replaced = strict_link_re.sub(
                            partial(get_replacement, session, text, context),
                            text,
                        )
                    setattr(row, column.name, replaced)

    if argv and argv[0] == '--commit':
        session.commit()
        print('Committed')
    else:
        print('Run with --commit to commit changes')
def test_default_forms():
    """Check that each pokemon has one default form and each species has one
    default pokemon."""

    session = connect()

    q = session.query(tables.Pokemon)
    q = q.join(tables.PokemonForm)
    q = q.filter(tables.PokemonForm.is_default==True)
    q = q.options(lazyload('*'))
    q = q.group_by(tables.Pokemon)
    q = q.add_columns(func.count(tables.PokemonForm.id))

    for pokemon, num_default_forms in q:
        if num_default_forms == 0:
            raise AssertionError("pokemon %s has no default forms" % pokemon.name)
        elif num_default_forms > 1:
            raise AssertionError("pokemon %s has %d default forms" % (pokemon.name, num_default_forms))

    q = session.query(tables.PokemonSpecies)
    q = q.join(tables.Pokemon)
    q = q.filter(tables.Pokemon.is_default==True)
    q = q.options(lazyload('*'))
    q = q.group_by(tables.PokemonSpecies)
    q = q.add_columns(func.count(tables.Pokemon.id))

    for species, num_default_pokemon in q:
        if num_default_pokemon == 0:
            raise AssertionError("species %s has no default pokemon" % species.name)
        elif num_default_pokemon > 1:
            raise AssertionError("species %s has %d default pokemon" % (species.name, num_default_pokemon))
Exemple #4
0
 def __init__(self,
         session=None,
         langs=None,
         mainwindow=None,
     ):
     self.session = session or connect(engine_args=dict(echo=echo))
     self.mainwindow = mainwindow
     self.langs = langs or [u'en']
Exemple #5
0
 def __init__(
     self,
     session=None,
     langs=None,
     mainwindow=None,
 ):
     self.session = session or connect(engine_args=dict(echo=echo))
     self.mainwindow = mainwindow
     self.langs = langs or [u'en']
Exemple #6
0
def main(*argv):
    session = connect()

    location_dict = defaultdict(list)
    for location in session.query(tables.Location).order_by(
            tables.Location.id):
        location_dict[location.identifier].append(location)

    changes = False
    for identifier, locations in sorted(location_dict.items()):
        disambiguate = any((
            len(locations) > 1,
            ambiguous_re.match(identifier),
            identifier in ambiguous_set,
        ))
        print len(locations), ' *'[disambiguate], identifier,
        if disambiguate:
            changes = True
            print u'→'.encode('utf-8'),
            by_region = defaultdict(list)
            for location in locations:
                if location.region:
                    by_region[location.region.identifier].append(location)
                else:
                    by_region[None].append(location)
            for region_identifier, region_locations in by_region.items():
                if region_identifier:
                    new_identifier = '%s-%s' % (region_identifier, identifier)
                else:
                    # No change
                    new_identifier = identifier
                if len(region_locations) == 1:
                    location = region_locations[0]
                    # The region was enough
                    print new_identifier,
                    location.identifier = new_identifier
                else:
                    # Need to number the locations :(
                    for i, location in enumerate(region_locations, start=1):
                        numbered_identifier = '%s-%s' % (new_identifier, i)
                        print numbered_identifier,
                        location.identifier = numbered_identifier
        print

    if changes:
        if argv and argv[0] == '--commit':
            session.commit()
            print 'Committed'
        else:
            print 'Run with --commit to commit changes'
    else:
        print 'No changes needed'
def main(*argv):
    session = connect()

    location_dict = defaultdict(list)
    for location in session.query(tables.Location).order_by(tables.Location.id):
        location_dict[location.identifier].append(location)

    changes = False
    for identifier, locations in sorted(location_dict.items()):
        disambiguate = any((
                len(locations) > 1,
                ambiguous_re.match(identifier),
                identifier in ambiguous_set,
            ))
        print len(locations), ' *'[disambiguate], identifier,
        if disambiguate:
            changes = True
            print u'→'.encode('utf-8'),
            by_region = defaultdict(list)
            for location in locations:
                if location.region:
                    by_region[location.region.identifier].append(location)
                else:
                    by_region[None].append(location)
            for region_identifier, region_locations in by_region.items():
                if region_identifier:
                    new_identifier = '%s-%s' % (region_identifier, identifier)
                else:
                    # No change
                    new_identifier = identifier
                if len(region_locations) == 1:
                    location = region_locations[0]
                    # The region was enough
                    print new_identifier,
                    location.identifier = new_identifier
                else:
                    # Need to number the locations :(
                    for i, location in enumerate(region_locations, start=1):
                        numbered_identifier = '%s-%s' % (new_identifier, i)
                        print numbered_identifier,
                        location.identifier = numbered_identifier
        print

    if changes:
        if argv and argv[0] == '--commit':
            session.commit()
            print 'Committed'
        else:
            print 'Run with --commit to commit changes'
    else:
        print 'No changes needed'
Exemple #8
0
def getPokemonList(s):
    session = connect()
#    f = open(filename,'r')
    f = s.splitlines(True)
    print f
    pokemon_list = []
    next_pokemon = True
    for line in f:
        if next_pokemon and line != '\r\n':
            pokemon_list.append(getName(line))
            next_pokemon = False
        elif line == '\r\n':
            next_pokemon = True
    return pokemon_list
def test_nonzero_autoincrement_ids():
    """Check that autoincrementing ids don't contain zeroes

    MySQL doesn't like these, see e.g. bug #580
    """

    session = connect()
    for cls in tables.mapped_classes:
        if 'id' in cls.__table__.c:
            if cls.__table__.c.id.autoincrement:
                def nonzero_id(cls):
                    with pytest.raises(NoResultFound):
                        util.get(session, cls, id=0)
                nonzero_id.description = "No zero id in %s" % cls.__name__
                yield nonzero_id, cls
def test_nonzero_autoincrement_ids():
    """Check that autoincrementing ids don't contain zeroes

    MySQL doesn't like these, see e.g. bug #580
    """

    session = connect()
    for cls in tables.mapped_classes:
        if 'id' in cls.__table__.c:
            if cls.__table__.c.id.autoincrement:

                def nonzero_id(cls):
                    with pytest.raises(NoResultFound):
                        util.get(session, cls, id=0)

                nonzero_id.description = "No zero id in %s" % cls.__name__
                yield nonzero_id, cls
Exemple #11
0
    def __init__(self, directory=None, session=None):
        """Opens the whoosh index stored in the named directory.  If the index
        doesn't already exist, it will be created.

        `directory`
            Directory containing the index.  Defaults to a location within the
            `pokedex` egg directory.

        `session`
            Used for creating the index and retrieving objects.  Defaults to an
            attempt to connect to the default SQLite database installed by
            `pokedex setup`.
        """

        # By the time this returns, self.index and self.session must be set

        # If a directory was not given, use the default
        if directory is None:
            directory = get_default_index_dir()

        self.directory = directory

        if session:
            self.session = session
        else:
            self.session = connect()

        # Attempt to open or create the index
        if not os.path.exists(directory) or not os.listdir(directory):
            # Directory doesn't exist OR is empty; caller needs to use
            # rebuild_index before doing anything.  Provide a dummy object that
            # complains when used
            self.index = UninitializedIndex()
            return

        # Otherwise, already exists; should be an index!  Bam, done.
        # Note that this will explode if the directory exists but doesn't
        # contain an index; that's a feature
        try:
            self.index = whoosh.index.open_dir(directory, indexname='MAIN')
        except whoosh.index.EmptyIndexError:
            raise IOError(
                "The index directory already contains files.  "
                "Please use a dedicated directory for the lookup index."
            )
def test_encounter_slots():
    # Encounters have a version, which has a version group; encounters also
    # have an encounter_slot, which has a version group.  The two version
    # groups should match, universally.
    session = connect()

    version_group_a = aliased(tables.VersionGroup)
    version_group_b = aliased(tables.VersionGroup)

    sanity_q = session.query(tables.Encounter) \
        .join((tables.EncounterSlot, tables.Encounter.slot)) \
        .join((version_group_a, tables.EncounterSlot.version_group)) \
        .join((tables.Version, tables.Encounter.version)) \
        .join((version_group_b, tables.Version.version_group)) \
        .filter(version_group_a.id != version_group_b.id)

    # Encounter slots all match the encounters they belong to
    assert sanity_q.count() == 0
def test_encounter_slots():
    # Encounters have a version, which has a version group; encounters also
    # have an encounter_slot, which has a version group.  The two version
    # groups should match, universally.
    session = connect()

    version_group_a = aliased(tables.VersionGroup)
    version_group_b = aliased(tables.VersionGroup)

    sanity_q = session.query(tables.Encounter) \
        .join((tables.EncounterSlot, tables.Encounter.slot)) \
        .join((version_group_a, tables.EncounterSlot.version_group)) \
        .join((tables.Version, tables.Encounter.version)) \
        .join((version_group_b, tables.Version.version_group)) \
        .filter(version_group_a.id != version_group_b.id)

    # Encounter slots all match the encounters they belong to
    assert sanity_q.count() == 0
Exemple #14
0
def results(request):

    session = connect()

    try:
        team_text = request.POST['text']
    except:
        team_text = 'No team loaded'

    #Get the array of party Pokemon as strings
    pokemon_list = getPokemonList(team_text)

    #Get party_list, an array of tables.Pokemon
    party_list = []
    pokemon_type_list = []
    for i in range(0,len(pokemon_list)):
        try:
            party_list.append(util.get(session, tables.PokemonSpecies, name=pokemon_list[i]).default_pokemon)
            continue
        except:
            pass
        try:
            party_list.append(util.get(session, tables.Pokemon, pokemon_list[i].lower()))
        except:
            pass

    #The max resist for a certain type
    max_resists = []

    #Get list of types as tables.Type
    type_query = session.query(tables.Type)

    for (i, type) in enumerate(type_query):
        if i > 17:
            break
        max_resists.append([type.name, 100])
        for pokemon in party_list:
            resist = 1
            for type in pokemon.types:
                resist = resist * type.target_efficacies[i].damage_factor / 100.0
            if resist < max_resists[i][1]:
                max_resists[i][1] = resist

    return render(request, 'checker/results.html', {'party_list': party_list, 'max_resists': max_resists, 'team_text': team_text})
Exemple #15
0
    def __init__(self, directory=None, session=None):
        """Opens the whoosh index stored in the named directory.  If the index
        doesn't already exist, it will be created.

        `directory`
            Directory containing the index.  Defaults to a location within the
            `pokedex` egg directory.

        `session`
            Used for creating the index and retrieving objects.  Defaults to an
            attempt to connect to the default SQLite database installed by
            `pokedex setup`.
        """

        # By the time this returns, self.index and self.session must be set

        # If a directory was not given, use the default
        if directory is None:
            directory = get_default_index_dir()

        self.directory = directory

        if session:
            self.session = session
        else:
            self.session = connect()

        # Attempt to open or create the index
        if not os.path.exists(directory) or not os.listdir(directory):
            # Directory doesn't exist OR is empty; caller needs to use
            # rebuild_index before doing anything.  Provide a dummy object that
            # complains when used
            self.index = UninitializedIndex()
            return

        # Otherwise, already exists; should be an index!  Bam, done.
        # Note that this will explode if the directory exists but doesn't
        # contain an index; that's a feature
        try:
            self.index = whoosh.index.open_dir(directory, indexname='MAIN')
        except whoosh.index.EmptyIndexError:
            raise IOError(
                "The index directory already contains files.  "
                "Please use a dedicated directory for the lookup index.")
Exemple #16
0
def make_session(options):
    from pokedex import defaults, db

    engine_uri = options['--engine-uri']
    got_from = 'command line'

    if engine_uri is None:
        engine_uri, got_from = defaults.get_default_db_uri_with_origin()

    engine_args = {}
    if options['--display-sql']:
        engine_args['echo'] = True

    session = db.connect(engine_uri, engine_args=engine_args)

    if options['--verbose']:
        print >> sys.stderr, (
            "Connected to database %(engine)s (from %(got_from)s)" %
            dict(engine=session.bind.url, got_from=got_from))

    return session
def test_unique_form_order():
    """Check that tone PokemonForm.order value isn't used for more species
    """

    session = connect()

    species_by_form_order = {}

    query = session.query(tables.PokemonForm)
    query = query.options(joinedload('pokemon.species'))

    for form in query:
        print form.name
        try:
            previous_species = species_by_form_order[form.order]
        except KeyError:
            species_by_form_order[form.order] = form.species
        else:
            assert previous_species == form.species, (
                "PokemonForm.order == %s is used for %s and %s" %
                (form.order, species_by_form_order[form.order].name,
                 form.species.name))
def main(argv):
    session = connect()
    for cls in tables.mapped_classes:
        for translation_class in cls.translation_classes:
            columns = translation_class.__table__.c
            md_columns = [
                c for c in columns if c.info.get('format') == 'markdown'
            ]
            if not md_columns:
                continue
            for row in session.query(translation_class):
                if row.local_language_id != english_id:
                    continue
                for column in md_columns:
                    markdown = getattr(row, column.name)
                    if not markdown:
                        continue
                    text = unicode(markdown)
                    # Make sure everything that remotely looks like a link is one
                    links = fuzzy_link_re.findall(text)
                    if not links:
                        continue
                    for link in links:
                        assert strict_link_re.findall(link), (
                            strict_link_re.findall(link), [link])
                    # Do the replacement
                    context = '%s %s %s' % (translation_class.__name__,
                                            row.foreign_id, column.name)
                    replaced = strict_link_re.sub(
                        partial(get_replacement, session, text, context),
                        text,
                    )
                    setattr(row, column.name, replaced)

    if argv and argv[0] == '--commit':
        session.commit()
        print 'Committed'
    else:
        print 'Run with --commit to commit changes'
def test_unique_form_order():
    """Check that tone PokemonForm.order value isn't used for more species
    """

    session = connect()

    species_by_form_order = {}

    query = session.query(tables.PokemonForm)
    query = query.options(joinedload('pokemon.species'))

    for form in query:
        print form.name
        try:
            previous_species = species_by_form_order[form.order]
        except KeyError:
            species_by_form_order[form.order] = form.species
        else:
            assert previous_species == form.species, (
                "PokemonForm.order == %s is used for %s and %s" % (
                        form.order,
                        species_by_form_order[form.order].name,
                        form.species.name))
Exemple #20
0
def create_downloads():
    # Gotta chdir to get the gzip header right; see Python bug 4750
    os.chdir(downloads_dir)

    # The database
    db_filename = os.path.join(downloads_dir, 'veekun-pokedex.sqlite')
    session = connect('sqlite:///' + db_filename)
    load(session, drop_tables=True, verbose=True, safe=False)
    session.close()
    db_gz = gzip.open(db_filename + '.gz', 'wb')
    with open(db_filename, 'rb') as source:
        db_gz.write(source.read())
    db_gz.close()  # XXX: 'with' context manager support is in Python 2.7
    os.unlink(db_filename)

    # Per-generation Pokémon tarballs
    main_tarball('generation-1.tar.gz', ['red-green', 'red-blue', 'yellow'])
    main_tarball('generation-2.tar.gz', ['gold', 'silver', 'crystal'])
    main_tarball('generation-3.tar.gz', ['ruby-sapphire', 'emerald', 'firered-leafgreen'])
    main_tarball('generation-4.tar.gz', ['diamond-pearl', 'platinum', 'heartgold-soulsilver'])
    main_tarball('generation-5.tar.gz', ['black-white'])

    # Other Pokémon stuff
    make_tarball('overworld.tar.gz', ['pokemon/overworld'])
    make_tarball('pokemon-cries.tar.gz', ['pokemon/cries'])
    make_tarball('pokemon-sugimori.tar.gz', ['pokemon/sugimori'])
    make_tarball('pokemon-footprints.tar.gz', ['pokemon/footprints'])
    make_tarball('pokemon-trozei.tar.gz', ['pokemon/trozei'])
    make_tarball('pokemon-icons.tar.gz', ['pokemon/icons'])
    make_tarball('pokemon-conquest.tar.gz', ['pokemon/conquest'])
    make_tarball('pokemon-dream-world.tar.gz', ['pokemon/dream-world'])
    make_tarball('pokemon-global-link.tar.gz', ['pokemon/global-link'])

    # Not Pokémon at all!
    make_tarball('chrome.tar.gz', ['chrome', 'ribbons'])
    make_tarball('items.tar.gz', ['items'])

    # Bunch o' montages
    main_montage('red-green.png',       'red-green/gray/{0}.png',   56, 151)
    main_montage('red-green-sgb.png',   'red-green/{0}.png',        56, 151)
    main_montage('red-blue.png',        'red-blue/gray/{0}.png',    56, 151)
    main_montage('red-blue-sgb.png',    'red-blue/{0}.png',         56, 151)
    main_montage('yellow.png',          'yellow/gray/{0}.png',      56, 151)
    main_montage('yellow-sgb.png',      'yellow/{0}.png',           56, 151)
    main_montage('yellow-gbc.png',      'yellow/gbc/{0}.png',       56, 151)
    main_montage('generation-1-back.png',
        'red-blue/back/gray/{0}.png',       32, 151)
    main_montage('red-green-blue-back-sgb.png',
        'red-blue/back/{0}.png',            32, 151)
    main_montage('yellow-back-sgb.png', 'yellow/back/{0}.png',      32, 151)
    main_montage('yellow-back-gbc.png', 'yellow/back/gbc/{0}.png',  32, 151)

    main_montage('gold.png',            'gold/{0}.png',             56, 251)
    main_montage('gold-shiny.png',      'gold/shiny/{0}.png',       56, 251)
    main_montage('silver.png',          'silver/{0}.png',           56, 251)
    main_montage('silver-shiny.png',    'silver/shiny/{0}.png',     56, 251)
    main_montage('crystal.png',         'crystal/{0}.png',          56, 251)
    main_montage('crystal-shiny.png',   'crystal/shiny/{0}.png',    56, 251)
    main_montage('gold-silver-back.png',
        'silver/back/{0}.png',              48, 251)
    main_montage('gold-silver-back-shiny.png',
        'silver/back/shiny/{0}.png',        48, 251)
    main_montage('crystal-back.png',
        'crystal/back/{0}.png',              48, 251)
    main_montage('crystal-back-shiny.png',
        'crystal/back/shiny/{0}.png',        48, 251)

    main_montage('generation-3.png',
        'ruby-sapphire/{0}.png',            64, 386, transparent=True)
    main_montage('generation-3-shiny.png',
        'ruby-sapphire/shiny/{0}.png',      64, 386, transparent=True)
    main_montage('emerald-frame2.png',
        'emerald/frame2/{0}.png',           64, 386, transparent=True)
    main_montage('emerald-frame2-shiny.png',
        'emerald/shiny/frame2/{0}.png',     64, 386, transparent=True)
    main_montage('firered-leafgreen.png',
        'firered-leafgreen/{0}.png',        64, 151, transparent=True)
    main_montage('firered-leafgreen-shiny.png',
        'firered-leafgreen/shiny/{0}.png',  64, 151, transparent=True)
    main_montage('generation-3-back.png',
        'ruby-sapphire/back/{0}.png',       64, 386, transparent=True)
    main_montage('generation-3-back-shiny.png',
        'ruby-sapphire/back/shiny/{0}.png', 64, 386, transparent=True)
    main_montage('firered-leafgreen-back.png',
        'firered-leafgreen/back/{0}.png',   64, 151, transparent=True)
    main_montage('firered-leafgreen-back-shiny.png',
        'firered-leafgreen/back/shiny/{0}.png', 64, 151, transparent=True)

    main_montage('diamond-pearl.png',
        'diamond-pearl/{0}.png',            80, 493, transparent=True)
    main_montage('diamond-pearl-shiny.png',
        'diamond-pearl/shiny/{0}.png',      80, 493, transparent=True)
    main_montage('diamond-pearl-frame2.png',
        'diamond-pearl/frame2/{0}.png',     80, 493, transparent=True)
    main_montage('diamond-pearl-shiny-frame2.png',
        'diamond-pearl/shiny/frame2/{0}.png', 80, 493, transparent=True)
    main_montage('platinum.png',
        'platinum/{0}.png',                 80, 493, transparent=True)
    main_montage('platinum-shiny.png',
        'platinum/shiny/{0}.png',           80, 493, transparent=True)
    main_montage('platinum-frame2.png',
        'platinum/frame2/{0}.png',          80, 493, transparent=True)
    main_montage('platinum-shiny-frame2.png',
        'platinum/shiny/frame2/{0}.png',    80, 493, transparent=True)
    main_montage('heartgold-soulsilver.png',
        'heartgold-soulsilver/{0}.png',     80, 493, transparent=True)
    main_montage('heartgold-soulsilver-shiny.png',
        'heartgold-soulsilver/shiny/{0}.png', 80, 493, transparent=True)
    main_montage('heartgold-soulsilver-frame2.png',
        'heartgold-soulsilver/frame2/{0}.png', 80, 493, transparent=True)
    main_montage('heartgold-soulsilver-shiny-frame2.png',
        'heartgold-soulsilver/shiny/frame2/{0}.png', 80, 493, transparent=True)
    main_montage('diamond-pearl-back.png',
        'diamond-pearl/back/{0}.png',       80, 493, transparent=True)
    main_montage('diamond-pearl-back-shiny.png',
        'diamond-pearl/back/shiny/{0}.png', 80, 493, transparent=True)
    main_montage('platinum-back.png',
        'platinum/back/{0}.png',            80, 493, transparent=True)
    main_montage('platinum-back-shiny.png',
        'platinum/back/shiny/{0}.png',      80, 493, transparent=True)
    main_montage('platinum-back-frame2.png',
        'platinum/back/frame2/{0}.png',     80, 493, transparent=True)
    main_montage('platinum-back-shiny-frame2.png',
        'platinum/back/shiny/frame2/{0}.png', 80, 493, transparent=True)
    main_montage('heartgold-soulsilver-back.png',
        'heartgold-soulsilver/back/{0}.png', 80, 493, transparent=True)
    main_montage('heartgold-soulsilver-back-shiny.png',
        'heartgold-soulsilver/back/shiny/{0}.png', 80, 493, transparent=True)
    main_montage('heartgold-soulsilver-back-frame2.png',
        'heartgold-soulsilver/back/frame2/{0}.png', 80, 493, transparent=True)
    main_montage('heartgold-soulsilver-back-shiny-frame2.png',
        'heartgold-soulsilver/back/shiny/frame2/{0}.png', 80, 493, transparent=True)

    main_montage('black-white.png',
        'black-white/{0}.png', 96, 649, transparent=True)
    main_montage('black-white-shiny.png',
        'black-white/shiny/{0}.png', 96, 649, transparent=True)
    main_montage('black-white-back.png',
        'black-white/back/{0}.png', 96, 649, transparent=True)
    main_montage('black-white-back-shiny.png',
        'black-white/back/shiny/{0}.png', 96, 649, transparent=True)

    # And female montages, which are a little different
    make_diff_montage(
        filename='diamond-pearl-female-diff.png',
        other_filename='diamond-pearl.png',
        pattern='pokemon/main-sprites/diamond-pearl/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/diamond-pearl/{0}.png',
        sprite_size=80,
        pokemon=493,
    )
    make_diff_montage(
        filename='platinum-female-diff.png',
        other_filename='platinum.png',
        pattern='pokemon/main-sprites/platinum/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/platinum/{0}.png',
        sprite_size=80,
        pokemon=493,
    )
    make_diff_montage(
        filename='heartgold-soulsilver-female-diff.png',
        other_filename='heartgold-soulsilver.png',
        pattern='pokemon/main-sprites/heartgold-soulsilver/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/heartgold-soulsilver/{0}.png',
        sprite_size=80,
        pokemon=493,
    )
    make_diff_montage(
        filename='black-white-female-diff.png',
        other_filename='black-white.png',
        pattern='pokemon/main-sprites/black-white/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/black-white/{0}.png',
        sprite_size=96,
        pokemon=649,
    )
    make_diff_montage(
        filename='diamond-pearl-back-female-diff.png',
        other_filename='diamond-pearl-back.png',
        pattern='pokemon/main-sprites/diamond-pearl/back/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/diamond-pearl/back/{0}.png',
        sprite_size=80,
        pokemon=493,
    )
    make_diff_montage(
        filename='platinum-back-female-diff.png',
        other_filename='platinum-back.png',
        pattern='pokemon/main-sprites/platinum/back/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/platinum/back/{0}.png',
        sprite_size=80,
        pokemon=493,
    )
    make_diff_montage(
        filename='heartgold-soulsilver-back-female-diff.png',
        other_filename='heartgold-soulsilver-back.png',
        pattern='pokemon/main-sprites/heartgold-soulsilver/back/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/heartgold-soulsilver/back/{0}.png',
        sprite_size=80,
        pokemon=493,
    )
    make_diff_montage(
        filename='black-white-back-female-diff.png',
        other_filename='black-white-back.png',
        pattern='pokemon/main-sprites/black-white/back/female/{0}.png',
        fallback_pattern='pokemon/main-sprites/black-white/back/{0}.png',
        sprite_size=96,
        pokemon=649,
    )

    # Overworld
    make_montage('overworld-right.png',
        'pokemon/overworld/right/{0}.png', 32, 493, transparent=True)
    make_montage('overworld-down.png',
        'pokemon/overworld/down/{0}.png', 32, 493, transparent=True)
    make_montage('overworld-up.png',
        'pokemon/overworld/up/{0}.png', 32, 493, transparent=True)
    make_montage('overworld-right-shiny.png',
        'pokemon/overworld/shiny/right/{0}.png', 32, 493, transparent=True)
    make_montage('overworld-down-shiny.png',
        'pokemon/overworld/shiny/down/{0}.png', 32, 493, transparent=True)
    make_montage('overworld-up-shiny.png',
        'pokemon/overworld/shiny/up/{0}.png', 32, 493, transparent=True)

    # Other miscellaneous
    make_montage('footprints.png', 'pokemon/footprints/{0}.png', 16, 649)
    make_montage('sugimori.png', 'pokemon/sugimori/{0}.png', 96, 493,
        padding=2, filter='lanczos')
    make_montage('conquest.png', 'pokemon/conquest/{0}.png', 128, None,
        transparent=True)
    make_labeled_montage(
        'items.png', 'items', suffix='.png',
        sprite_size=24, horiz_padding=36, vert_padding=6,
    )
    make_labeled_montage(
        'berries.png', 'items/berries', suffix='.png',
        sprite_size=48, horiz_padding=36, vert_padding=4,
    )
Exemple #21
0
from sqlalchemy import and_
from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm.exc import NoResultFound

from .models import (
    DBSession,
    Patch,
    PatchType,
    Route
    )

from pokedex.db import connect
import pokedex.db.tables as t

PDSession = connect()

@subscriber(BeforeRender)
def add_globals(event):
    event['c'] = c

@view_config(route_name='home', renderer='home.mako')
def home(request):
    return {}

@view_config(route_name='locations', renderer='locations.mako')
def locations(request):
    return {}

@view_config(route_name='about', renderer='about.mako')
def about(request):
Exemple #22
0
from pokemwdb.wikicache import WikiCache
from pokemwdb import wikiparse


#stdout = sys.stdout
#import traceback
#class F(object):
    #def write(self, s):
        #stdout.write('---\n')
        #stdout.write(s)
        #stdout.write(''.join(traceback.format_stack()))
        #stdout.write('---\n\n')
#sys.stdout = F()
#session = connect(engine_args=dict(echo=True))

session = connect() #engine_args=dict(echo=True))
wiki = WikiCache('http://wiki.pokemon-online.eu/api.php?')

version_groups = session.query(tables.VersionGroup).order_by(
        tables.VersionGroup.generation_id,
        tables.VersionGroup.id,
    ).all()

differ = diff_match_patch()
def make_diff(a, b):
    diff = differ.diff_main(a, b)
    differ.diff_cleanupSemantic(diff)
    return diff

def wiki_colorizer(light, dark, name):
    def colorizer(text):
Exemple #23
0
def session(request):
    uri = request.config.getvalue("engine")
    return connect(uri)
Exemple #24
0
 def __init__(self):
     WikiChecker.__init__(self)
     self.session = connect()
def session():
    return connect()
Exemple #26
0
def session(request):
    uri = request.config.getvalue("engine")
    return connect(uri)
Exemple #27
0
# Encoding: utf8

import pytest

from pokedex.tests import single_params
from pokedex.db import connect, tables, util

session = connect()

def test_get_item_identifier():
    item = util.get(session, tables.Item, identifier='master-ball')
    assert item.name == 'Master Ball'

def test_get_item_name():
    item = util.get(session, tables.Item, name='Awakening')
    assert item.name == 'Awakening'

def test_get_english_by_identifier():
    language = util.get(session, tables.Language, 'en')
    assert language.name == 'English'

@single_params(*'burmy shaymin unown cresselia'.split())
def test_get_pokemon_identifier(identifier):
    poke = util.get(session, tables.PokemonSpecies, identifier=identifier)
    assert poke.identifier == identifier

@single_params(*'Burmy Shaymin Unown Cresselia'.split())
def test_get_pokemon_name(name):
    poke = util.get(session, tables.PokemonSpecies, name=name)
    assert poke.name == name
Exemple #28
0
# Encoding: UTF-8

import pytest
from sqlalchemy.orm.exc import NoResultFound

from pokedex.tests import positional_params

from pokedex.db import tables, connect, util, markdown

connection = connect()

def test_filter():
    q = connection.query(tables.PokemonSpecies).filter(
            tables.PokemonSpecies.name == "Marowak")
    assert q.one().identifier == 'marowak'

def test_languages():
    q = connection.query(tables.PokemonSpecies).filter(
            tables.PokemonSpecies.name == "Mightyena")
    pkmn = q.one()
    for lang, name in (
            ('en', 'Mightyena'),
            ('ja', 'グラエナ'),
            ('roomaji', 'Guraena'),
            ('fr', 'Grahyèna'),
        ):
        language = connection.query(tables.Language).filter_by(
                identifier=lang).one()
        assert pkmn.name_map[language] == name

def test_bad_lang():
Exemple #29
0
        query = query.filter(tables.PokemonSpecies.identifier == identifier)
        return query.one()

    @_cached
    def load_by_identifier(self, table, identifier):
        query = self.session.query(table)
        query = query.filter(table.identifier == identifier)
        return query.one()

    def _loader(table):
        def load(self, identifier):
            return self.load_by_identifier(table, identifier)
        return load

    load_move = _loader(tables.Move)
    load_nature = _loader(tables.Nature)
    load_ability = _loader(tables.Ability)
    load_item = _loader(tables.Item)
    load_stat = _loader(tables.Stat)
    load_damage_class = _loader(tables.MoveDamageClass)

    def load_struggle(self):
        return self.load_move('struggle')

    def load_types(self, identifiers):
        results = []
        for name in names:
            return self.load_type(identifiers)

default_loader = Loader(connect(), 5)
Exemple #30
0
# Encoding: UTF-8

import pytest
from sqlalchemy.orm.exc import NoResultFound

from pokedex.tests import positional_params

from pokedex.db import tables, connect, util, markdown

connection = connect()


def test_filter():
    q = connection.query(
        tables.PokemonSpecies).filter(tables.PokemonSpecies.name == u"Marowak")
    assert q.one().identifier == 'marowak'


def test_languages():
    q = connection.query(tables.PokemonSpecies).filter(
        tables.PokemonSpecies.name == u"Mightyena")
    pkmn = q.one()
    for lang, name in (
        ('en', u'Mightyena'),
        ('ja', u'グラエナ'),
        ('roomaji', u'Guraena'),
        ('fr', u'Grahyèna'),
    ):
        language = connection.query(
            tables.Language).filter_by(identifier=lang).one()
        assert pkmn.name_map[language] == name
def setup():
    global session
    session = connect()
    make_classification_groups()