-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdcp1610-scan
executable file
·49 lines (37 loc) · 1.87 KB
/
dcp1610-scan
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
#! /usr/bin/env python3
import argparse
import logging
import dcp1610.protocol
import dcp1610.discovery
logger = logging.getLogger(__name__)
def main():
prs = argparse.ArgumentParser()
prs.add_argument('-d', '--dpi', default=100, type=int,
help="Scan resolution. If the scanner does not support specified value, the best matching supported one will be used")
prs.add_argument('--color', action='store_true',
help="Color scan")
prs.add_argument('-X', default='0.0', type=float,
help="Origin X. Float in range (0,1) means fraction of page, integer > 1 is pixels")
prs.add_argument('-Y', default='0.0', type=float,
help="Origin Y")
prs.add_argument('-W', default='1.0', type=float,
help="Image width, pixels or fraction of page size")
prs.add_argument('-H', default='1.0', type=float,
help="Image height, pixels or fraction of page size")
prs.add_argument('-v', action='store_true',
help="Pring more logs")
prs.add_argument('-o', '--output', default="scan.png",
help="Output file name")
prs.add_argument('address', help="Scanner ip address/hostname, required argument", nargs='?')
args = prs.parse_args()
logging.basicConfig(format='[%(asctime)s] %(message)s',
level=logging.DEBUG if args.v else logging.INFO)
address = args.address
if not address:
address, name = dcp1610.discovery.find_scanner()
logger.info("No address specified, using discovered %s (%s)", name, address)
task = dcp1610.protocol.ScanTask(address, args.W, args.H, args.X, args.Y, args.dpi,
dcp1610.protocol.MODE_CGRAY if args.color else dcp1610.protocol.MODE_GRAY64)
task.do_scan(args.output)
if __name__ == '__main__':
main()