commit a3185bdce4f8f7bf85930eb11de3ab6bf6a9730e Author: Daniel STAN Date: Tue Jul 8 16:38:04 2014 +0200 initial commit 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 0000000..c9caeec Binary files /dev/null and b/logo_crans.png differ diff --git a/printlib b/printlib new file mode 160000 index 0000000..027f158 --- /dev/null +++ b/printlib @@ -0,0 +1 @@ +Subproject commit 027f158ddfdcaa9395bb5704dcd6a12436a1a302