2021-04-26 19:16:27 +02:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
2021-04-27 19:16:08 +02:00
|
|
|
path = "./mods/"
|
|
|
|
# pattern = re.compile(r'^(?P<nomtableau>[^ \t\]]+)[ ]*=[ ]*\{')
|
2021-05-03 22:11:49 +02:00
|
|
|
pattern = re.compile(r'^(?P<nomtableau>[A-Za-z_0-9]+)[ ]*=[ ]*\{')
|
|
|
|
pattern_local = re.compile(r'local (?P<nomvar>[A-Za-z_0-9]+)')
|
2021-04-27 19:16:08 +02:00
|
|
|
|
2021-05-03 22:11:49 +02:00
|
|
|
global_vars = []
|
2021-04-26 19:16:27 +02:00
|
|
|
|
|
|
|
pathlist = Path(path).rglob('*.lua')
|
|
|
|
for path in pathlist:
|
|
|
|
path_in_str = str(path)
|
2021-04-27 19:16:08 +02:00
|
|
|
# print(path_in_str)
|
|
|
|
trouve = False
|
2021-04-26 19:16:27 +02:00
|
|
|
with open(path_in_str) as f:
|
2021-05-03 22:11:49 +02:00
|
|
|
variables_locales = []
|
2021-04-27 19:16:08 +02:00
|
|
|
for i, line in enumerate(f.readlines()):
|
|
|
|
m = pattern.match(line)
|
|
|
|
if m:
|
2021-05-03 22:11:49 +02:00
|
|
|
nomtableau = m.group('nomtableau')
|
|
|
|
if nomtableau not in variables_locales:
|
|
|
|
print(path_in_str, ":", i+1, ":", m.group('nomtableau').strip())
|
|
|
|
global_vars.append(m.group('nomtableau').strip())
|
|
|
|
trouve = True
|
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
n = pattern_local.match(line)
|
|
|
|
if n:
|
|
|
|
variables_locales.append(n.group('nomvar'))
|
|
|
|
|
2021-04-27 19:16:08 +02:00
|
|
|
if not trouve:
|
2021-05-03 22:11:49 +02:00
|
|
|
nb_varloc = len(variables_locales)
|
|
|
|
#print(path_in_str, ": -", "({} variables locales)".format(nb_varloc) if nb_varloc > 0 else '')
|
2021-04-26 19:16:27 +02:00
|
|
|
|
2021-05-03 22:11:49 +02:00
|
|
|
""" for subdir, dirs, files in os.walk(path):
|
2021-04-26 19:16:27 +02:00
|
|
|
for file in files:
|
|
|
|
print(os.path.join(subdir, file))
|
|
|
|
filepath = subdir + os.sep + file
|
|
|
|
if filepath.endswith(".lua"):
|
2021-05-03 22:11:49 +02:00
|
|
|
print(filepath) """
|
|
|
|
|
|
|
|
print(', '.join(['"{}"'.format(v) for v in global_vars]))
|