Skip to content
Snippets Groups Projects
Commit c679843e authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch '2-migrate-configuration-to-dynaconf' into 'master'

Resolve "Migrate configuration to dynaconf"

Closes #2

See merge request !16
parents aeae2052 09b14d43
No related branches found
No related tags found
1 merge request!16Resolve "Migrate configuration to dynaconf"
Pipeline #20874 passed
......@@ -160,4 +160,6 @@ debian/documento-printserver.*.debhelper
debian/files
barcode-tmp.pdf
config.json
\ No newline at end of file
config.json
# Ignore dynaconf secret files
.secrets.*
99-escpos.rules etc/udev/rules.d
\ No newline at end of file
99-escpos.rules etc/udev/rules.d
settings.toml etc/documento/printserver
\ No newline at end of file
{
"vendor": "0416",
"product": "5011",
"url": "http://127.0.0.1:8000",
"username": "admin",
"password": "admin",
"barcode_printer": "QL-500"
}
\ No newline at end of file
from dynaconf import Dynaconf
settings = Dynaconf(
envvar_prefix="DOCUMENTO_PRINTSERVER",
settings_files=["/etc/documento/printserver/settings.toml"],
)
import json
import subprocess # noqa
import time
......@@ -7,13 +6,11 @@ from barcode import Code128
from barcode.writer import ImageWriter
from escpos.printer import Usb
# Load config
with open("config.json") as f:
config = json.load(f)
from .config import settings
# Read vendor and product IDs from config and setup printer
raw_vendor = config.get("vendor")
raw_product = config.get("product")
raw_vendor = settings.get("printer.vendor")
raw_product = settings.get("printer.product")
vendor = int(f"0x{raw_vendor}", 16)
product = int(f"0x{raw_product}", 16)
print(f"Printer: Vendor: {raw_vendor} ({vendor}); Product: {raw_product} ({product})")
......@@ -69,7 +66,7 @@ def print_info(document, categories=None):
printer.control("LF")
base_url = config.get("url")
base_url = settings.get("server.url")
login_url = base_url + "/api/auth/login/"
jobs_url = base_url + "/api/print_jobs/"
categories_url = base_url + "/api/categories/"
......@@ -80,7 +77,10 @@ def print_server():
# Get auth token
r = requests.post(
login_url,
json={"username": config.get("username"), "password": config.get("password"),},
json={
"username": settings.get("server.username"),
"password": settings.get("server.password"),
},
)
token = r.json()["token"]
headers = {"Authorization": f"Token {token}"}
......@@ -112,7 +112,7 @@ def print_server():
# Send barcode label to printer
subprocess.Popen( # noqa
["lp", "-d", config.get("barcode_printer"), "barcode-tmp.pdf"],
["lp", "-d", settings.get("barcode_printer.name"), "barcode-tmp.pdf"],
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
) # noqa
......
......@@ -183,6 +183,23 @@ toml = "*"
[package.extras]
pipenv = ["pipenv"]
[[package]]
name = "dynaconf"
version = "3.1.4"
description = "The dynamic configurator for your Python Project"
category = "main"
optional = false
python-versions = "*"
[package.extras]
all = ["redis", "ruamel.yaml", "configobj", "hvac"]
configobj = ["configobj"]
ini = ["configobj"]
redis = ["redis"]
toml = ["toml"]
vault = ["hvac"]
yaml = ["ruamel.yaml"]
[[package]]
name = "filelock"
version = "3.0.12"
......@@ -1040,7 +1057,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytes
[metadata]
lock-version = "1.1"
python-versions = "^3.6"
content-hash = "f9b9d14acb1db63d5f985fb7967df739432cbc19255eecd5df6158ce037b8920"
content-hash = "870e1ea1a73db425d7e3b392900f102b052aa8a6e08e5d9c07967d6d5b216f03"
[metadata.files]
alabaster = [
......@@ -1161,6 +1178,10 @@ dparse = [
{file = "dparse-0.5.1-py3-none-any.whl", hash = "sha256:e953a25e44ebb60a5c6efc2add4420c177f1d8404509da88da9729202f306994"},
{file = "dparse-0.5.1.tar.gz", hash = "sha256:a1b5f169102e1c894f9a7d5ccf6f9402a836a5d24be80a986c7ce9eaed78f367"},
]
dynaconf = [
{file = "dynaconf-3.1.4-py2.py3-none-any.whl", hash = "sha256:e6f383b84150b70fc439c8b2757581a38a58d07962aa14517292dcce1a77e160"},
{file = "dynaconf-3.1.4.tar.gz", hash = "sha256:b2f472d83052f809c5925565b8a2ba76a103d5dc1dbb9748b693ed67212781b9"},
]
filelock = [
{file = "filelock-3.0.12-py3-none-any.whl", hash = "sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836"},
{file = "filelock-3.0.12.tar.gz", hash = "sha256:18d82244ee114f543149c66a6e0c14e9c4f8a1044b5cdaadd0f82159d6a6ff59"},
......
......@@ -10,6 +10,7 @@ python = "^3.6"
python-escpos = "^3.0a8"
python-barcode = "^0.13.1"
requests = "^2.25.1"
dynaconf = "^3.1.4"
[tool.poetry.dev-dependencies]
sphinx = "^3.5"
......
[printer]
vendor = "0416"
product = "5011"
[barcode_printer]
name = "QL-500"
[server]
url = "http://127.0.0.1:8000"
username = "admin"
password = "admin"
......@@ -37,7 +37,7 @@ commands =
[flake8]
max_line_length = 100
exclude = tests,.tox,.venv
exclude = tests,.tox,.venv,debian
ignore = BLK100,E203,E231,W503,D100,D101,D102,D103,D104,D105,D106,D107,RST215,RST214,F821,F841,S106,T100,T101,DJ05
[isort]
......@@ -65,3 +65,4 @@ omit =
*/tests/*
.tox/*
.venv/*
debian/*
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment