forked from dfd-tud/deda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeda_compare_prints.py
executable file
·68 lines (54 loc) · 2.14 KB
/
deda_compare_prints.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2018 Timo Richter
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
"""
import argparse, os, sys
from libdeda.print_parser import PrintParser
class Main(object):
def argparser(self):
parser = argparse.ArgumentParser(
description='Compare Tracking Data from Various Printed Pages')
parser.add_argument("files", metavar="FILE", nargs="+", type=str, help='Path to Input File')
parser.add_argument("-d",'--dpi', default=0, type=int,
help='Input image dpi')
parser.add_argument("-v",'--verbose', action='count', default=0, help='Fehlerausgabe')
self.args = parser.parse_args()
def __init__(self):
self.argparser()
def __call__(self):
printers = {}
errors = []
for f in self.args.files:
try:
pp = PrintParser(f, ydxArgs=dict(inputDpi=self.args.dpi),
verbose=self.args.verbose)
except Exception as e:
errors.append((e,f))
else:
info = pp.tdm.decode()
p= info["printer"]
printers[p] = printers.get(p,[])+[(f,info)]
if len(printers) == 1 and len(errors) == 0:
print("The printers of the input have been detected as")
print("\tIDENTICAL.")
return
print("The amount of detected printers from the input is \n\t%d\n"
%len(printers))
if len(errors) > 0:
print("Errors:")
for e, f in errors:
print("%s: %s"%(str(e),f))
print()
for i, (printerId, filesinfo) in enumerate(printers.items()):
info = filesinfo[0][1]
print("Printer #%d: %s"%(i+1,info["manufacturer"]))
for f, info in filesinfo:
print("%s"%f)
print()
if __name__ == "__main__":
Main()()