ACE3/tools/search_privates.py

106 lines
3.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import fnmatch
import os
import re
import ntpath
2015-04-16 15:46:11 +00:00
import sys
import argparse
2015-04-16 15:46:11 +00:00
def get_private_declare(content):
priv_declared = []
srch = re.compile('private.*')
priv_srch_declared = srch.findall(content)
priv_srch_declared = sorted(set(priv_srch_declared))
priv_dec_str = ''.join(priv_srch_declared)
2015-04-16 16:48:21 +00:00
srch = re.compile('(?<![_a-zA-Z0-9])(_[a-zA-Z]*?)[ ,\}\]\)";]')
2015-04-16 15:46:11 +00:00
priv_split = srch.findall(priv_dec_str)
priv_split = sorted(set(priv_split))
priv_declared += priv_split;
2015-04-16 17:10:40 +00:00
srch = re.compile('PARAMS_[0-9].*|EXPLODE_[0-9]_PVT.*|DEFAULT_PARAM.*|KEY_PARAM.*')
2015-04-16 15:46:11 +00:00
priv_srch_declared = srch.findall(content)
priv_srch_declared = sorted(set(priv_srch_declared))
priv_dec_str = ''.join(priv_srch_declared)
2015-04-16 16:22:11 +00:00
srch = re.compile('(?<![_a-zA-Z0-9])(_[a-zA-Z]*?)[ ,\}\]\)";]')
2015-04-16 15:46:11 +00:00
priv_split = srch.findall(priv_dec_str)
priv_split = sorted(set(priv_split))
2015-04-16 15:46:11 +00:00
priv_declared += priv_split;
return priv_declared
def check_privates(filepath):
def pushClosing(t):
closingStack.append(closing.expr)
closing << Literal( closingFor[t[0]] )
def popClosing():
closing << closingStack.pop()
with open(filepath, 'r') as file:
content = file.read()
priv_use = []
priv_use = []
2015-04-16 15:46:11 +00:00
# Regex search privates
2015-04-16 16:54:52 +00:00
srch = re.compile('(?<![_a-zA-Z0-9])(_[a-zA-Z]*?)[ ,\}\]\)";]')
priv_use = srch.findall(content)
priv_use = sorted(set(priv_use))
# Private declaration search
2015-04-16 15:46:11 +00:00
priv_declared = get_private_declare(content)
if '_this' in priv_declared: priv_declared.remove('_this')
if '_this' in priv_use: priv_use.remove('_this')
if '_x' in priv_declared: priv_declared.remove('_x')
if '_x' in priv_use: priv_use.remove('_x')
if '_forEachIndex' in priv_declared: priv_declared.remove('_forEachIndex')
if '_forEachIndex' in priv_use: priv_use.remove('_forEachIndex')
2015-04-16 15:46:11 +00:00
if '_foreachIndex' in priv_declared: priv_declared.remove('_foreachIndex')
if '_foreachIndex' in priv_use: priv_use.remove('_foreachIndex')
missing = []
for s in priv_use:
if s not in priv_declared:
if s not in missing:
missing.append(s)
if len(missing) > 0:
2015-04-16 16:29:23 +00:00
print (filepath)
for bad_priv in missing:
2015-04-16 16:29:23 +00:00
print ('\t' + bad_priv)
def main():
print("#########################")
print("# Search your Privates #")
print("#########################")
sqf_list = []
parser = argparse.ArgumentParser()
parser.add_argument('-m','--module', help='only search specified module addon folder', required=False, default=".")
args = parser.parse_args()
for root, dirnames, filenames in os.walk('../addons' + '/' + args.module):
for filename in fnmatch.filter(filenames, '*.sqf'):
sqf_list.append(os.path.join(root, filename))
for filename in sqf_list:
check_privates(filename)
if __name__ == "__main__":
2015-04-16 16:29:23 +00:00
main()