From a3185bdce4f8f7bf85930eb11de3ab6bf6a9730e Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Tue, 8 Jul 2014 16:38:04 +0200 Subject: [PATCH] initial commit --- .gitignore | 1 + .gitmodules | 3 ++ AdafruitThermal.py | 1 + __init__.py | 0 dump.py | 68 +++++++++++++++++++++++++++++++++++++++++++++ logo_crans.png | Bin 0 -> 1308 bytes printlib | 1 + 7 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 120000 AdafruitThermal.py create mode 100644 __init__.py create mode 100755 dump.py create mode 100644 logo_crans.png create mode 160000 printlib diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1140917 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "printlib"] + path = printlib + url = https://github.com/adafruit/Python-Thermal-Printer.git diff --git a/AdafruitThermal.py b/AdafruitThermal.py new file mode 120000 index 0000000..2702284 --- /dev/null +++ b/AdafruitThermal.py @@ -0,0 +1 @@ +printlib/Adafruit_Thermal.py \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dump.py b/dump.py new file mode 100755 index 0000000..191adc6 --- /dev/null +++ b/dump.py @@ -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': '', + '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) diff --git a/logo_crans.png b/logo_crans.png new file mode 100644 index 0000000000000000000000000000000000000000..c9caeec47dba831412ea72b427eecb90232c99bf GIT binary patch literal 1308 zcmV+%1>^dOP)QSWP)YQnt*|^9ZqbG4O&1`Fr;8Z)PkO<(=(`K3n(3>JG)T5KA5T~&zx~v zT@fAPQ|K(BsO%)CqnJANX!>{ld6mWSvCr*@H_fJ_6?{0B?D$Rz_q6p-StP$yvF=L(`GYLQOI6M)Z0Lo@)r15LolPwRwl zJyX;Gl!iQ;w>&;MV2l)M84nw3rV*n^C6qEQeh1_L=eiGbD06=K@vwH&y3mLNzOBb8 zI4GU;jLHB-C#S3sg~?YgO|#=OHD%a%(89>mh3K}MbJ;wo29>Tjw6WIh zgA{L|oorWjie1z&-Jx|cheg?gZh;~sTHba@>g65{@lL~kp=AQzM0CRWTJ?RZGxhKv zi0FtXOhOHmy)B_Dok$7IExD7@gc+mI(raQo3rBM&m=E{AM18qEAa#_FhIgoG6oZ`0d@S54aB*k>gqCt|X)4qc9gr5&QMJ)|pyzec zCCi1Lu8rFK1jcGgmV=(cg~kg7hEmQV>hRQLIvmrv(8*EZ(5WQPuRZmY|A^8?L5d^$ z3aL-WSjje|lTl+mQIapjV5(V%@Lhzt9ha7fCe1%k32tDH1HG~l9xP^ zQ9x5o;#bu3v@}nDsk`*|){^Zg8^GJ;W6K??ms%I^QyXis+f!~{J+-AkFse|b0+-I$6%irVs)Ymq< zf7Pj*s&z}sX-~&)s?t_$<~{AVUu-e2YDd>T)E2!T_jKut+%BXmIpKu8P literal 0 HcmV?d00001 diff --git a/printlib b/printlib new file mode 160000 index 0000000..027f158 --- /dev/null +++ b/printlib @@ -0,0 +1 @@ +Subproject commit 027f158ddfdcaa9395bb5704dcd6a12436a1a302