fix: prefer changelog over Game.ini in census sidecar scan
This commit is contained in:
1 parent
25eee44483
commit
cbe1848d10
5 files changed
+27
-10
No files matched your search
@@ -20,19 +20,21 @@ def _from_text(text: str) -> str | None:
|
|||||||
|
|
||||||
def _sidecar_version(file_path: str) -> str | None:
|
def _sidecar_version(file_path: str) -> str | None:
|
||||||
parent = os.path.dirname(file_path)
|
parent = os.path.dirname(file_path)
|
||||||
for name in os.listdir(parent) if os.path.isdir(parent) else []:
|
if not os.path.isdir(parent):
|
||||||
low = name.lower()
|
return None
|
||||||
if low in CHANGELOG_NAMES or low == "game.ini":
|
names = os.listdir(parent)
|
||||||
|
for name in names:
|
||||||
|
if name.lower() in CHANGELOG_NAMES:
|
||||||
with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh:
|
with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh:
|
||||||
text = fh.read()
|
found = _from_text(fh.read())
|
||||||
if low == "game.ini":
|
|
||||||
m = INI_VER.search(text)
|
|
||||||
if m:
|
|
||||||
return m.group(1).strip()
|
|
||||||
else:
|
|
||||||
found = _from_text(text)
|
|
||||||
if found:
|
if found:
|
||||||
return found
|
return found
|
||||||
|
for name in names:
|
||||||
|
if name.lower() == "game.ini":
|
||||||
|
with open(os.path.join(parent, name), encoding="utf-8", errors="ignore") as fh:
|
||||||
|
m = INI_VER.search(fh.read())
|
||||||
|
if m:
|
||||||
|
return m.group(1).strip()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _zip_version(file_path: str) -> str | None:
|
def _zip_version(file_path: str) -> str | None:
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[Game]
|
||||||
|
Title=Both Sidecars
|
||||||
|
Version=9.9.9
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Current Version: 3.3.1
|
||||||
Whitespace-only changes.
@@ -1,4 +1,5 @@
|
|||||||
import hashlib, os, sys, tempfile, unittest, zipfile
|
import hashlib, os, sys, tempfile, unittest, zipfile
|
||||||
|
from unittest.mock import patch
|
||||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||||
sys.path.insert(0, os.path.join(ROOT, "scripts"))
|
sys.path.insert(0, os.path.join(ROOT, "scripts"))
|
||||||
from update_swarm.census import census_job
|
from update_swarm.census import census_job
|
||||||
@@ -19,6 +20,16 @@ class TestCensus(unittest.TestCase):
|
|||||||
self.assertEqual(rec["installed_version"], "1.74.1")
|
self.assertEqual(rec["installed_version"], "1.74.1")
|
||||||
self.assertEqual(rec["source"], "file")
|
self.assertEqual(rec["source"], "file")
|
||||||
|
|
||||||
|
@patch(
|
||||||
|
"update_swarm.census.os.listdir",
|
||||||
|
return_value=["Game.ini", "changelog.txt", "dummy.bin"],
|
||||||
|
)
|
||||||
|
def test_sidecar_prefers_changelog_over_game_ini(self, _listdir):
|
||||||
|
rec = census_job(job("B"), os.path.join(FIX, "both-sidecars", "dummy.bin"))
|
||||||
|
self.assertEqual(rec["installed_version"], "3.3.1")
|
||||||
|
self.assertEqual(rec["source"], "file")
|
||||||
|
self.assertEqual(rec["evidence"], "sidecar")
|
||||||
|
|
||||||
def test_filename_token(self):
|
def test_filename_token(self):
|
||||||
rec = census_job(job("N"), os.path.join(FIX, "named", "Pokemon - Named [Hack][3.3.1].zip"))
|
rec = census_job(job("N"), os.path.join(FIX, "named", "Pokemon - Named [Hack][3.3.1].zip"))
|
||||||
self.assertEqual(rec["installed_version"], "3.3.1")
|
self.assertEqual(rec["installed_version"], "3.3.1")
|
||||||
|
|||||||
Reference in new issue
Block a user