Skip to content
Snippets Groups Projects
Commit fc6ff8cb authored by Alexis Filipozzi's avatar Alexis Filipozzi
Browse files

add recursion level attribute to correct style link

parent 87dc396b
No related branches found
No related tags found
No related merge requests found
......@@ -4,8 +4,9 @@ import os
class Formatter:
def __init__(self, data):
def __init__(self, data, recursion_level):
self._data = data
self._recursion_level = recursion_level
self._root = None
self._body = None
self._extra = None
......@@ -20,7 +21,7 @@ class Formatter:
root.append(message)
style = etree.Element("style")
style.attrib["inherits"] = "../guide-style.protoxml"
style.attrib["inherits"] = ("../" * self._recursion_level) + "guide-style.protoxml"
message.append(style)
body = etree.Element("body")
......
......@@ -18,7 +18,7 @@ def main_one_arg(directory):
for filename in os.listdir(directory):
parse_and_format(directory, filename, destination)
def parse_and_format(dir_path, filename, dest):
def parse_and_format(dir_path, filename, dest, level=1):
assert(os.path.exists(os.path.join(dir_path, filename)))
path_to_file = os.path.join(dir_path, filename)
path_to_dst = os.path.join(dest, filename)
......@@ -30,13 +30,14 @@ def parse_and_format(dir_path, filename, dest):
if not os.path.exists(path_to_dst):
os.makedirs(path_to_dst)
for sub_file in os.listdir(path_to_file):
parse_and_format(path_to_file, sub_file, path_to_dst)
parse_and_format(path_to_file, sub_file, path_to_dst, level+1)
elif os.path.isfile(path_to_file):
parse_format_and_write_file(path_to_file, os.path.join(dest, filename.replace(".html", ".protoxml")))
parse_format_and_write_file(path_to_file, os.path.join(dest,
filename.replace(".html", ".protoxml")), level)
else:
print "Unhandled file type (probably symlink) with file " + str(path_to_file)
def parse_format_and_write_file(filename, dest):
def parse_format_and_write_file(filename, dest, level):
has_been_parsed = False
parser = None
formatter = None
......@@ -49,7 +50,7 @@ def parse_format_and_write_file(filename, dest):
print "Error message: " + str(e)
if has_been_parsed:
try:
formatter = Formatter(parser.get_data())
formatter = Formatter(parser.get_data(), level)
formatter.format()
formatter.write_to_file(dest)
except Exception as e:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment