From a0ef820947e1666313916f31ff65f94da03345c7 Mon Sep 17 00:00:00 2001 From: Sam Cheng Date: Wed, 22 Mar 2017 15:16:07 -0700 Subject: [PATCH] add support for an ESCPOS_CAPABILITIES_FILE environment variable. This is useful in situations where package structure is changed, such as using cx-freeze --- src/escpos/capabilities.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/escpos/capabilities.py b/src/escpos/capabilities.py index e4f1a18..adebf90 100644 --- a/src/escpos/capabilities.py +++ b/src/escpos/capabilities.py @@ -1,10 +1,15 @@ import re import six -from os import path +from os import environ, path import yaml # Load external printer database -with open(path.join(path.dirname(__file__), 'capabilities.json')) as f: +if 'ESCPOS_CAPABILITIES_FILE' in environ: + file_path = environ['ESCPOS_CAPABILITIES_FILE'] +else: + file_path = path.join(path.dirname(__file__), 'capabilities.json') + +with open(file_path) as f: CAPABILITIES = yaml.load(f) PROFILES = CAPABILITIES['profiles']