Skip to content
Snippets Groups Projects
Commit 4bb03420 authored by Josh Borrow's avatar Josh Borrow
Browse files

pep8 compliant

parent a1f81034
Branches
No related tags found
No related merge requests found
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk) Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
""" """
import os #Disable errors associated with un-overwritten methods in HTMLParser.
#pylint: disable=W0223
from html.parser import HTMLParser from html.parser import HTMLParser
import pypandoc import pypandoc
...@@ -19,8 +21,8 @@ import yaml ...@@ -19,8 +21,8 @@ import yaml
def open_meta(filename="about_meta.yaml", data_dir="../data"): def open_meta(filename="about_meta.yaml", data_dir="../data"):
""" Read the meta file and return the associated data """ """ Read the meta file and return the associated data """
with open(f"{data_dir}/{filename}", "r") as f: with open(f"{data_dir}/{filename}", "r") as handle:
return yaml.load(f) return yaml.load(handle)
def compile_markdown(data, data_dir="../data"): def compile_markdown(data, data_dir="../data"):
...@@ -29,8 +31,8 @@ def compile_markdown(data, data_dir="../data"): ...@@ -29,8 +31,8 @@ def compile_markdown(data, data_dir="../data"):
output_text = "" output_text = ""
for item in data["files"]: for item in data["files"]:
with open(f"{data_dir}/{item['name']}", "r") as f: with open(f"{data_dir}/{item['name']}", "r") as handle:
input_text = f.read() input_text = handle.read()
compiled_text = pypandoc.convert_text(input_text, 'html', format='md') compiled_text = pypandoc.convert_text(input_text, 'html', format='md')
...@@ -39,6 +41,7 @@ def compile_markdown(data, data_dir="../data"): ...@@ -39,6 +41,7 @@ def compile_markdown(data, data_dir="../data"):
class Parser(HTMLParser): class Parser(HTMLParser):
""" Custom HTML Parser that builds the headings tree """
def __init__(self): def __init__(self):
super(Parser, self).__init__() super(Parser, self).__init__()
...@@ -58,7 +61,7 @@ class Parser(HTMLParser): ...@@ -58,7 +61,7 @@ class Parser(HTMLParser):
self.headings.append([tag, this_id]) self.headings.append([tag, this_id])
self.waiting_for_data = True self.waiting_for_data = True
def handle_endtag(self, tag): def handle_endtag(self, tag):
pass pass
...@@ -117,18 +120,18 @@ def compile_to_yaml(in_filename="about_meta.yaml", out_filename="about.yaml", da ...@@ -117,18 +120,18 @@ def compile_to_yaml(in_filename="about_meta.yaml", out_filename="about.yaml", da
"sidebar": sidebar "sidebar": sidebar
} }
with open(f"{data_dir}/{out_filename}", "w") as f: with open(f"{data_dir}/{out_filename}", "w") as handle:
yaml.dump(output_data, f) yaml.dump(output_data, handle)
return output_data return output_data
if __name__ == "__main__": if __name__ == "__main__":
print("Running this script directly will only compile the markdown in data.") print("Running this script directly will only compile the markdown in data.")
print("If you wish to continue, please enter Y, if not, please enter N.") print("If you wish to continue, please enter Y, if not, please enter N.")
choice = input()
if choice in ['y', 'Y']: CHOICE = input()
if CHOICE in ['y', 'Y']:
compile_to_yaml() compile_to_yaml()
else: else:
exit(0) exit(0)
""" Short compilation script from the website """ Short compilation script from the website
(essentially just stitches together a bunch of jinja templates) (essentially just stitches together a bunch of jinja templates)
Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk) Created 16-08-2017 by Josh Borrow (joshua.borrow@durham.ac.uk)
""" """
...@@ -37,8 +37,8 @@ def get_associated_data(template_names, data_dir="../data"): ...@@ -37,8 +37,8 @@ def get_associated_data(template_names, data_dir="../data"):
filename = f"{data_dir}/{stub}.yaml" filename = f"{data_dir}/{stub}.yaml"
try: try:
with open(filename, "r") as f: with open(filename, "r") as handle:
data.append(yaml.load(f)) data.append(yaml.load(handle))
except FileNotFoundError: except FileNotFoundError:
data.append({}) data.append({})
...@@ -85,8 +85,8 @@ def global_variables(active, data_dir="../data"): ...@@ -85,8 +85,8 @@ def global_variables(active, data_dir="../data"):
Active is the name of the current page's template and is used in the Active is the name of the current page's template and is used in the
production of the processed navbar. """ production of the processed navbar. """
with open("{}/global.yaml".format(data_dir), "r") as f: with open("{}/global.yaml".format(data_dir), "r") as handle:
raw = yaml.load(f) # We need to process the navbar. raw = yaml.load(handle) # We need to process the navbar.
return process_navbar(raw, active) return process_navbar(raw, active)
...@@ -102,8 +102,8 @@ def render(render_pages, data_dir, template_dir, output_dir): ...@@ -102,8 +102,8 @@ def render(render_pages, data_dir, template_dir, output_dir):
os.makedirs(output_dir) os.makedirs(output_dir)
for page, data in zip(render_pages, output): for page, data in zip(render_pages, output):
with open("{}/{}".format(output_dir, page), "w") as f: with open("{}/{}".format(output_dir, page), "w") as handle:
f.write(data) handle.write(data)
return return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment