Skip to content
Snippets Groups Projects
Commit adc817e1 authored by FarawayVision's avatar FarawayVision
Browse files

Add a CI step for automatically filling in linecount and posecount metadata

parent 9e54a0fd
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,9 @@ pages:
- sed "s/__CI_COMMIT_SHA/${CI_COMMIT_SHA}/g" prod-config.xml > .public/config.xml
- cp opponents/listing.xml .public/opponents
- cp opponents/general_collectibles.xml .public/opponents
- pip install beautifulsoup4
- find `python opponents/list_opponents.py` -iname "*.png" -o -iname "*.gif" -o -iname "*.jpg" -o -iname "*.xml" -o -iname "*.js" -o -iname "*.css" | tar -cT - | tar -C .public -x
- python3 opponents/fill_linecount_metadata.py .public/opponents
- python opponents/gzip_dialogue.py .public/opponents/*/behaviour.xml
- python opponents/analyze_image_space.py .public/opponents
- python opponents/copy_event_alts.py .public/ ./ easter
......
from __future__ import print_function
import os
import os.path as osp
from bs4 import BeautifulSoup
import shutil
import stat
import sys
def process(opponent_folder_path):
opponent = osp.basename(opponent_folder_path)
behaviour_path = osp.join(opponent_folder_path, 'behaviour.xml')
meta_path = osp.join(opponent_folder_path, 'meta.xml')
if not osp.exists(behaviour_path) or not osp.exists(meta_path):
return
with open(meta_path, 'r', encoding='utf-8') as f:
meta_soup = BeautifulSoup(f.read())
if meta_soup.opponent.lines is not None or meta_soup.opponent.poses is not None:
return
with open(behaviour_path, 'r', encoding='utf-8') as f:
soup = BeautifulSoup(f.read())
all_lines = set()
all_poses = set()
for state in soup.find_all('state', recursive=True):
pose = state.get('img', '')
all_poses.add(pose)
dialogue = ''.join(str(child) for child in state.stripped_strings).strip()
all_lines.add(dialogue)
n_unique_lines = len(all_lines)
n_poses = len(all_poses)
print(opponent+":")
print(" - "+str(n_unique_lines)+" lines")
print(" - "+str(n_poses)+" poses")
linecount_tag = soup.new_tag('lines')
linecount_tag.string = str(n_unique_lines)
posecount_tag = soup.new_tag('poses')
posecount_tag.string = str(n_poses)
meta_soup.opponent.append(linecount_tag)
meta_soup.opponent.append(posecount_tag)
with open(meta_path, 'w', encoding='utf-8') as f:
f.write(str(meta_soup))
for arg in sys.argv[1:]:
for name in os.listdir(arg):
path = osp.join(arg, name)
if osp.isdir(path):
process(path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment