def load_file(game_servers, local_file, remote_file, load_type='upload'):
test_server_info = get_test_server_info(GAME)
check_game_servers(game_servers, test_server_info)
locate_game_servers = transform_gameservers(game_servers, test_server_info)
ips = locate_game_servers.keys()
@hosts(ips)
def _upload_file():
upload(local_file, REMOTE_DIR, env.host_string)
for game_server in locate_game_servers[env.host_string]:
replace_file(game_server, remote_file)
@hosts(ips)
def _download_file():
for game_server in locate_game_servers[env.host_string]:
local_path = '{}/{}/'.format(local_root_path, game_server)
local('su - astd -c "mkdir -p {}"'.format(local_path))
target_file = '/app/{}/{}'.format(game_server, remote_file)
with quiet():
target_file_exists = run('test -f {}'.format(target_file)).succeeded
if target_file_exists:
get(target_file, local_path)
else:
raise Exception('File {} NOT exists on {}'.format(target_file, game_server))
local('chown -R astd.astd {}'.format(local_root_path))
if load_type == 'upload':
ftp_file_check(local_file)
file_name_consistence_check(local_file, remote_file)
execute(_upload_file)
print('{} was uploaded to {} successfully.'.format(local_file, game_servers))
elif load_type == 'download':
ftp_path = 'download/{}/{}'.format(GAME, TIMESTAMP)
local_root_path = '/app/online/{}'.format(ftp_path)
execute(_download_file)
print('Downloaded remote file: {} to FTP: {}/'.format(remote_file, ftp_path))
评论列表
文章目录