diff --git a/data/indextempl.html b/data/indextempl.html
index 74ea2f5..cd42b2f 100644
--- a/data/indextempl.html
+++ b/data/indextempl.html
@@ -2,20 +2,20 @@
TS Scraper | Index
-
+
TS Scraper
-
+
File Index
-
+
{% for file in files %}
{{ file.path }}
{% endfor %}
-
+
This file was auto-generated by TS Scraper.
TS Scraper is written in Python 2 by Robert MacGregor.
diff --git a/exporters/doku.py b/exporters/doku.py
index f7913b3..41e67ff 100644
--- a/exporters/doku.py
+++ b/exporters/doku.py
@@ -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.")
\ No newline at end of file
+
+ print("Done processing.")
diff --git a/exporters/html.py b/exporters/html.py
index 28d1397..0edb90f 100644
--- a/exporters/html.py
+++ b/exporters/html.py
@@ -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.")
-
diff --git a/main.py b/main.py
index e3f080a..765389e 100644
--- a/main.py
+++ b/main.py
@@ -18,32 +18,32 @@ class Application(object):
thread_count = 8
threads = None
-
+
target_directory = None
target_exporter = None
-
+
def print_usage(self):
- print("Usage: '%s '" % sys.argv[0])
+ print("Usage: '%s