コード例 #1
0
def load(session, options):
    from ptcgdex import tcg_tables
    from ptcgdex import load as ptcg_load
    from pokedex.db import load as dex_load
    tcg_tables = [c.__tablename__ for c in all_tables(tcg_tables.tcg_classes)]
    table_names = options['<table-name>']
    sets = []
    if table_names:
        tcg_table_set = set(tcg_tables)
        tables = []
        for tablename in table_names:
            tcg_tablename = 'tcg_' + tablename
            if tablename in tcg_table_set:
                tables.append(tablename)
            elif tcg_tablename in tcg_table_set:
                tables.append(tcg_tablename)
            else:
                sets.append(tablename)
    else:
        tables = tcg_tables
        sets = None

    if tables:
        dex_load.load(session,
                      directory=options['--ptcg-csv-dir'],
                      drop_tables=options['--drop-tables'],
                      tables=tables,
                      verbose=options['--verbose'],
                      safe=options['--safe'],
                      recursive=False,
                      langs=[])
コード例 #2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    options = docopt(__doc__, argv=argv[1:])

    if not options['--verbose'] and not options['--quiet']:
        if options['export-card'] or options['export-set']:
            options['--verbose'] = False
        else:
            options['--verbose'] = True

    if not options['--ptcg-csv-dir']:
        options['--ptcg-csv-dir'] = os.path.join(os.path.dirname(__file__),
                                                 'data', 'csv')

    if options['help']:
        print __doc__

    elif options['setup']:
        from pokedex.db import load as dex_load
        session = make_session(options)
        if not options['--no-pokedex']:
            dex_load.load(session,
                          directory=options['--dex-csv-dir'],
                          drop_tables=True,
                          verbose=options['--verbose'],
                          safe=options['--safe'])
        load(session, options)

    elif options['load']:
        session = make_session(options)
        load(session, options)

    elif options['dump']:
        session = make_session(options)
        dump(session, options)

    elif options['import']:
        session = make_session(options)
        import_(session, options)

    elif options['export-card']:
        session = make_session(options)
        export(session, options)

    elif options['export-set']:
        session = make_session(options)
        export_set(session, options)

    else:
        exit('Subcommand not supported yet')
コード例 #3
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,
    )