mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2024-09-09 09:51:34 -07:00
prequeue: dont initialize a new preprocessor for each file
This commit is contained in:
parent
9eb2cf3d21
commit
94052ab5b9
@ -51,17 +51,16 @@ def load_pokecrystal_macros():
|
||||
|
||||
return ourmacros
|
||||
|
||||
def preprocess(config, macros, lines=None):
|
||||
"""
|
||||
Entry point for the preprocessor.
|
||||
"""
|
||||
processor = preprocessor.Preprocessor(config, macros)
|
||||
return processor.preprocess(lines=lines)
|
||||
|
||||
def main():
|
||||
def setup_processor():
|
||||
config = configuration.Config()
|
||||
macros = load_pokecrystal_macros()
|
||||
return preprocess(config, macros)
|
||||
processor = preprocessor.Preprocessor(config, macros)
|
||||
return processor
|
||||
|
||||
def main():
|
||||
processor = setup_processor()
|
||||
processor.preprocess()
|
||||
processor.update_globals
|
||||
|
||||
# only run against stdin when not included as a module
|
||||
if __name__ == "__main__":
|
||||
|
25
prequeue.py
25
prequeue.py
@ -8,24 +8,33 @@ a single process.
|
||||
import os
|
||||
import sys
|
||||
|
||||
import extras.pokemontools.configuration as configuration
|
||||
|
||||
import preprocessor
|
||||
|
||||
def main():
|
||||
config = configuration.Config()
|
||||
macros = preprocessor.load_pokecrystal_macros()
|
||||
def preprocess_queue(filenames=sys.argv[1:]):
|
||||
|
||||
stdin = sys.stdin
|
||||
stdout = sys.stdout
|
||||
|
||||
for source in sys.argv[1:]:
|
||||
processor = preprocessor.setup_processor()
|
||||
|
||||
for source in filenames:
|
||||
dest = os.path.splitext(source)[0] + '.tx'
|
||||
sys.stdin = open(source, 'r')
|
||||
sys.stdout = open(dest, 'w')
|
||||
preprocessor.preprocess(config, macros)
|
||||
processor.preprocess()
|
||||
|
||||
# reset stdout
|
||||
processor.update_globals()
|
||||
|
||||
sys.stdin = stdin
|
||||
sys.stdout = stdout
|
||||
|
||||
def main():
|
||||
filenames = list(set(sys.argv[1:]))
|
||||
if filenames:
|
||||
num_files = len(filenames)
|
||||
s = '' if num_files == 1 else 's'
|
||||
sys.stdout.write('Preprocessing {0} file{1}...\n'.format(num_files, s))
|
||||
preprocess_queue(filenames)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user