aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-12-06 12:26:29 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-12-06 12:26:29 +0000
commit3492d89c6eeebe01c2a1a1400ba84dd7b68357bf (patch)
tree3049a4a4355d61f9a3a91e7f4ac137029adfb3ef /src/util
parenta3bbceff63833f97f0d517caa85826c3cbf4f2ff (diff)
downloadgnunet-3492d89c6eeebe01c2a1a1400ba84dd7b68357bf.tar.gz
gnunet-3492d89c6eeebe01c2a1a1400ba84dd7b68357bf.zip
added config + silent mode
Diffstat (limited to 'src/util')
-rwxr-xr-xsrc/util/gnunet-qr.py.in95
1 files changed, 53 insertions, 42 deletions
diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in
index 086f6ae84..de4849023 100755
--- a/src/util/gnunet-qr.py.in
+++ b/src/util/gnunet-qr.py.in
@@ -12,7 +12,9 @@ def help ():
12 print 'gnunet-qr\n\ 12 print 'gnunet-qr\n\
13Scan a QR code using a video device and import\n\ 13Scan a QR code using a video device and import\n\
14Arguments mandatory for long options are also mandatory for short options.\n\ 14Arguments mandatory for long options are also mandatory for short options.\n\
15 -c, --config=FILENAME use configuration file FILENAME\n\
15 -d, --device=DEVICE use device DEVICE\n\ 16 -d, --device=DEVICE use device DEVICE\n\
17 -s, --silent do not show preview windows\n\
16 -h, --help print this help\n\ 18 -h, --help print this help\n\
17Report bugs to gnunet-developers@gnu.org.\n\ 19Report bugs to gnunet-developers@gnu.org.\n\
18GNUnet home page: http://www.gnu.org/software/gnunet/\n\ 20GNUnet home page: http://www.gnu.org/software/gnunet/\n\
@@ -20,48 +22,57 @@ General help using GNU software: http://www.gnu.org/gethelp/'
20 22
21 23
22if __name__ == '__main__': 24if __name__ == '__main__':
23 # Parse arguments 25 configuration = ''
24 try: 26 device = '/dev/video0'
25 opts, args = getopt.gnu_getopt(sys.argv[1:], "hd:", ["help", "device"]) 27 silent = False
26 except getopt.GetoptError as e: 28 # Parse arguments
27 help () 29 try:
28 print str (e) 30 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:s", ["config","help", "device","silent"])
29 exit (1) 31 except getopt.GetoptError as e:
30 32 help ()
31 device = '/dev/video0' 33 print str (e)
32 for o,a in opts: 34 exit (1)
33 if o in ("-h", "--help"):
34 help ()
35 sys.exit (0)
36 elif o in ("-d", "--device"):
37 device = a
38 # create a Processor
39 proc = zbar.Processor()
40 35
41 # configure the Processor 36 for o,a in opts:
42 proc.parse_config('enable') 37 if o in ("-h", "--help"):
38 help ()
39 sys.exit (0)
40 elif o in ("-c", "--config"):
41 configuration = a
42 elif o in ("-d", "--device"):
43 device = a
44 elif o in ("-s", "--silent"):
45 silent = True
46 # create a Processor
47 proc = zbar.Processor()
43 48
44 # initialize the Processor 49 # configure the Processor
45 try: 50 proc.parse_config('enable')
46 proc.init(device)
47 except Exception as e:
48 print 'Failed to open device ' + device
49 exit (1)
50 51
51 # enable the preview window 52 # initialize the Processor
52 proc.visible = True 53 try:
53 54 proc.init(device)
54 # read at least one barcode (or until window closed) 55 except Exception as e:
55 try: 56 print 'Failed to open device ' + device
56 proc.process_one() 57 exit (1)
57 except Exception as e: 58
58 # Window was closed without finding code 59 # enable the preview window
59 exit (1) 60 if (True == silent):
60 61 proc.visible = True
61 # hide the preview window 62 else:
62 proc.visible = False 63 proc.visible = False
63 64
64 # extract results 65 # read at least one barcode (or until window closed)
65 for symbol in proc.results: 66 try:
66 # do something useful with results 67 proc.process_one()
67 print 'Found ', symbol.type, ' symbol ', '"%s"' % symbol.data 68 except Exception as e:
69 # Window was closed without finding code
70 exit (1)
71
72 # hide the preview window
73 proc.visible = False
74
75 # extract results
76 for symbol in proc.results:
77 # do something useful with results
78 print 'Found ', symbol.type, ' symbol ', '"%s"' % symbol.data \ No newline at end of file