initial commit
This commit is contained in:
commit
a3185bdce4
7 changed files with 74 additions and 0 deletions
68
dump.py
Executable file
68
dump.py
Executable file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
# Bad namming: change namming
|
||||
from AdafruitThermal import Adafruit_Thermal as AdafruitThermal
|
||||
import subprocess, time, Image, socket
|
||||
import os
|
||||
import json
|
||||
|
||||
#
|
||||
CODING='cp437'
|
||||
DEVICE="/dev/ttyUSB0"
|
||||
SAMPLE_MACHINE = {
|
||||
'login': 'cerveaulent',
|
||||
'macAddress': '<automatique>',
|
||||
'pass': '**********',
|
||||
}
|
||||
|
||||
# Load data
|
||||
crans_logo = Image.open(os.path.join(os.path.dirname(__file__), 'logo_crans.png'))
|
||||
|
||||
if not sys.argv[1:]:
|
||||
liste = [SAMPLE_MACHINE]
|
||||
else:
|
||||
with open(sys.argv[1], 'r') as f:
|
||||
liste = json.load(f)
|
||||
|
||||
printer = AdafruitThermal(DEVICE, 19200, timeout=5)
|
||||
|
||||
printer.setDefault() # Restore printer to defaults
|
||||
printer.printImage(crans_logo, True)
|
||||
|
||||
def print_carac(text, value):
|
||||
printer.justify('L')
|
||||
pad = 384/12 - len(text) - len(value)
|
||||
printer.println(text + ('.'*pad) + value )
|
||||
|
||||
|
||||
def show_machine(machine):
|
||||
printer.justify('C')
|
||||
printer.underlineOn()
|
||||
printer.println(u'Détails machine'.encode(CODING))
|
||||
printer.underlineOff()
|
||||
printer.justify('L')
|
||||
|
||||
print_carac('Login', machine['login'])
|
||||
if machine.has_key('macAddress'):
|
||||
print_carac('Mac', machine['macAddress'])
|
||||
if machine.has_key('pass'):
|
||||
print_carac('Mot de passe', machine['pass'])
|
||||
|
||||
printer.feed(1)
|
||||
|
||||
|
||||
# Do print
|
||||
first = True
|
||||
|
||||
for m in liste:
|
||||
if not first:
|
||||
print_carac('','')
|
||||
first = False
|
||||
show_machine(m)
|
||||
|
||||
printer.println(u'Veuillez conserver ces informations en lieu sûr.'.encode(CODING))
|
||||
|
||||
printer.feed(2)
|
Loading…
Add table
Add a link
Reference in a new issue