forked from mirrors/thatmattlove-hyperglass
gunicorn fixed, improved manage.py
This commit is contained in:
parent
9a4a8cf65e
commit
ddc7f1238e
27 changed files with 76 additions and 23 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.flask_cache/f2a7e36076223a740fa17b882df5c74a
Normal file
BIN
.flask_cache/f2a7e36076223a740fa17b882df5c74a
Normal file
Binary file not shown.
Binary file not shown.
1
hyperglass/.gitignore
vendored
1
hyperglass/.gitignore
vendored
|
|
@ -1,6 +1,7 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.sass-cache/
|
.sass-cache/
|
||||||
.flask_cache
|
.flask_cache
|
||||||
|
gunicorn_config.py
|
||||||
test.py
|
test.py
|
||||||
__pycache__/
|
__pycache__/
|
||||||
parsing/
|
parsing/
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ from flask_limiter import Limiter
|
||||||
from flask_limiter.util import get_remote_address
|
from flask_limiter.util import get_remote_address
|
||||||
|
|
||||||
# Local Imports
|
# Local Imports
|
||||||
from hyperglass import render
|
import hyperglass.configuration as configuration
|
||||||
from hyperglass import configuration
|
|
||||||
from hyperglass.command import execute
|
from hyperglass.command import execute
|
||||||
|
from hyperglass import render
|
||||||
|
|
||||||
# Load TOML config file
|
# Load TOML config file
|
||||||
devices = configuration.devices()
|
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"
|
rate_limit_site = configuration.gen.rate_limit_site() + "per minute"
|
||||||
limiter = Limiter(app, key_func=get_remote_address, default_limits=[rate_limit_site])
|
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
|
# Render Main Flask-Limiter Error Message
|
||||||
@app.errorhandler(429)
|
@app.errorhandler(429)
|
||||||
def error429(e):
|
def error429(e):
|
||||||
|
|
|
||||||
|
|
@ -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.")
|
|
||||||
|
|
@ -3,12 +3,15 @@ import sass
|
||||||
import codecs
|
import codecs
|
||||||
import jinja2
|
import jinja2
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from logzero import logger
|
||||||
from markdown2 import Markdown
|
from markdown2 import Markdown
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
|
|
||||||
|
import hyperglass
|
||||||
from hyperglass import configuration
|
from hyperglass import configuration
|
||||||
|
|
||||||
dir = os.path.dirname(os.path.abspath(__file__))
|
dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
hyperglass_root = os.path.dirname(hyperglass.__file__)
|
||||||
file_loader = jinja2.FileSystemLoader(dir)
|
file_loader = jinja2.FileSystemLoader(dir)
|
||||||
env = jinja2.Environment(loader=file_loader)
|
env = jinja2.Environment(loader=file_loader)
|
||||||
|
|
||||||
|
|
@ -79,6 +82,8 @@ class html:
|
||||||
|
|
||||||
class css:
|
class css:
|
||||||
def renderTemplate():
|
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:
|
try:
|
||||||
template = env.get_template("templates/hyperglass.scss")
|
template = env.get_template("templates/hyperglass.scss")
|
||||||
rendered_output = template.render(
|
rendered_output = template.render(
|
||||||
|
|
@ -94,14 +99,16 @@ class css:
|
||||||
mono_font_url=configuration.brand.mono_font_url(),
|
mono_font_url=configuration.brand.mono_font_url(),
|
||||||
mono_font_name=configuration.brand.mono_font_name(),
|
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)
|
scss_output.write(rendered_output)
|
||||||
except:
|
except:
|
||||||
|
logger.error("Error rendering Jinja2 template.")
|
||||||
raise TypeError("Error rendering Jinja2 template.")
|
raise TypeError("Error rendering Jinja2 template.")
|
||||||
try:
|
try:
|
||||||
generated_sass = sass.compile(filename="static/sass/hyperglass.scss")
|
generated_sass = sass.compile(filename=scss_file)
|
||||||
with open("static/css/hyperglass.css", "w") as css_output:
|
with open(css_file, "w") as css_output:
|
||||||
css_output.write(generated_sass)
|
css_output.write(generated_sass)
|
||||||
print("\n", "* Sass templates rendered to CSS files.", "\n")
|
logger.info("Rendered Sass templates to CSS files.")
|
||||||
except:
|
except:
|
||||||
|
logger.error("Error rendering Sass template.")
|
||||||
raise TypeError("Error rendering Sass template.")
|
raise TypeError("Error rendering Sass template.")
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,5 @@ from hyperglass.hyperglass import app
|
||||||
application = app
|
application = app
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
application.renderCSS()
|
||||||
application.run()
|
application.run()
|
||||||
|
|
|
||||||
53
manage.py
Normal file
53
manage.py
Normal 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
|
||||||
Loading…
Add table
Reference in a new issue