Now using configuration files
This commit is contained in:
parent
8153bfd9ca
commit
e6a046d4e6
27
src/main.py
27
src/main.py
@ -8,22 +8,35 @@
|
|||||||
|
|
||||||
# Following are the librairies we import,
|
# Following are the librairies we import,
|
||||||
from flask import Flask # Used for the web framework
|
from flask import Flask # Used for the web framework
|
||||||
from printer import Printer
|
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
|
# We define the app module used by Flask
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = b'\x98>3nM[D\xa4\xd4\xd0K\xab?oM.`\x98'
|
app.secret_key = configuration_file["secrets"]["flask_secret_key"]
|
||||||
# TODO: Get this secret key from a config file
|
|
||||||
|
|
||||||
|
|
||||||
# Printer connection
|
# Printer connection
|
||||||
# Uses the class defined in the printer.py file
|
# Uses the class defined in the printer.py file
|
||||||
|
|
||||||
# Define the USB connections here.
|
# Define the USB connections here.
|
||||||
# TODO: move this to a config file
|
vendor_id = configuration_file["printer"]["vendor_id"]
|
||||||
vendor_id = 0x04b8
|
device_id = configuration_file["printer"]["device_id"]
|
||||||
device_id = 0x0e28
|
|
||||||
|
|
||||||
|
|
||||||
printer = Printer(app)
|
printer = Printer(app)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user