示例#1
0
def download_game(game, nocache=False):
    targetDir = config.GameArchives / game.source

    src_plugin = GameSource(game.source)
    downloadOptions = {}
    if hasattr(src_plugin, 'download_options'):
        downloadOptions = src_plugin.download_options(game)

    if hasattr(src_plugin, 'game_file_url'):
        log.debug(
            'game_file_url is not static, calling plugin:%s' % src_plugin)
        gameUrl = src_plugin.game_file_url(game)
    else:
        gameUrl = game.game_file_url
    assert gameUrl

    downloader = Downloader(cached=not nocache)
    print 'downloading %s...' % game.name,
    sys.stdout.flush()

    game.zip = downloader.download(gameUrl, targetDir, **downloadOptions)
    print 'OK'
    # downloader = DownloaderFactory.createDownloader(not nocache)
    # def game_downloader(game, targetDir, downloader):
    #    gameUrl = game.game_file_url
    #    game.zip = downloader.downloadFile(gameUrl, targetDir,
    #                                       downloadOptions=downloadOptions)
    # if src_plugin.game_downloader:
    #    game_downloader = src_plugin.game_downloader
    # game_downloader(game, targetDir, downloader)

    db.save_game(game)
示例#2
0
def update_game(source, id, force=False, sleep_between_downloads=0):
    if not force:
        game = db.load_game_by_key(source, id, ignore_empty=False)
        if game:
            print 'up-to-date %s/%d...' % (source, int(id))
            return game
    else:
        print 'force',
    print 'updating %s/%d...' % (source, int(id)),
    sys.stdout.flush()

    if sleep_between_downloads:
        print  'sleeping %s sec...' % sleep_between_downloads,
        sys.stdout.flush()
        time.sleep(sleep_between_downloads)

    game = parse_game(source, id)
    if game:
        print 'found:"' + game.name + '"...',
        db.save_game(game)
    else:
        print 'no game found...',
        g = Game()
        g.source = source
        g.id = id
        db.save_game(g)

    print 'OK'
    return game
示例#3
0
def download_game(game, nocache=False):
    targetDir = config.GameArchives / game.source

    src_plugin = GameSource(game.source)
    downloadOptions = {}
    if hasattr(src_plugin, 'download_options'):
        downloadOptions = src_plugin.download_options(game)

    if hasattr(src_plugin, 'game_file_url'):
        log.debug('game_file_url is not static, calling plugin:%s' %
                  src_plugin)
        gameUrl = src_plugin.game_file_url(game)
    else:
        gameUrl = game.game_file_url
    assert gameUrl

    downloader = Downloader(cached=not nocache)
    print 'downloading %s...' % game.name,
    sys.stdout.flush()

    game.zip = downloader.download(gameUrl, targetDir, **downloadOptions)
    print 'OK'
    # downloader = DownloaderFactory.createDownloader(not nocache)
    # def game_downloader(game, targetDir, downloader):
    #    gameUrl = game.game_file_url
    #    game.zip = downloader.downloadFile(gameUrl, targetDir,
    #                                       downloadOptions=downloadOptions)
    # if src_plugin.game_downloader:
    #    game_downloader = src_plugin.game_downloader
    # game_downloader(game, targetDir, downloader)

    db.save_game(game)
示例#4
0
def unpack_game(game, removezip=False):
    targetDir = config.GAMES / game.source / convertToFileName(
        game.name) + '.' + str(game.id)

    print 'unpacking %s...' % game.name,
    sys.stdout.flush()

    pyunpack.Archive(game.zip).extractall(targetDir, auto_create_dir=True)
#    if msg:
#        return False
    print 'OK'
    if removezip:
        os.remove(game.zip)
    game.dir = targetDir
    db.save_game(game)
    return True
示例#5
0
def unpack_game(game, removezip=False):
    targetDir = config.GAMES / game.source / convertToFileName(
        game.name) + '.' + str(game.id)

    print 'unpacking %s...' % game.name,
    sys.stdout.flush()

    pyunpack.Archive(game.zip).extractall(targetDir, auto_create_dir=True)
    #    if msg:
    #        return False
    print 'OK'
    if removezip:
        os.remove(game.zip)
    game.dir = targetDir
    db.save_game(game)
    return True
def save_game(game, game_id):
    db.save_game(game_id, game_to_save_blob(game))