Travis span matcher script

A slightly overkill script to ensure each file contains as many opening span tags as closing.
Almost implemented to allow checking multiple pairs of tags.
This commit is contained in:
PsiOmega
2015-06-14 17:32:56 +02:00
parent a006089b2a
commit 90c71d00f1
3 changed files with 45 additions and 1 deletions

View File

@@ -26,5 +26,6 @@ script:
- (! find nano/templates/ -type f -exec md5sum {} + | sort | uniq -D -w 32 | grep nano)
- (num=`grep -E '\\\\(red|blue|green|black|b|i[^mc])' **/*.dm | wc -l`; [ $num -le 1355 ])
- ( md5sum -c - <<< "0af969f671fba6cf9696c78cd175a14a *baystation12.int")
- DreamMaker baystation12.dme
- python tools/TagMatcher/tag-matcher.py ../..
- python tools/GenerateChangelog/ss13_genchangelog.py html/changelog.html html/changelogs
- DreamMaker baystation12.dme

View File

@@ -0,0 +1,3 @@
@echo off
call python tag-matcher.py ../..
pause

View File

@@ -0,0 +1,40 @@
import argparse, re, sys
from os import path, walk
opt = argparse.ArgumentParser()
opt.add_argument('dir', help='The directory to scan for files with non-matching spans')
args = opt.parse_args()
if(not path.isdir(args.dir)):
print('Not a directory')
sys.exit(1)
pair_of_tags = [('<span(.*?)>','</span>')]
mismatches = { }
for root, subdirs, files in walk(args.dir):
for filename in files:
if filename.endswith('.dm'):
open_match = 0
close_match = 0
file_path = path.join(root, filename)
with open(file_path, 'r') as f:
open_span = re.compile(pair_of_tags[0][0], re.IGNORECASE)
close_span = re.compile(pair_of_tags[0][1], re.IGNORECASE)
for x in f:
open_match += len(open_span.findall(x))
close_match += len(close_span.findall(x))
if open_match != close_match:
if not pair_of_tags[0][0] in mismatches.keys():
mismatches[pair_of_tags[0][0]] = []
mismatches[pair_of_tags[0][0]].append('{0} - {1}/{2}'.format(file_path, open_match, close_match))
for mismatch_key in mismatches.keys():
print(mismatch_key)
for mismatch_value in mismatches[mismatch_key]:
print('\t{0}').format(mismatch_value)
if len(mismatches.keys()) > 0:
sys.exit(1)