-
Notifications
You must be signed in to change notification settings - Fork 3
/
printcli.py
51 lines (43 loc) · 1.69 KB
/
printcli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
from __future__ import unicode_literals
import argparse
import os
from labelprinter import Labelprinter
import labelprinterServeConf as conf
def show_config(args, labelprinter):
for var in dir(conf):
if(var.isupper()):
print("{} = {}".format(var, conf.__getattribute__(var)))
def text(args, labelprinter):
bold = 'on' if args.bold else 'off'
if isinstance(args.text, bytes):
text = args.text.decode('utf-8')
else:
text = args.text
labelprinter.printText(text,
charSize=args.char_size,
font=args.font,
align=args.align,
bold=bold,
charStyle=args.char_style,
cut=args.cut
)
parser = argparse.ArgumentParser(description="A command line interface to Labello.")
subparsers = parser.add_subparsers(help="commands")
parser_text = subparsers.add_parser("text", help="print a text")
parser_text.add_argument("text", type=str, help="the text to print")
parser_text.add_argument("--char_size", type=str, default='42')
parser_text.add_argument("--font", type=str, default='lettergothic')
parser_text.add_argument("--align", type=str, default='left')
parser_text.add_argument("--bold", action='store_true')
parser_text.add_argument("--char_style", type=str, default='normal')
parser_text.add_argument("--cut", type=str, default='full')
parser_text.set_defaults(func=text)
parser_config = subparsers.add_parser("config", help="show the config")
parser_config.set_defaults(func=show_config)
args = parser.parse_args()
if args.func != show_config:
labelprinter = Labelprinter(conf=conf)
else:
labelprinter = None
args.func(args, labelprinter)