Skip to content

Commit

Permalink
Renamed console_log_interpreter.py to console_log.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Kataiser committed Jan 16, 2020
1 parent b19a244 commit 2df43bb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions TF2 Rich Presence/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main(version_num=None):
# copies stuff to the Github repo
if github_repo_path != 'n':
print("Copied", shutil.copy('main.py', Path(f'{github_repo_path}/TF2 Rich Presence')))
print("Copied", shutil.copy('console_log_interpreter.py', Path(f'{github_repo_path}/TF2 Rich Presence')))
print("Copied", shutil.copy('console_log.py', Path(f'{github_repo_path}/TF2 Rich Presence')))
print("Copied", shutil.copy('launcher.py', Path(f'{github_repo_path}/TF2 Rich Presence')))
print("Copied", shutil.copy('build.py', Path(f'{github_repo_path}/TF2 Rich Presence')))
print("Copied", shutil.copy('tests.py', Path(f'{github_repo_path}/TF2 Rich Presence')))
Expand Down Expand Up @@ -148,7 +148,7 @@ def main(version_num=None):
('DB_default.json', Path(f'{new_build_folder_name}/resources/')),
('LICENSE', Path(f'{new_build_folder_name}/resources/')),
('main.py', Path(f'{new_build_folder_name}/resources/')),
('console_log_interpreter.py', Path(f'{new_build_folder_name}/resources/')),
('console_log.py', Path(f'{new_build_folder_name}/resources/')),
('launcher.py', Path(f'{new_build_folder_name}/resources/')),
('Readme.txt', Path(f'{new_build_folder_name}/')),
('Launch TF2 with Rich Presence.bat', Path(f'{new_build_folder_name}/')),
Expand Down
2 changes: 1 addition & 1 deletion TF2 Rich Presence/build_version.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"v1.10.1": "58bbd2b9",
"v1.11": "9c941d15",
"v1.11.1": "1a0c9578",
"v1.11.2": "6385e51c"
"v1.11.2": "798d5e30"
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion TF2 Rich Presence/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def cleanup(self, max_logs: int):

# generates a short hash string from several source files
def generate_hash() -> str:
files_to_hash: List[str] = ['main.py', 'console_log_interpreter.py', 'configs.py', 'custom_maps.py', 'logger.py', 'updater.py', 'launcher.py', 'settings.py', 'detect_system_language.py',
files_to_hash: List[str] = ['main.py', 'console_log.py', 'configs.py', 'custom_maps.py', 'logger.py', 'updater.py', 'launcher.py', 'settings.py', 'detect_system_language.py',
'maps.json', 'localization.json', 'APIs']
files_to_hash_data: List = []
build_folder = [item for item in os.listdir('.') if item.startswith('TF2 Rich Presence v') and os.path.isdir(item)]
Expand Down
4 changes: 2 additions & 2 deletions TF2 Rich Presence/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import configs
import custom_maps
import console_log_interpreter
import console_log
import launcher
import localization
import logger
Expand Down Expand Up @@ -327,7 +327,7 @@ def loop_body(self):

# reads a console.log and returns current map and class
def interpret_console_log(self, *args, **kwargs) -> tuple:
return console_log_interpreter.interpret(self, *args, **kwargs)
return console_log.interpret(self, *args, **kwargs)

# generate text that displays the difference between now and old_time
def generate_delta(self, old_time: float) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ def interpret(self, console_log_path: str, user_usernames: list, kb_limit=settin
lines: List[str] = consolelog_file.readlines()
self.log.debug(f"console.log: {consolelog_file_size} bytes, {len(lines)} lines (didn't skip lines)")

# limit the file size, for readlines perf
if consolelog_file_size > byte_limit * 4 and settings.get('trim_console_log') and not force:
trim_size = byte_limit * 2
self.log.debug(f"Limiting console.log to {trim_size} bytes")

try:
with open(consolelog_filename, 'rb+') as consolelog_file:
# this can probably be done faster and/or cleaner
consolelog_file_trim = consolelog_file.read()[-trim_size:]
consolelog_file.seek(0)
consolelog_file.truncate()
consolelog_file.write(consolelog_file_trim)
except PermissionError as error:
self.log.error(f"Failed to trim console.log: {error}")

# iterates though roughly 16000 lines from console.log and learns everything from them
line_used: str = ''
for line in lines:
Expand Down
2 changes: 1 addition & 1 deletion TF2 Rich Presence/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_generate_hash(self):
old_dir = os.getcwd()
os.chdir(os.path.abspath('test_resources\\hash_targets'))

self.assertEqual(logger.generate_hash(), 'e3572e41')
self.assertEqual(logger.generate_hash(), '3cf1129d')

os.chdir(old_dir)

Expand Down

0 comments on commit 2df43bb

Please sign in to comment.