Example #1
0
def save_and_sync_next_step(old_set):
    name_set = None
    start_time = time.time()
    stop = False
    while not stop:
        print 'finding save...'
        dir = save.get_save_dir()
        listing = list_saves(dir)
        new_set = set(listing)
        name_set = new_set - old_set
        if not name_set:
            for name in listing:
                mtime = os.path.getmtime(os.path.join(dir, name))
                if mtime > start_time:
                    stop = True
                    break
            time.sleep(0.5)
        else:
            stop = True
            name = iter(name_set).next()
            break
    print 'found save', name
    time.sleep(0.5)
    ui.execute_later(
        lambda: upload_save(save.get_save_dir() + '/' + name, name))
Example #2
0
def main(size=None, init=True):
    features.FEATURE_FILE_PATH = os.path.join(save.get_save_dir(), 'features')
    features.parse_options()
    setup_game_version()
    setup_android_version()
    setup_errors()
    size = size or check_force_size()

    maybe_start_remote_debug()

    monitor.start()

    client.window.init_screen(size)
    osutil.init()

    ui.init()
    ui.set_fill_image(None)
    unpack_data()
    ui.set_fill_image(pygame.image.load('data/user/background.jpg'))

    setup_freeciv_config()
    client.window.init()
    gamescreen.init()

    start_autoupdate()

    if init:
        client.freeciv.run()
    else:
        client_main()
Example #3
0
def setup_freeciv_config():
    path = os.environ['FREECIV_OPT'] = save.get_save_dir() + '/civrc-2.3-1'
    try:
        if not os.path.exists(path):
            shutil.copy('data/civrc-2.3-default', path)
    except (IOError, OSError):
        pass
Example #4
0
def get_resume_data():
    try:
        content = open(pause_file).read()
    except IOError:
        return None
    else:
        return os.path.join(save.get_save_dir(), 'pause_save.sav.gz')
Example #5
0
def setup_freeciv_config():
    path = os.environ['FREECIV_OPT'] = save.get_save_dir() + '/civrc-2.3-1'
    try:
        if not os.path.exists(path):
            shutil.copy('data/civrc-2.3-default', path)
    except (IOError, OSError):
        pass
Example #6
0
def main():
    features.FEATURE_FILE_PATH = os.path.join(save.get_save_dir(), 'features')
    features.parse_options()
    setup_game_version()
    setup_android_version()
    setup_errors()

    maybe_start_remote_debug()

    monitor.start()
    save.start_zygote()

    client.window.init_screen()
    osutil.init()

    ui.init()
    ui.set_fill_image(graphics.load_image('data/user/background.jpg'))

    setup_freeciv_config()
    client.window.init()
    gamescreen.init()

    start_autoupdate()
    start_marketnotice()

    client.freeciv.run()
Example #7
0
def get_resume_data():
    try:
        content = open(pause_file).read()
    except IOError:
        return None
    else:
        return os.path.join(save.get_save_dir(), 'pause_save.sav.gz')
Example #8
0
def main():
    features.FEATURE_FILE_PATH = os.path.join(save.get_save_dir(), 'features')
    features.parse_options()
    setup_game_version()
    setup_android_version()
    setup_errors()

    maybe_start_remote_debug()

    monitor.start()
    save.start_zygote()

    client.window.init_screen()
    osutil.init()

    ui.init()
    ui.set_fill_image(graphics.load_image('data/user/background.jpg'))

    setup_freeciv_config()
    client.window.init()
    gamescreen.init()

    start_autoupdate()
    start_marketnotice()

    client.freeciv.run()
Example #9
0
def main(size=None, init=True):
    features.FEATURE_FILE_PATH = os.path.join(save.get_save_dir(), 'features')
    features.parse_options()
    setup_game_version()
    setup_android_version()
    setup_errors()    
    size = size or check_force_size()
    
    maybe_start_remote_debug()
    
    monitor.start()
    
    client.window.init_screen(size)
    osutil.init()
    
    ui.init()
    ui.set_fill_image(None)
    unpack_data()
    ui.set_fill_image(pygame.image.load('data/user/background.jpg'))
    
    setup_freeciv_config()
    client.window.init()
    gamescreen.init()
    
    start_autoupdate()
    
    if init:
        client.freeciv.run()
    else:
        client_main()
Example #10
0
def get_install_time():
    path = os.path.join(save.get_save_dir(), 'install_time')
    try:
        return int(open(path).read())
    except (IOError, ValueError):
        install_time = int(time.time() * 1000)
        with open(path, 'w') as f:
            f.write('%d' % install_time)
    return install_time
Example #11
0
def get_install_time():
    path = os.path.join(save.get_save_dir(), 'install_time')
    try:
        return int(open(path).read())
    except (IOError, ValueError):
        install_time = int(time.time() * 1000)
        with open(path, 'w') as f:
            f.write('%d' % install_time)
    return install_time
Example #12
0
def comment_upload(install_time):
    ui.execute_later(lambda: ui.message('Compressing log...'))

    content = lzma.compress(open(save.get_save_dir() + '/more.log').read())

    ui.execute_later(lambda: ui.back())

    request(lambda result: comment_next(install_time), 'upload_log', content, install_time,
            banner="Uploading log (%dkB)" % (len(content)/1024))
Example #13
0
def client():
    global session

    if not session:
        try:
            sessid = open(save.get_save_dir() + '/civsync.sessid.txt').read().strip()
        except IOError:
            sessid = None
        session = civsync.Session(sessid)

    return session
Example #14
0
def comment_upload(install_time):
    ui.execute_later(lambda: ui.message('Compressing log...'))

    content = lzma.compress(open(save.get_save_dir() + '/more.log').read())

    ui.execute_later(lambda: ui.back())

    request(lambda result: comment_next(install_time),
            'upload_log',
            content,
            install_time,
            banner="Uploading log (%dkB)" % (len(content) / 1024))
Example #15
0
def client():
    global session

    if not session:
        try:
            sessid = open(save.get_save_dir() +
                          '/civsync.sessid.txt').read().strip()
        except IOError:
            sessid = None
        session = civsync.Session(sessid)

    return session
Example #16
0
def downloaded(data):
    ui.set_dialog(ui.Label('Loading save...'))
    uncompressed = lzma.decompress(data)
    print 'Uncompressed size', len(uncompressed)
    dl_path = save.get_save_dir() + '/downloaded_save'
    try:
        os.remove(dl_path)
    except OSError:
        print 'not removed...'
    with open(dl_path, 'wb') as f:
        f.write(uncompressed)
    ui.back(anim=False)
    save.load_game(dl_path)
Example #17
0
def downloaded(data):
    ui.set_dialog(ui.Label('Loading save...'))
    uncompressed = lzma.decompress(data)
    print 'Uncompressed size', len(uncompressed)
    dl_path = save.get_save_dir() + '/downloaded_save'
    try:
        os.remove(dl_path)
    except OSError:
        print 'not removed...'
    with open(dl_path, 'wb') as f:
        f.write(uncompressed)
    ui.back(anim=False)
    save.load_game(dl_path)
Example #18
0
def downloaded(data):
    ui.set_dialog(ui.Label("Loading save..."))
    uncompressed = lzma.decompress(data)
    print "Uncompressed size", len(uncompressed)
    dl_path = save.get_save_dir() + "/downloaded_save"
    try:
        os.remove(dl_path)
    except OSError:
        print "not removed..."
    with open(dl_path, "wb") as f:
        f.write(uncompressed)
    ui.back(anim=False)
    save.load_game(dl_path)
Example #19
0
def save_and_sync_next_step(old_set):
    name_set = None
    start_time = time.time()
    stop = False
    while not stop:
        print 'finding save...'
        dir = save.get_save_dir()
        listing = list_saves(dir)
        new_set = set(listing)
        name_set = new_set - old_set
        if not name_set:
            for name in listing:
                mtime = os.path.getmtime(os.path.join(dir, name))
                if mtime > start_time:
                    stop = True
                    break
            time.sleep(0.5)
        else:
            stop = True
            name = iter(name_set).next()
            break
    print 'found save', name
    time.sleep(0.5)
    ui.execute_later.append(lambda: upload_save(save.get_save_dir() + '/' + name, name))
Example #20
0
def comment_upload(install_time):
    with ui.execute_later_lock:
        ui.execute_later.append(lambda: ui.message("Compressing log..."))

    content = lzma.compress(open(save.get_save_dir() + "/more.log").read())

    with ui.execute_later_lock:
        ui.execute_later.append(lambda: ui.back())

    request(
        lambda result: comment_next(install_time),
        "upload_log",
        content,
        install_time,
        banner="Uploading log (%dkB)" % (len(content) / 1024),
    )
Example #21
0
def pause():
    if client.client:
        print 'pause occured'
        print 'saving game'
        client.client.chat('/save %s/pause_save.sav.gz' % save.get_save_dir())
        with open(pause_file, 'w') as f:
            f.write('version=1\n')
        time.sleep(featues.get('app.shutdown'))
        if not osutil.is_paused():
            remove_pause_file()
            return
        print 'turning off server'
        client.client.disconnect()
        ui.back(allow_override=False)
        osutil.wait_for_resume()
        resume()
    else:
        osutil.wait_for_resume()
Example #22
0
def pause():
    if client.client:
        print "pause occured"
        print "saving game"
        client.client.chat("/save %s/pause_save.sav.gz" % save.get_save_dir())
        with open(pause_file, "w") as f:
            f.write("version=1\n")
        time.sleep(features.get("app.shutdown"))
        if not osutil.is_paused():
            remove_pause_file()
            return
        print "turning off server"
        client.client.disconnect()
        ui.back(allow_override=False)
        osutil.wait_for_resume()
        resume()
    else:
        osutil.wait_for_resume()
Example #23
0
def pause():
    if client.client:
        print 'pause occured'
        print 'saving game'
        client.client.chat('/save %s/pause_save.sav.gz' % save.get_save_dir())
        with open(pause_file, 'w') as f:
            f.write('version=1\n')
        time.sleep(features.get('app.shutdown'))
        if not osutil.is_paused():
            remove_pause_file()
            return
        print 'turning off server'
        client.client.disconnect()
        ui.back(allow_override=False)
        osutil.wait_for_resume()
        resume()
    else:
        osutil.wait_for_resume()
Example #24
0
features.add_feature('app.autoupdate', default=True, type=bool)
features.add_feature('app.forcesize')
features.add_feature('app.resume', default=True, type=bool)
features.add_feature('app.profile', default=False, type=bool)
features.add_feature('app.shutdown', default=10, type=int)
features.add_feature('app.multiplayer', default=False, type=bool)

def apply_hardexit(t):
    client.freeciv.hard_exit = t

features.set_applier('app.hardexit', apply_hardexit, type=bool, default=True)

main_menu = None
main_menu_update_shown = False

pause_file = os.path.join(save.get_save_dir(), 'pause_options')

def client_main():
    action = sys.argv[1] if sys.argv[1:] else None
    if try_resume():
        ui.main()
        return
    
    if action == 'load':
        savename = sys.argv[2]
        save.load_game(savename)
    elif action == 'connect':
        host, port = sys.argv[2:]
        save.connect(host, int(port))
    else:
        show_main_menu()
Example #25
0
 def logged(result):
     print 'Login successful'
     with open(save.get_save_dir() + '/civsync.sessid.txt', 'w') as f:
         f.write(session.sessid)
     callback()
Example #26
0
def save_and_sync(client):
    old_set = set(list_saves(save.get_save_dir()))
    client.chat('/save')
    ui.back()
    threading.Thread(target=save_and_sync_next_step, args=(old_set, )).start()
Example #27
0
features.add_feature('debug.dsn',
                     default=DESK_DSN if osutil.is_desktop else ANDR_DSN,
                     type=bool)


def apply_hardexit(t):
    client.freeciv.hard_exit = t


features.set_applier('app.hardexit', apply_hardexit, type=bool, default=True)

main_menu = None
main_menu_update_shown = False

pause_file = os.path.join(save.get_save_dir(), 'pause_options')


def client_main():
    if try_resume():
        ui.main()
        return

    ui.set(ui.Label('loading...'))
    ui.execute_later(app_main)

    if features.get('app.profile'):
        profile_main()
    else:
        ui.main()
def get_download_path():
    return _save.get_save_dir() + '/from-dropbox.sav'
Example #29
0
def save_and_sync(client):
    old_set = set(list_saves(save.get_save_dir()))
    client.chat('/save')
    ui.back()
    threading.Thread(target=save_and_sync_next_step, args=(old_set, )).start()
Example #30
0
def get_download_path():
    return _save.get_save_dir() + '/from-dropbox.sav'
Example #31
0
 def logged(result):
     print "Login successful"
     with open(save.get_save_dir() + "/civsync.sessid.txt", "w") as f:
         f.write(session.sessid)
     ui.back(anim=False)
     callback()
Example #32
0
 def logged(result):
     print 'Login successful'
     with open(save.get_save_dir() + '/civsync.sessid.txt', 'w') as f:
         f.write(session.sessid)
     callback()