added qr code and capacity text

This commit is contained in:
Hendrik Schutter 2022-11-22 20:10:45 +01:00
parent 963114b37a
commit ea0767a220
2 changed files with 55 additions and 32 deletions

View File

@ -4,6 +4,9 @@
""" Author: Hendrik Schutter, localhorst@mosad.xyz
Date of creation: 2022/11/16
Date of last modification: 2022/11/16
pip install qrcode
"""
import re
@ -13,18 +16,20 @@ import time
import subprocess
import shlex
import shutil
from dataclasses import dataclass
import dataclasses
import glob
import PIL
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
import datetime
import json
import qrcode
rehddversion="bV0.2.2" # read this from rehdd process
@dataclass
@dataclasses.dataclass
class DriveData:
drive_index: int
drive_state: str #none, deleted, shredded
@ -38,7 +43,7 @@ class DriveData:
shred_timestamp: int #unix timestamp
shred_duration: int #in seconds
@dataclass
@dataclasses.dataclass
class DriveDataPrintable:
modelfamiliy: str #max lenght 25
modelname: str #max lenght 25
@ -50,9 +55,20 @@ class DriveDataPrintable:
shred_timestamp: str #max lenght 25, human-readable
shred_duration: str #max lenght 25, human-readable
@dataclasses.dataclass
class ReHddInfo:
link: str
version: str
@dataclasses.dataclass
class DriveDataJson:
drive: DriveData
rehdd: ReHddInfo
rehdd_info = ReHddInfo("https://git.mosad.xyz/localhorst/reHDD", "bV0.2.2") # read this from rehdd process
temp_drive = DriveData(drive_index=0, drive_state="shredded", modelfamiliy="Toshiba 2.5\\ HDD MK..65GSSX",\
modelname="TOSHIBA MK3265GSDX", capacity=343597383680, serialnumber="70fFr-_/ tefrtg", power_on_hours=7074,\
modelname="TOSHIBA MK3265GSDX", capacity=343597383680, serialnumber="YG6742U56UDRL", power_on_hours=7074,\
power_cycle=4792, smart_error_count=1, shred_timestamp=1647937421, shred_duration=81718)
@ -99,28 +115,30 @@ def format_to_printable(drive):
cut_string(30, datetime.datetime.utcfromtimestamp(drive.shred_timestamp).strftime('%Y-%m-%d %H:%M:%S')),\
cut_string(30, str(datetime.timedelta(seconds = drive.shred_duration))))
def draw_text(drawable, printable_data, text_y_offset):
def draw_text(drawable, printable_data, text_x_offset):
font_file = get_font_path()
font_size = 20
text_x_offset = 10
text_x_offset_increment = 25
text_y_offset = 15
text_y_offset_increment = 25
drawable.text((text_y_offset, text_x_offset), "Familiy: " + printable_data.modelfamiliy,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_y_offset, text_x_offset), "Model: " + printable_data.modelname,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_y_offset, text_x_offset), "Serial: " + printable_data.serialnumber,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_y_offset, text_x_offset), "Hours: " + printable_data.power_on_hours,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_y_offset, text_x_offset), "Cycles: " + printable_data.power_cycle,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_y_offset, text_x_offset), "Errors: " + printable_data.smart_error_count,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_y_offset, text_x_offset), "Shred on: " + printable_data.shred_timestamp,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_y_offset, text_x_offset), "Duration: " + printable_data.shred_duration,(0),font=ImageFont.truetype(font_file, font_size))
text_x_offset += text_x_offset_increment
drawable.text((text_x_offset, text_y_offset), "Familiy: " + printable_data.modelfamiliy,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), "Model: " + printable_data.modelname,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), "Serial: " + printable_data.serialnumber,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), "Hours: " + printable_data.power_on_hours,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), "Cycles: " + printable_data.power_cycle,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), "Errors: " + printable_data.smart_error_count,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), "Shred on: " + printable_data.shred_timestamp,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), "Duration: " + printable_data.shred_duration,(0),font=ImageFont.truetype(font_file, font_size))
text_y_offset += text_y_offset_increment
drawable.text((text_x_offset, text_y_offset), printable_data.capacity,(0),font=ImageFont.truetype(font_file, font_size*3))
def draw_outline(drawable, margin, width, output_width, output_height):
#upper
@ -132,26 +150,31 @@ def draw_outline(drawable, margin, width, output_width, output_height):
#lower
drawable.line([(margin,output_height - margin), (output_width-margin,output_height -margin)], fill=None, width=width, joint=None)
def draw_qr_code(image, data):
qr_img = qrcode.make(data)
qr_img.thumbnail((290, 290), Image.Resampling.LANCZOS)
image.paste(qr_img, (7, 7))
def main():
output_width = 696
output_height = 348
output_height = 300
printable_data = format_to_printable(temp_drive)
print(printable_data)
qr_data = DriveDataJson(temp_drive, rehdd_info)
json_qr_daten = json.dumps(dataclasses.asdict(qr_data))
text_y_offset= int(output_width / 3)
#print(printable_data)
text_x_offset= 300
output_image = Image.new('1', (output_width, output_height), "white")
draw = ImageDraw.Draw(output_image)
draw_outline(draw, 4, 5, output_width, output_height)
draw_text(draw, printable_data, text_y_offset)
draw_outline(draw, 2, 5, output_width, output_height)
draw_text(draw, printable_data, text_x_offset)
draw_qr_code(output_image, str(json_qr_daten).replace(" ", ""))
output_image.save("output.png")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB