def create_rattletrap_command(replay_path: str, output_path: str, overwrite: bool = True, rattletrap_path: str = None) \ -> List[str]: """ Takes a path to the replay and outputs the json of that replay. :param replay_path: Path to a specific replay. :param output_path: The output path of rattletrap. :param overwrite: True if we should recreate the json even if it already exists. :param rattletrap_path: Custom location for rattletrap executable. :return: The json created from rattle trap. """ if rattletrap_path is None: rattletrap_path = get_rattletrap_path() binaries = get_rattletrap_binaries(rattletrap_path) if len(binaries) == 0: logger.warning("Need to redownload rattletrap") download_rattletrap() binaries = get_rattletrap_binaries(rattletrap_path) binary = get_binary_for_platform(pt.system(), binaries) if binary is None: logger.warning('no binary!') cmd = [ os.path.join(rattletrap_path, '{}'.format(binary)), '--compact', '-i', replay_path ] if output_path: output_dirs = os.path.dirname(output_path) if not os.path.isdir(output_dirs) and output_dirs != '': os.makedirs(output_dirs) if overwrite or not os.path.isfile(output_path): cmd += ['--output', output_path] return cmd
def cleanup(self): path = get_rattletrap_path() binaries = get_rattletrap_binaries(get_rattletrap_path()) # clean out existing for binary in binaries: os.remove(os.path.join(path, binary))
def update_rattletrap(): path = get_rattletrap_path() cur_ver = StrictVersion('0.0.0') binaries = get_all_binaries(path) try: response = request.urlopen( 'https://api.github.com/repos/tfausak/rattletrap/releases/latest') js = json.loads(response.read()) github_ver = StrictVersion(js['name']) except Exception: log.warning('Unable to download rattletrap copying backup') # unable to download a new rattletrap version so we should just copy our own github_ver = StrictVersion(cur_ver) copy_cloud_over_to_rattletrap(binaries) return if len(binaries) > 0: binary = get_highest_binary(binaries) if 'cloud' in binary: log.warning('Cloud parser is highest binary.') copy_cloud_over_to_rattletrap(binaries) cur_ver = get_binary_version(binary) update = github_ver > cur_ver log.info(f'GitHub version: {js["name"]}\n' f'Current version: {cur_ver}\n' f'Update? {update}') if update: for file in get_rattletrap_binaries(path): os.remove(os.path.join(path, file)) for asset in js['assets']: log.info('Downloading {}'.format(asset['name'])) new_file = os.path.join(path, asset['name']) request.urlretrieve(asset['browser_download_url'], filename=new_file) log.info('Making file executable: %s', new_file) os.chmod(new_file, 0o777)
def update_rattletrap(): path = get_rattletrap_path() cur_ver = '0.0.0' binaries = get_rattletrap_binaries(path) try: response = request.urlopen( 'https://api.github.com/repos/tfausak/rattletrap/releases/latest') js = json.loads(response.read()) github_ver = StrictVersion(js['name']) except: print('Unable to download rattletrap copying backup') # unable to download a new rattletrap version so we should just copy our own github_ver = StrictVersion(cur_ver) copyfile(os.path.join(get_rattletrap_path(), 'cloud_parser'), os.path.join(get_rattletrap_path(), 'rattletrap-linux')) os.chmod(os.path.join(get_rattletrap_path(), 'rattletrap-linux'), 0o777) return if len(binaries) > 0: cur_ver = binaries[0].split('-')[1] update = github_ver > StrictVersion(cur_ver) print(f'GitHub version: {js["name"]}\n' f'Current version: {cur_ver}\n' f'Update? {update}') if update: for file in binaries: os.remove(file) for asset in js['assets']: print('Downloading {}'.format(asset['name'])) new_file = os.path.join(path, asset['name']) request.urlretrieve(asset['browser_download_url'], filename=new_file) print('making file executable', new_file) os.chmod(new_file, 0o777)
def test_get_correct_version_from_platform(self): path = get_rattletrap_path() binaries = get_rattletrap_binaries(get_rattletrap_path())