1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 08:48:05 +00:00

gunicorn fixed, improved manage.py

This commit is contained in:
checktheroads 2019-05-12 19:22:17 -07:00
parent 9a4a8cf65e
commit ddc7f1238e
27 changed files with 76 additions and 23 deletions

Binary file not shown.

View file

@ -1,6 +1,7 @@
.DS_Store
.sass-cache/
.flask_cache
gunicorn_config.py
test.py
__pycache__/
parsing/

View file

@ -9,9 +9,9 @@ from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
# Local Imports
from hyperglass import render
from hyperglass import configuration
import hyperglass.configuration as configuration
from hyperglass.command import execute
from hyperglass import render
# Load TOML config file
devices = configuration.devices()
@ -27,6 +27,14 @@ rate_limit_query = configuration.gen.rate_limit_query() + " per minute"
rate_limit_site = configuration.gen.rate_limit_site() + "per minute"
limiter = Limiter(app, key_func=get_remote_address, default_limits=[rate_limit_site])
def renderCSS():
try:
render.css.renderTemplate()
except:
raise
# Render Main Flask-Limiter Error Message
@app.errorhandler(429)
def error429(e):

View file

@ -1,17 +0,0 @@
import os
import sys
from loguru import logger
# from hyperglass.hyperglass import app
logger.add(sys.stderr)
for arg in sys.argv:
if arg == "clearcache":
try:
hyperglass.hyperglass.app.clearcache()
logger.info("Successfully cleared cache.")
except:
raise
logger.error("Failed to clear cache.")

View file

@ -3,12 +3,15 @@ import sass
import codecs
import jinja2
import subprocess
from logzero import logger
from markdown2 import Markdown
from flask import render_template
import hyperglass
from hyperglass import configuration
dir = os.path.dirname(os.path.abspath(__file__))
hyperglass_root = os.path.dirname(hyperglass.__file__)
file_loader = jinja2.FileSystemLoader(dir)
env = jinja2.Environment(loader=file_loader)
@ -79,6 +82,8 @@ class html:
class css:
def renderTemplate():
scss_file = os.path.join(hyperglass_root, "static/sass/hyperglass.scss")
css_file = os.path.join(hyperglass_root, "static/css/hyperglass.css")
try:
template = env.get_template("templates/hyperglass.scss")
rendered_output = template.render(
@ -94,14 +99,16 @@ class css:
mono_font_url=configuration.brand.mono_font_url(),
mono_font_name=configuration.brand.mono_font_name(),
)
with open("static/sass/hyperglass.scss", "w") as scss_output:
with open(scss_file, "w") as scss_output:
scss_output.write(rendered_output)
except:
logger.error("Error rendering Jinja2 template.")
raise TypeError("Error rendering Jinja2 template.")
try:
generated_sass = sass.compile(filename="static/sass/hyperglass.scss")
with open("static/css/hyperglass.css", "w") as css_output:
generated_sass = sass.compile(filename=scss_file)
with open(css_file, "w") as css_output:
css_output.write(generated_sass)
print("\n", "* Sass templates rendered to CSS files.", "\n")
logger.info("Rendered Sass templates to CSS files.")
except:
logger.error("Error rendering Sass template.")
raise TypeError("Error rendering Sass template.")

View file

@ -3,4 +3,5 @@ from hyperglass.hyperglass import app
application = app
if __name__ == "__main__":
application.renderCSS()
application.run()

53
manage.py Normal file
View file

@ -0,0 +1,53 @@
import os
import sys
import click
from logzero import logger
from hyperglass import render as render
from hyperglass import hyperglass
@click.group()
def main():
pass
@main.command()
def clearcache():
try:
hyperglass.clearCache()
logger.info("Successfully cleared cache.")
except:
raise
logger.error("Failed to clear cache.")
@main.command()
def testserver():
try:
render.css.renderTemplate()
hyperglass.app.run(host="0.0.0.0", debug=True, port=5000)
logger.error("Started test server.")
except:
logger.error("Failed to start test server.")
raise
if __name__ == "__main__":
main()
# for arg in sys.argv:
# if arg == "clearcache":
# try:
# hyperglass.hyperglass.app.clearcache()
# logger.info("Successfully cleared cache.")
# except:
# raise
# logger.error("Failed to clear cache.")
# elif arg == "test":
# try:
# render.css.renderTemplate()
# app.run(host="0.0.0.0", debug=True, port=5000)
# logger.error("Started test server.")
# except:
# logger.error("Failed to start test server.")
# raise