Add preprocessor macros to the wiki grabber.

This allows to copy information about widgets at three places without
copy pasting and it's bugs. The three places are:

- In the widget overview list

- In the widget definition info

- In the widget instanciate info
This commit is contained in:
Mark de Wever 2009-07-19 18:45:28 +00:00
parent ffcb31b84f
commit 5df10f06cb
2 changed files with 82 additions and 2 deletions

View file

@ -35,6 +35,7 @@ Version 1.7.1+svn:
* Allow items to be removed from a listbox
* Fixed objective dialog not recognizing markup (bug #13888)
* Fix minimap no clipping in the new wiggets
* Added preprocessor macros to the wiki grabber tool
Version 1.7.1:
* AI:

View file

@ -33,6 +33,11 @@ if __name__ == "__main__":
# - second the actual data
file_map = {}
# contains all macros:
# - key macro name
# - value macro contents
macro_map = {}
# default directory to dump the output in with trailing /.
output_directory = "/tmp/"
@ -338,6 +343,8 @@ if __name__ == "__main__":
def process(data):
"""Processes a wiki block."""
data = replace_macros(data)
res = re.compile("(.*?)\n\n(.*)", re.S).findall(data);
if(res != None and len(res) != 0):
header = process_header(res[0][0])
@ -391,14 +398,14 @@ if __name__ == "__main__":
"""Processes a directory.
Recurses into the sub directory, ignoring hidden directories.
Processes every .cpp file.
Processes every .[c|h]pp file.
"""
items = os.listdir(dir)
for item in items:
# Ignore .svn dirs.
# Ignore hidden directories.
if(item.startswith(".")):
continue
@ -407,11 +414,83 @@ if __name__ == "__main__":
elif(item.endswith(".cpp") or item.endswith(".hpp")):
process_file(dir + "/" + item)
##### ##### ##### MACRO PROCESSING ##### ##### #####
def instanciate_macro(macro):
"""Replaces a macro text by the marco value."""
global macro_map
if(macro_map.has_key(macro.group(1)) == False):
print "Macro '" + macro.group(1) + "' is not defined."
return macro.group(0)
return macro_map[macro.group(1)]
def replace_macros(data):
"""Replaces all macros found in the data.
If a macro isn't defined, the text is left as is."""
macro_regex = re.compile("@macro *= *(\w+)", re.M | re.S)
data = macro_regex.sub(lambda match: instanciate_macro(match), data)
return data
def create_macro(macro):
"""Wrapper for creating macros."""
global macro_map
if(macro_map.has_key(macro.group(1))):
print "Macro '" + macro.group(1) + "' is being redefined."
macro_map[macro.group(1)] = macro.group(2)
def process_file_macros(name):
"""Processes all wiki macro blocks (if any) of a file."""
global current_file
current_file = name
file = open(name, "r")
data = file.read()
file.close()
regex = re.compile("(/\*WIKI_MACRO($.*?)^ \*/)", re.M | re.S)
res = regex.findall(data)
if(res != None):
for i in range(len(res)):
global current_block
current_block = res[i][0]
section = reindent(res[i][1])
macro_regex = re.compile("^@start_macro *= *(.*?)\n(.*?)\n@end_macro.*?$", re.M | re.S)
macro_regex.sub(lambda match: create_macro(match), section)
def process_directory_macros(dir):
"""Processes a directory looking for macros.
Recurses into the sub directory, ignoring hidden directories.
Processes every .[c|h]pp file.
"""
items = os.listdir(dir)
for item in items:
# Ignore hidden directories.
if(item.startswith(".")):
continue
if(os.path.isdir(dir + "/" + item)):
process_directory_macros(dir + "/" + item)
elif(item.endswith(".cpp") or item.endswith(".hpp")):
process_file_macros(dir + "/" + item)
##### ##### ##### MAIN ##### ##### #####
process_directory_macros(src_directory)
process_directory(src_directory)
create_output()