Skip to content

Commit f6b203b

Browse files
authored
Merge pull request #127 from SaltieRL/rattletrapdownload
Rattletrapdownload
2 parents 7ed5275 + bd9bb0c commit f6b203b

16 files changed

+190
-56
lines changed

.coveragerc

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ exclude_lines =
1010
if __name__ == .__main__.:
1111
omit =
1212
tests/*
13+
carball/tests/*
14+
utils/tests/*
15+
init.py
16+
setup.py

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ venv/
66
output
77
.env
88
.coverage
9+
rattletrap*
910
*.iml

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ include requirements.txt
22
include carball/rattletrap/*
33
include carball/analysis/*
44
exclude carball/generated/*
5+
exclude carball/rattletrap/rattletrap*
56
recursive-include carball/generated/api *.py
67
recursive-include carball *.xlsx

carball/decompile_replays.py

-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import json
21
import os
3-
import subprocess
42
import logging
53
import platform as pt
64

@@ -25,16 +23,6 @@ def decompile_replay(replay_path, output_path: str=None, overwrite=True):
2523
:param overwrite: True if we should recreate the json even if it already exists.
2624
:return: The json created from rattle trap.
2725
"""
28-
binaries = [f for f in os.listdir(os.path.join(BASE_DIR, 'rattletrap')) if not f.endswith('.py')]
29-
platform = pt.system()
30-
if platform == 'Windows':
31-
binary = [f for f in binaries if f.endswith('.exe')][0]
32-
elif platform == 'Linux':
33-
binary = [f for f in binaries if 'linux' in f][0]
34-
elif platform == 'Darwin':
35-
binary = [f for f in binaries if 'osx' in f][0]
36-
else:
37-
raise Exception('Unknown platform, unable to process replay file.')
3826
return run_rattletrap.decompile_replay(replay_path, output_path)
3927

4028

carball/rattletrap/check_rattletrap_version.py

+37-21
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,40 @@
33
import json
44
from distutils.version import StrictVersion
55

6-
response = request.urlopen('https://api.github.com/repos/tfausak/rattletrap/releases/latest')
7-
8-
js = json.loads(response.read())
9-
10-
cur_ver = '0.0.0'
11-
binaries = [f for f in os.listdir('.') if not f.endswith('.py') and os.path.isfile(f)]
12-
print (binaries)
13-
if len(binaries) > 0:
14-
cur_ver = binaries[0].split('-')[1]
15-
update = StrictVersion(js['name']) > StrictVersion(cur_ver)
16-
print (f'GitHub version: {js["name"]}\n'
17-
f'Current version: {cur_ver}\n'
18-
f'Update? {update}')
19-
if update:
20-
for file in binaries:
21-
os.remove(file)
22-
23-
for asset in js['assets']:
24-
25-
print('Downloading {}'.format(asset['name']))
26-
request.urlretrieve(asset['browser_download_url'], asset['name'])
6+
from carball.rattletrap.rattletrap_utils import get_rattletrap_binaries, get_rattletrap_path
7+
8+
9+
def update_rattletrap():
10+
path = get_rattletrap_path()
11+
print('updating rattletrap in path', path)
12+
files = os.listdir(path)
13+
print('files in path', files)
14+
15+
cur_ver = '0.0.0'
16+
binaries = get_rattletrap_binaries(path)
17+
print('existing found', binaries)
18+
19+
response = request.urlopen('https://api.github.com/repos/tfausak/rattletrap/releases/latest')
20+
21+
js = json.loads(response.read())
22+
23+
if len(binaries) > 0:
24+
cur_ver = binaries[0].split('-')[1]
25+
update = StrictVersion(js['name']) > StrictVersion(cur_ver)
26+
print (f'GitHub version: {js["name"]}\n'
27+
f'Current version: {cur_ver}\n'
28+
f'Update? {update}')
29+
if update:
30+
for file in binaries:
31+
os.remove(file)
32+
33+
for asset in js['assets']:
34+
print('Downloading {}'.format(asset['name']))
35+
new_file = os.path.join(path, asset['name'])
36+
request.urlretrieve(asset['browser_download_url'], filename=new_file)
37+
print('making file executable', new_file)
38+
os.chmod(new_file, 0o777)
39+
40+
41+
if __name__ == "__main__":
42+
update_rattletrap()
-19.9 MB
Binary file not shown.
-9.33 MB
Binary file not shown.
-32.1 MB
Binary file not shown.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import inspect
2+
import os
3+
import fnmatch
4+
from typing import List, Union
5+
6+
7+
def get_rattletrap_path() -> Union[bytes, str]:
8+
filename = inspect.getframeinfo(inspect.currentframe()).filename
9+
path = os.path.dirname(os.path.abspath(filename))
10+
return path
11+
12+
13+
def get_rattletrap_binaries(path: Union[bytes, str]) -> List[Union[bytes, str]]:
14+
files = os.listdir(path)
15+
binaries = [f for f in files if not f.endswith('.py') and fnmatch.fnmatch(f, "*rattletrap*")]
16+
print(binaries)
17+
return binaries
18+
19+
20+
def download_rattletrap():
21+
from carball.rattletrap.check_rattletrap_version import update_rattletrap
22+
update_rattletrap()
23+
24+
25+
def get_binary_for_platform(platform, binaries):
26+
if platform == 'Windows':
27+
binary = [f for f in binaries if f.endswith('.exe')][0]
28+
elif platform == 'Linux':
29+
binary = [f for f in binaries if 'linux' in f][0]
30+
elif platform == 'Darwin':
31+
binary = [f for f in binaries if 'osx' in f][0]
32+
else:
33+
raise Exception('Unknown platform, unable to process replay file.')
34+
return binary

carball/rattletrap/run_rattletrap.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import inspect
12
import logging
23
import os
34
import subprocess
45
import json
56
import platform as pt
67
from typing import List
78

9+
from carball.rattletrap.rattletrap_utils import get_rattletrap_binaries, download_rattletrap, get_rattletrap_path, \
10+
get_binary_for_platform
11+
812
logger = logging.getLogger(__name__)
9-
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
1013

1114

1215
def create_rattletrap_command(replay_path: str, output_path: str, overwrite: bool=True) -> List[str]:
@@ -18,17 +21,16 @@ def create_rattletrap_command(replay_path: str, output_path: str, overwrite: boo
1821
:param overwrite: True if we should recreate the json even if it already exists.
1922
:return: The json created from rattle trap.
2023
"""
21-
binaries = [f for f in os.listdir(os.path.join(BASE_DIR, 'rattletrap')) if not f.endswith('.py')]
22-
platform = pt.system()
23-
if platform == 'Windows':
24-
binary = [f for f in binaries if f.endswith('.exe')][0]
25-
elif platform == 'Linux':
26-
binary = [f for f in binaries if 'linux' in f][0]
27-
elif platform == 'Darwin':
28-
binary = [f for f in binaries if 'osx' in f][0]
29-
else:
30-
raise Exception('Unknown platform, unable to process replay file.')
31-
cmd = [os.path.join(os.path.join(BASE_DIR, 'rattletrap'), '{}'.format(binary)), '--compact', '-i',
24+
rattletrap_path = get_rattletrap_path()
25+
binaries = get_rattletrap_binaries(rattletrap_path)
26+
if len(binaries) == 0:
27+
logger.warning("Need to redownload rattletrap")
28+
download_rattletrap()
29+
binaries = get_rattletrap_binaries(rattletrap_path)
30+
binary = get_binary_for_platform(pt.system(), binaries)
31+
if binary is None:
32+
print('no binary!')
33+
cmd = [os.path.join(rattletrap_path, '{}'.format(binary)), '--compact', '-i',
3234
replay_path]
3335
if output_path:
3436
output_dirs = os.path.dirname(output_path)

carball/tests/game_creation_test.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import unittest
22

33
from carball.analysis.analysis_manager import AnalysisManager
4-
from carball.analysis.constants.playlist import get_playlist_from_game, get_team_size_from_game
54

6-
from ..json_parser.game import Game
7-
from ..tests.utils import run_tests_on_list, run_analysis_test_on_replay, get_raw_replays
5+
from carball.json_parser.game import Game
6+
from carball.tests.utils import run_tests_on_list, run_analysis_test_on_replay, get_raw_replays
87

9-
from .. import decompile_replays
8+
from carball import decompile_replays
109

1110

1211
class DBTest(unittest.TestCase):

carball/tests/setup_tests.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import unittest
3+
4+
from carball.rattletrap.rattletrap_utils import get_rattletrap_binaries, get_rattletrap_path, download_rattletrap
5+
from carball.rattletrap.run_rattletrap import create_rattletrap_command
6+
from carball.rattletrap.check_rattletrap_version import update_rattletrap
7+
8+
9+
class setup_tests(unittest.TestCase):
10+
11+
def cleanup(self):
12+
path = get_rattletrap_path()
13+
binaries = get_rattletrap_binaries(get_rattletrap_path())
14+
15+
# clean out existing
16+
for binary in binaries:
17+
os.remove(os.path.join(path, binary))
18+
19+
def test_rattle(self):
20+
self.cleanup()
21+
22+
download_rattletrap()
23+
24+
def test_create_rattletrap_command(self):
25+
self.cleanup()
26+
27+
create_rattletrap_command('file.replay', 'outputdir')
28+
29+
# check post download
30+
create_rattletrap_command('file.replay', 'outputdir2')
31+
32+
def test_direct_check_version(self):
33+
self.cleanup()
34+
update_rattletrap()
35+
36+
#skip update
37+
update_rattletrap()
38+
39+
def test_get_correct_version_from_platform(self):
40+
path = get_rattletrap_path()
41+
binaries = get_rattletrap_binaries(get_rattletrap_path())

codecov.yml

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ coverage:
88
range: "70...100"
99

1010
status:
11-
project: yes
12-
patch: yes
11+
project:
12+
default:
13+
threshold: 1
14+
carball:
15+
threshold: 0.5
16+
paths:
17+
- "!carball/tests"
18+
- carball/*
19+
patch: off
1320
changes: no
1421

1522
parsers:

init.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
from utils.create_proto import create_proto_files
2-
from utils.import_fixer import convert_to_relative_imports
1+
def initalize_rattletrap():
2+
from carball.rattletrap.check_rattletrap_version import update_rattletrap
3+
try:
4+
update_rattletrap()
5+
except e:
6+
print('Issue adding rattletrap')
37

4-
5-
if __name__ == "__main__":
8+
def initialize_project():
9+
from utils.create_proto import create_proto_files
10+
from utils.import_fixer import convert_to_relative_imports
11+
612
create_proto_files()
713
convert_to_relative_imports()
14+
initalize_rattletrap()
15+
16+
if __name__ == "__main__":
17+
initialize_project()

setup.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import setuptools
44
from setuptools import setup
5+
from setuptools.command.develop import develop
6+
from setuptools.command.install import install
57
import os
68

79
with open(os.path.join('carball', 'analysis', 'PROTOBUF_VERSION'), 'r') as f:
@@ -16,6 +18,24 @@
1618
else:
1719
long_description = ''
1820

21+
22+
class PostDevelopCommand(develop):
23+
"""Post-installation for development mode."""
24+
def run(self):
25+
from init import initialize_project
26+
initialize_project()
27+
# this needs to be last
28+
develop.run(self)
29+
30+
class PostInstallCommand(install):
31+
"""Post-installation for installation mode."""
32+
def run(self):
33+
from init import initialize_project
34+
initialize_project()
35+
# this needs to be last
36+
install.run(self)
37+
38+
1939
setup(
2040
name='carball',
2141
version=version_string,
@@ -29,5 +49,9 @@
2949
author_email='[email protected]',
3050
description='Rocket League replay parsing and analysis.',
3151
long_description=long_description,
32-
exclude_package_data={'': ['.gitignore', '.git/*', '.git/**/*', 'replays/*']}
52+
exclude_package_data={'': ['.gitignore', '.git/*', '.git/**/*', 'replays/*']},
53+
cmdclass={
54+
'develop': PostDevelopCommand,
55+
'install': PostInstallCommand,
56+
},
3357
)

utils/tests/test_create_proto.py

+7
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ def test_is_not_windows(self, is_windows):
2626

2727
protoc_path = get_proto()
2828
self.assertTrue(protoc_path.endswith('protoc'))
29+
30+
def test_create_do_protos(self):
31+
from utils.create_proto import create_proto_files
32+
from utils.import_fixer import convert_to_relative_imports
33+
34+
create_proto_files()
35+
convert_to_relative_imports()

0 commit comments

Comments
 (0)