basic dynamic menu generation

This commit is contained in:
brent s. 2019-11-18 01:06:28 -05:00
parent 48f5f347b1
commit 0dac14d7e1
6 changed files with 94 additions and 1 deletions

2
.gitignore vendored
View File

@ -18,4 +18,4 @@
.*.swp .*.swp
.editix .editix
__pycache__/ __pycache__/
test.py *.sqlite3

View File

@ -0,0 +1,8 @@
from flask import Flask
from . import db

app = Flask(__name__, instance_relative_config = True)

from app import views

app.config.from_object('config')

23
app/db.py Normal file
View File

@ -0,0 +1,23 @@
import os
import sqlite3

db_path = '/usr/local/lib/bootbox/local.sqlite3'

class LocalDB(object):
def __init__(self, db_path = db_path):
self.db_path = db_path
self.conn = sqlite3.connect(self.db_path)
self.conn.row_factory = sqlite3.Row
self.cur = self.conn.cursor()

def getMenu(self, menu):
result = []
self.cur.execute('SELECT * FROM {0}'.format(menu))
for row in self.cur.fetchall():
result.append(dict(row))
return(result)

def close(self):
self.cur.close()
self.conn.close()
return()

View File

@ -0,0 +1,6 @@
#!ipxe

console --picture {{ request.url_root }}ipxe/bg.png --left 32 --right 32 --top 32 --bottom 48

{% block menu %}
{% endblock %}

View File

@ -0,0 +1,21 @@
{% extends 'formatting.ipxe.j2' %}
{% block menu%}
dhcp
echo MAIN MENU

cpuid --ext 29 && set bits 64 || set bits 32
cpuid --ext 29 && set arch x86_64 || set arch x86

:main
menu BootBox @ {{ request.url_root }}
{% for mt in ('install', 'utilities') %}
item --gap -- == {{ mt.upper() }} ==
{% for os in db.getMenu(mt) %}
item --key {{ os['shortcut'] }} {{ os['name'] }} ({{ os['shortcut'] }}) {{ os['desc'] }}
{%- endfor %}
{% endfor %}



shell
{% endblock %}

View File

@ -0,0 +1,35 @@
import os
import pprint
import re
##
from flask import render_template, make_response, request, Response
from flask_autoindex import AutoIndex
##
from app import db
from app import app

ua_re = re.compile(r'^iPXE/v[0-9.]+')


def getReqInfo():
d = {}
for a in dir(request):
if a.startswith('_'):
continue
d[a] = getattr(request, a)
return(d)


@app.route('/', methods = ['GET'])
def index():
DB = db.LocalDB()
result = render_template('main.ipxe.j2',
db = DB)
DB.close()
return(result)


@app.route('/foo', methods = ['GET'])
def foo():
pprint.pprint(getReqInfo())
return(Response())