mirror of
https://github.com/Ragora/TSScraper.git
synced 2026-07-14 23:34:34 +00:00
Make exporters actually work and begin stripping the multi-directory operations that were never really necessary
This commit is contained in:
parent
574385d707
commit
8f969d7208
5 changed files with 245 additions and 219 deletions
|
|
@ -10,13 +10,14 @@ class Exporter(object):
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
def write(self):
|
def write(self, directory):
|
||||||
|
|
||||||
with open("Out.txt", "w") as handle:
|
with open("Out.txt", "w") as handle:
|
||||||
# Write the header
|
# Write the header
|
||||||
handle.write("====== Test ======\n\n")
|
handle.write("====== Test ======\n\n")
|
||||||
|
|
||||||
# For each file entry...
|
# 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):
|
if (len(file.global_functions) == 0 and len(file.bound_functions.keys()) == 0 and len(file.datablocks) == 0):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,23 @@ import os.path
|
||||||
class Exporter(object):
|
class Exporter(object):
|
||||||
data = None
|
data = None
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data, target_directory):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
self.target_directory = target_directory
|
||||||
|
|
||||||
def write(self):
|
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
|
import jinja2
|
||||||
|
|
||||||
# Read the template files first
|
# Read the template files first
|
||||||
|
|
@ -23,24 +36,37 @@ class Exporter(object):
|
||||||
index_template = handle.read()
|
index_template = handle.read()
|
||||||
|
|
||||||
html_filenames = [ ]
|
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 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):
|
if (len(file.global_functions) == 0 and len(file.bound_functions.keys()) == 0 and len(file.datablocks) == 0):
|
||||||
continue
|
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, oldextension = os.path.splitext(html_filename)
|
||||||
html_filename = "%s.html" % html_filename
|
html_filename = "%s.html" % html_filename
|
||||||
html_filenames.append(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)
|
template = jinja2.Template(file_template)
|
||||||
handle.write(template.render(file=file.path, globals=file.global_functions))
|
handle.write(template.render(file=file.path, globals=file.global_functions))
|
||||||
|
|
||||||
# Dump the index file
|
# 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)
|
template = jinja2.Template(index_template)
|
||||||
handle.write(template.render(files=self.data))
|
|
||||||
|
handle.write(template.render(files=script_relative_paths))
|
||||||
|
|
||||||
print("Done processing.")
|
print("Done processing.")
|
||||||
|
|
||||||
|
|
|
||||||
22
main.py
22
main.py
|
|
@ -23,7 +23,7 @@ class Application(object):
|
||||||
target_exporter = None
|
target_exporter = None
|
||||||
|
|
||||||
def print_usage(self):
|
def print_usage(self):
|
||||||
print("Usage: '%s <exporter> <target directories...>'" % sys.argv[0])
|
print("Usage: '%s <exporter> <output directory> <target directories...>'" % sys.argv[0])
|
||||||
print("Or: '%s exporters' for a list of known exporters." % sys.argv[0])
|
print("Or: '%s exporters' for a list of known exporters." % sys.argv[0])
|
||||||
|
|
||||||
def get_available_exporters(self):
|
def get_available_exporters(self):
|
||||||
|
|
@ -58,16 +58,16 @@ class Application(object):
|
||||||
if (sys.argv[1] == "exporters"):
|
if (sys.argv[1] == "exporters"):
|
||||||
print("Available Exporters: ")
|
print("Available Exporters: ")
|
||||||
|
|
||||||
for exporter in exporters.keys():
|
for exporter in exporters:
|
||||||
print("\t- %s" % exporter)
|
print("\t- %s" % exporter)
|
||||||
return
|
|
||||||
print("\t- None")
|
print("\t- None")
|
||||||
|
return
|
||||||
elif(len(sys.argv) < 3):
|
elif(len(sys.argv) < 4):
|
||||||
self.print_usage()
|
self.print_usage()
|
||||||
return
|
return
|
||||||
|
|
||||||
self.target_directory = sys.argv[2:]
|
self.target_directory = sys.argv[3]
|
||||||
|
self.output_directory = sys.argv[2]
|
||||||
self.target_exporter = sys.argv[1]
|
self.target_exporter = sys.argv[1]
|
||||||
self.run()
|
self.run()
|
||||||
|
|
||||||
|
|
@ -85,11 +85,13 @@ class Application(object):
|
||||||
scraper = tsscraper.TSScraper(self.target_directory, self.thread_count)
|
scraper = tsscraper.TSScraper(self.target_directory, self.thread_count)
|
||||||
results = scraper.process()
|
results = scraper.process()
|
||||||
|
|
||||||
|
# Init the exporter
|
||||||
|
if (exporter is not None):
|
||||||
|
# Ensure that the output directory at least exists
|
||||||
|
os.mkdir(self.output_directory)
|
||||||
|
|
||||||
# Init the DokuOutput
|
output = exporter.Exporter(results, self.target_directory)
|
||||||
# if (exporter is not None):
|
output.write(self.output_directory)
|
||||||
# output = exporter.Exporter(results)
|
|
||||||
# output.write()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Operation Completion-----------------------\n%f Seconds" % timeit.timeit("Application().main()", number=1, setup="from __main__ import Application"))
|
print("Operation Completion-----------------------\n%f Seconds" % timeit.timeit("Application().main()", number=1, setup="from __main__ import Application"))
|
||||||
23
tsscraper.py
23
tsscraper.py
|
|
@ -684,20 +684,19 @@ class TSScraper(object):
|
||||||
print("Program Error: Unknown datablock type '%s'! This means the software does not know how to check this datablock. (Declaration in %s, line %u)" % (datablock.type, datablock.filepath, datablock.line))
|
print("Program Error: Unknown datablock type '%s'! This means the software does not know how to check this datablock. (Declaration in %s, line %u)" % (datablock.type, datablock.filepath, datablock.line))
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
result = None
|
|
||||||
|
|
||||||
# Process each directory sequentially
|
# Process each directory sequentially
|
||||||
target_files = { }
|
target_files = { }
|
||||||
for index, target_directory in enumerate(self._target_directories):
|
|
||||||
if (os.path.isdir(target_directory) is False):
|
|
||||||
raise IOError("No such directory to recurse (#%u): '%s'" % (index, target_directory))
|
|
||||||
|
|
||||||
print("INFO: Building file list for directory '%s' ..." % target_directory)
|
target_directory = self._target_directories
|
||||||
current_files = self.get_file_list(target_directory)
|
if (os.path.isdir(target_directory) is False):
|
||||||
|
raise IOError("No such directory to recurse (#%u): '%s'" % (index, target_directory))
|
||||||
|
|
||||||
# Does a previous entry exist in the target file list?
|
print("INFO: Building file list for directory '%s' ..." % target_directory)
|
||||||
for current_absolute_path, current_relative_path in current_files:
|
current_files = self.get_file_list(target_directory)
|
||||||
target_files[current_relative_path] = current_absolute_path
|
|
||||||
|
# Does a previous entry exist in the target file list?
|
||||||
|
for current_absolute_path, current_relative_path in current_files:
|
||||||
|
target_files[current_relative_path] = current_absolute_path
|
||||||
|
|
||||||
# Build the list now
|
# Build the list now
|
||||||
target_file_list = [ ]
|
target_file_list = [ ]
|
||||||
|
|
@ -724,6 +723,4 @@ class TSScraper(object):
|
||||||
# We're done, return the results
|
# We're done, return the results
|
||||||
print("INFO: Done.")
|
print("INFO: Done.")
|
||||||
|
|
||||||
return result
|
return { "files": parse_results, "datablocks": datablock_list }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue