From 0b122c963aad5ace73da1bd7376c8797e290c84a Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Mon, 16 Dec 2019 00:20:20 +0100 Subject: [PATCH] add generic barcode methods to bureau --- screenless/bureau/bureau.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/screenless/bureau/bureau.py b/screenless/bureau/bureau.py index b3bb788..38db6fd 100644 --- a/screenless/bureau/bureau.py +++ b/screenless/bureau/bureau.py @@ -1,6 +1,7 @@ # bureau import functools import inspect +import io import json import logging import os.path @@ -12,6 +13,7 @@ import textwrap #import traceback import threading +import barcode import lmdb import PIL import weasyprint @@ -219,6 +221,26 @@ class Bureau(object): db = KeyValStore(self.dbenv, name) return db + def bc_svg(self, code, tofile=False, outfile=None): + """ + generate a CODE128 barcode as an SVG + returns a string or can write to a tmp file or specific + file given arguments + """ + fp = io.BytesIO() + barcode.generate("CODE128", code, writer=barcode.writer.SVGWriter(), output=fp) + # TODO: add file output + return fp.read().decode() + + def bc_png(self, code, outfile=None): + """ + generate a code128 barcode as a png + returns the full path to the file + if file is not specified, uses a tmp file + """ + # TODO: implement this (its like 5 lines!) + raise NotImplemented("png generation not implemented!") + def load_config(self): """ load (or reload) config data from file