Make exporters actually work and begin stripping the multi-directory operations that were never really necessary

This commit is contained in:
Robert MacGregor 2016-04-21 18:32:47 -04:00
parent 574385d707
commit 8f969d7208
5 changed files with 245 additions and 219 deletions

View file

@ -6,43 +6,44 @@ import os.path
class Exporter(object):
data = None
def __init__(self, data):
self.data = data
def write(self, directory):
def write(self):
with open("Out.txt", "w") as handle:
# Write the header
handle.write("====== Test ======\n\n")
# For each file entry...
for file in self.data:
for file in self.data["files"]:
if (len(file.global_functions) == 0 and len(file.bound_functions.keys()) == 0 and len(file.datablocks) == 0):
continue
# Calculate the total entry count
entry_count = len(file.global_functions) + len(file.datablocks)
for type in file.bound_functions.keys():
entry_count = entry_count + len(file.bound_functions[type])
handle.write("===== Entries in %s (%u total) =====\n\n" % (file.path, entry_count))
handle.write("===== Global Functions (%u total) =====\n\n" % len(file.global_functions))
# For each global function...
for function in file.global_functions:
handle.write("==== %s ====\n" % function.name)
handle.write("File (line %u): %s\n\n" % (function.line, file.path))
if (len(function.parameters) != 0):
handle.write("Parameters (in order):\n")
for parameter in function.parameters:
handle.write(" * %s\n" % parameter)
else:
handle.write("Parameters: None\n")
handle.write("\n")
# For each known type...
for type in file.bound_functions.keys():
handle.write("===== Bound Functions on %s (%u total) =====\n\n" % (type, len(file.bound_functions[type])))
@ -50,15 +51,15 @@ class Exporter(object):
for function in file.bound_functions[type]:
handle.write("==== %s::%s ====\n" % (function.type, function.name))
handle.write("File (line %u): %s\n\n" % (function.line, file.path))
if (len(function.parameters) != 0):
handle.write("Parameters (in order):\n")
for parameter in function.parameters:
handle.write(" * %s\n" % parameter)
else:
handle.write("Parameters: None\n")
handle.write("\n")
print("Done processing.")
print("Done processing.")

View file

@ -6,41 +6,67 @@ import os.path
class Exporter(object):
data = None
def __init__(self, data):
def __init__(self, data, target_directory):
self.data = data
def write(self):
self.target_directory = target_directory
def _path_visitor(self, arg, dirname, names):
for name in names:
mirrored_path = os.path.join(dirname, name)
relative_path = os.path.join(arg, mirrored_path.replace(self.target_directory + "/", ""))
try:
if (os.path.isdir(mirrored_path)):
print(relative_path)
os.mkdir(relative_path)
except OSError:
pass
def write(self, directory):
import jinja2
# Read the template files first
file_template = None
with open("data/filetempl.html", "r") as handle:
file_template = handle.read()
index_template = None
with open("data/indextempl.html", "r") as handle:
index_template = handle.read()
html_filenames = [ ]
# Recurse the target directory and recreate its structure
os.path.walk(self.target_directory, self._path_visitor, directory)
# For each file entry...
for file in self.data:
script_relative_paths = [ ]
for file in self.data["files"]:
if (len(file.global_functions) == 0 and len(file.bound_functions.keys()) == 0 and len(file.datablocks) == 0):
continue
html_filename = file.path.lstrip("./").replace("/", "-")
# First, we collapse to a file path relative to our output dir
# FIXME: Dirty hack to make sure the os.path.join works
html_filename = file.path.replace(self.target_directory + "/", "")
script_relative = html_filename
script_relative_paths.append(script_relative)
# Next, we ensure that the subdirectories exist
#html_filename = html_filename.lstrip("./").replace("/", "-")
html_filename, oldextension = os.path.splitext(html_filename)
html_filename = "%s.html" % html_filename
html_filenames.append(html_filename)
with open(html_filename, "w") as handle:
with open(os.path.join(directory, html_filename), "w") as handle:
template = jinja2.Template(file_template)
handle.write(template.render(file=file.path, globals=file.global_functions))
# Dump the index file
with open("index.html", "w") as handle:
with open(os.path.join(directory, "index.html"), "w") as handle:
template = jinja2.Template(index_template)
handle.write(template.render(files=self.data))
handle.write(template.render(files=script_relative_paths))
print("Done processing.")