Now using configuration files
This commit is contained in:
parent
8153bfd9ca
commit
e6a046d4e6
29
src/main.py
29
src/main.py
@ -7,23 +7,36 @@
|
||||
# Then we build the web interface, using the simple Jinja2 templating.
|
||||
|
||||
# Following are the librairies we import,
|
||||
from flask import Flask # Used for the web framework
|
||||
from printer import Printer
|
||||
from flask import Flask # Used for the web framework
|
||||
from printer import Printer # The wrapper for the printer class
|
||||
import toml # Used for the config file parsing
|
||||
import pprint
|
||||
|
||||
# Load the configuration file
|
||||
try:
|
||||
configuration_file = toml.load("configuration/config.toml")
|
||||
except TypeError :
|
||||
print("Unable to load the config file: invalid type or is a list containing invalid types")
|
||||
exit(-1)
|
||||
except toml.TomlDecodeError:
|
||||
print("An error occured while decoding the file")
|
||||
exit(-1)
|
||||
except Exception as e:
|
||||
print("Error while loading file : " + str(e))
|
||||
|
||||
pprint.pprint(configuration_file)
|
||||
|
||||
# We define the app module used by Flask
|
||||
app = Flask(__name__)
|
||||
app.secret_key = b'\x98>3nM[D\xa4\xd4\xd0K\xab?oM.`\x98'
|
||||
# TODO: Get this secret key from a config file
|
||||
app.secret_key = configuration_file["secrets"]["flask_secret_key"]
|
||||
|
||||
|
||||
# Printer connection
|
||||
# Uses the class defined in the printer.py file
|
||||
|
||||
# Define the USB connections here.
|
||||
# TODO: move this to a config file
|
||||
vendor_id = 0x04b8
|
||||
device_id = 0x0e28
|
||||
|
||||
vendor_id = configuration_file["printer"]["vendor_id"]
|
||||
device_id = configuration_file["printer"]["device_id"]
|
||||
|
||||
printer = Printer(app)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user