35 lines
2.5 KiB
Python
35 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Install only the lock selector in a stopped sbtest farm; compile before publishing."""
|
|
import argparse,subprocess,shutil,json
|
|
from pathlib import Path
|
|
HERE=Path(__file__).resolve().parent
|
|
p=argparse.ArgumentParser(description=__doc__);p.add_argument('sbtest',type=Path);p.add_argument('backup',type=Path);a=p.parse_args()
|
|
sb=a.sbtest.resolve();q=sb/'share/locale/newcibn/quest';back=a.backup
|
|
if sb!=Path('/usr/metin2/server/sbtest') or not str(q.resolve()).startswith(str(sb)+'/'):raise SystemExit('requires isolated sbtest quest directory')
|
|
ports=subprocess.check_output(['sockstat','-4','-l']).decode()
|
|
if any(':'+port+' ' in ports for port in ('13040','15040')):raise SystemExit('stop sbtest game and db first')
|
|
if back.exists():raise SystemExit('use a fresh backup directory')
|
|
back.mkdir(parents=True);stage=back/'stage';stage.mkdir()
|
|
raw=(HERE/'attr_lock.quest').read_text()
|
|
if any(ch.encode('gbk')[-1:]==b'\\' for ch in raw if ord(ch)>127):raise SystemExit('GBK trail backslash in quest text')
|
|
(stage/'attr_lock.quest').write_bytes(raw.encode('gbk'))
|
|
functions=(q/'quest_functions').read_bytes().rstrip()+b'\n'
|
|
if b'item.select_attr_lock' not in functions.splitlines():functions+=b'item.select_attr_lock\n'
|
|
(stage/'quest_functions').write_bytes(functions)
|
|
with (back/'qc.log').open('wb') as log:subprocess.run([str(q/'qc'),'attr_lock.quest'],cwd=stage,stdout=log,stderr=subprocess.STDOUT,check=True)
|
|
if not (stage/'object/state/attr_lock').is_file():raise SystemExit('no compiled state')
|
|
for name in ('quest_functions','locale_list','attr_lock.quest'):
|
|
if (q/name).exists():shutil.copy2(q/name,back/name)
|
|
for path in (q/'object').rglob('*'):
|
|
if path.is_file() and (path.name.startswith('attr_lock.') or path.relative_to(q/'object').as_posix()=='state/attr_lock'):
|
|
dest=back/'object'/path.relative_to(q/'object');dest.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(path,dest);path.unlink()
|
|
manifest=[]
|
|
for path in (stage/'object').rglob('*'):
|
|
if path.is_file():
|
|
rel=path.relative_to(stage/'object');dest=q/'object'/rel;dest.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(path,dest);manifest.append(rel.as_posix())
|
|
shutil.copy2(stage/'attr_lock.quest',q/'attr_lock.quest');(q/'quest_functions').write_bytes(functions)
|
|
listing=(q/'locale_list').read_bytes().rstrip()+b'\n'
|
|
if b'attr_lock.quest' not in listing.splitlines():listing+=b'attr_lock.quest\n'
|
|
(q/'locale_list').write_bytes(listing);(back/'new-objects.json').write_text(json.dumps(manifest,indent=2)+'\n')
|
|
print('lock selector installed; restart sbtest to load; backup:',back)
|