-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pages serverconfig implementation
- Loading branch information
Showing
10 changed files
with
615 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ __pycache__ | |
.pytest_cache | ||
.cloudcli | ||
.env | ||
.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Github Pages | ||
|
||
The content is generated using Python with Jinja2 templates in `pages-source` directory | ||
and served via GitHub pages from `pages/` directory. | ||
|
||
To generate the content: | ||
|
||
* Install requirements: `pip install -r requirements.txt` | ||
* Generate html for local development and watch for changes `python -m pages_src.generate --dev` | ||
|
||
Start a local web server to test by running `python -m http.server -d .data/pages` | ||
and then visiting `http://localhost:8000`. |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import sys | ||
import time | ||
|
||
import jinja2 | ||
import requests | ||
import watchdog.events | ||
import watchdog.observers | ||
|
||
|
||
CALCULATOR_JS_PHP_URL = "https://console.kamatera.com/info/calculator.js.php" | ||
|
||
|
||
def generate(calculator_js_php_url=CALCULATOR_JS_PHP_URL): | ||
env = jinja2.Environment( | ||
loader=jinja2.PackageLoader("pages_src", "templates"), | ||
autoescape=jinja2.select_autoescape() | ||
) | ||
with open(".data/pages/index.html", "w") as f: | ||
f.write(env.get_template("index.html").render()) | ||
with open(".data/pages/serverconfiggen.html", "w") as f: | ||
f.write(env.get_template("serverconfiggen.html").render( | ||
calculator_js_php_url=calculator_js_php_url | ||
)) | ||
print('OK') | ||
|
||
|
||
class EventHandler(watchdog.events.FileSystemEventHandler): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.modified_src_paths = set() | ||
|
||
|
||
def on_any_event(self, event): | ||
if not event.is_directory and not event.src_path.endswith('~'): | ||
if event.event_type != watchdog.events.EVENT_TYPE_CLOSED: | ||
self.modified_src_paths.add(event.src_path) | ||
|
||
|
||
def dev(): | ||
if not os.path.exists(".data/pages/calculator.js.php"): | ||
res = requests.get(CALCULATOR_JS_PHP_URL) | ||
res.raise_for_status() | ||
with open(".data/pages/calculator.js.php", "wb") as f: | ||
f.write(res.content) | ||
generate("calculator.js.php") | ||
event_handler = EventHandler() | ||
observer = watchdog.observers.Observer() | ||
observer.schedule(event_handler, path='pages_src', recursive=True) | ||
observer.start() | ||
print("Watching pages_src for changes...") | ||
try: | ||
while True: | ||
time.sleep(0.1) | ||
if len(event_handler.modified_src_paths) > 0: | ||
print(f'Regenerating, changes detected in {event_handler.modified_src_paths}') | ||
event_handler.modified_src_paths = set() | ||
generate("calculator.js.php") | ||
except KeyboardInterrupt: | ||
observer.stop() | ||
observer.join() | ||
|
||
|
||
def main(*args): | ||
os.makedirs(".data/pages", exist_ok=True) | ||
if '--dev' in args: | ||
dev() | ||
else: | ||
generate() | ||
|
||
|
||
if __name__ == "__main__": | ||
main(*sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head>{% block head %} | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous"> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-u1OknCvxWvY5kfmNBILK2hRnQC3Pr17a+RTT6rIHI7NnikvbZlHgTPOOmMi466C8" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | ||
<title>Kamatera Toolbox</title> | ||
{% endblock %}</head> | ||
<body>{% block body %}{% endblock %}</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends "base.html" %} | ||
{% block body %} | ||
<ul class="list-group"> | ||
<li class="list-group-item"><a href="serverconfiggen.html">Configuration Generator</a></li> | ||
</ul> | ||
{% endblock %} |
Oops, something went wrong.