From ccff77a2648ddabc714cfb44443cf812679b77fb Mon Sep 17 00:00:00 2001 From: Robert Bost Date: Mon, 12 Feb 2024 13:53:25 -0700 Subject: [PATCH] lint --- src/palworld_exporter/collectors/util.py | 19 +++++++++++-------- src/test/collectors/test_util.py | 10 ++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/palworld_exporter/collectors/util.py b/src/palworld_exporter/collectors/util.py index b88aa52..818606c 100644 --- a/src/palworld_exporter/collectors/util.py +++ b/src/palworld_exporter/collectors/util.py @@ -1,17 +1,18 @@ -from glob import glob import logging import os import re +from glob import glob server_name_re = re.compile(r'^DedicatedServerName=(?P.*?)$') + def find_server_name(filename: str) -> str | None: with open(filename, 'r') as f: - for l in f.readlines(): - m = server_name_re.search(l) + for line in f.readlines(): + m = server_name_re.search(line) if m: return m.group("name") - + def find_save_directory(starting_dir: str) -> str: # First, look for a single Level.sav @@ -26,11 +27,12 @@ def find_save_directory(starting_dir: str) -> str: logging.warning("No Level.sav found") elif len(result) > 1: logging.warning("Multiple Level.sav found") - + logging.warning("Searching GameUserSettings.ini for save directory") - # Second, try using the GameUserSettings.ini to figure out the right - game_settings_search = os.path.join(starting_dir, "**/GameUserSettings.ini") + # Second, try using the GameUserSettings.ini to figure out the right + game_settings_search = os.path.join( + starting_dir, "**/GameUserSettings.ini") result = glob(game_settings_search, recursive=True) if len(result) == 1: # Found settings so identify the save directory name @@ -46,4 +48,5 @@ def find_save_directory(starting_dir: str) -> str: elif len(result) == 0: raise FileNotFoundError("No GameUserSettings.ini found") elif len(result) > 1: - raise ValueError("Multiple GameUserSettings.ini found. Please use more specific directory.") + raise ValueError( + "Multiple GameUserSettings.ini found. Please use more specific directory.") diff --git a/src/test/collectors/test_util.py b/src/test/collectors/test_util.py index b3298aa..24c1d49 100644 --- a/src/test/collectors/test_util.py +++ b/src/test/collectors/test_util.py @@ -7,7 +7,7 @@ class UtilTestCase(TestCase): def setUp(self): self.setUpPyfakefs() - + def test_valid_direct_path(self): dir = "/Pal/Saved/SaveGames/0/F0951AC10BED42C6B0EA92ACABB01E95" self.fs.create_dir(dir) @@ -15,7 +15,7 @@ def test_valid_direct_path(self): found = find_save_directory(dir) assert found == dir - + def test_valid_indirect_path(self): dir = "/Pal/Saved/SaveGames/0/F0951AC10BED42C6B0EA92ACABB01E95" self.fs.create_dir(dir) @@ -37,15 +37,13 @@ def test_valid_has_settings_ini(self): bHasAppliedUserSetting=False DedicatedServerName=2FAAC44DFD3E4DA18C418EE1F577A560 """) - + found = find_save_directory(dir) assert save_dir == found - - def test_invalid_no_settings_ini(self): dir = "/empty/directory" self.fs.create_dir(dir) - + with pytest.raises(FileNotFoundError): find_save_directory(dir)