aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-qr.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-qr.py.in')
-rwxr-xr-xsrc/util/gnunet-qr.py.in173
1 files changed, 87 insertions, 86 deletions
diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in
index 549ce5af1..a5918fdf8 100755
--- a/src/util/gnunet-qr.py.in
+++ b/src/util/gnunet-qr.py.in
@@ -4,105 +4,106 @@ import getopt
4import subprocess 4import subprocess
5from sys import argv 5from sys import argv
6try: 6try:
7 import zbar 7 import zbar
8except ImportError as e: 8except ImportError as e:
9 print('Cannot run gnunet-qr, please install zbar-python') 9 print('Cannot run gnunet-qr, please install zbar-python')
10 sys.exit (1) 10 sys.exit(1)
11 11
12def help (): 12
13 print('gnunet-qr\n\ 13def help():
14 print('gnunet-qr\n\
14Scan a QR code using a video device and import\n\ 15Scan a QR code using a video device and import\n\
15Arguments mandatory for long options are also mandatory for short options.\n\ 16Arguments mandatory for long options are also mandatory for short options.\n\
16 -c, --config=FILENAME use configuration file FILENAME\n\ 17 -c, --config=FILENAME use configuration file FILENAME\n\
17 -d, --device=DEVICE use device DEVICE\n\ 18 -d, --device=DEVICE use device DEVICE\n\
18 -s, --silent do not show preview windows\n\ 19 -s, --silent do not show preview windows\n\
19 -h, --help print this help\n\ 20 -h, --help print this help\n\
20 -v, --verbose be verbose\n\ 21 -v, --verbose be verbose\n\
21Report bugs to gnunet-developers@gnu.org.\n\ 22Report bugs to gnunet-developers@gnu.org.\n\
22GNUnet home page: http://www.gnu.org/software/gnunet/\n\ 23GNUnet home page: http://www.gnu.org/software/gnunet/\n\
23General help using GNU software: http://www.gnu.org/gethelp/') 24General help using GNU software: http://www.gnu.org/gethelp/')
24 25
25 26
26if __name__ == '__main__': 27if __name__ == '__main__':
27 configuration = '' 28 configuration = ''
28 device = '/dev/video0' 29 device = '/dev/video0'
29 url = '' 30 url = ''
30 verbose = False 31 verbose = False
31 silent = False 32 silent = False
32 # Parse arguments 33 # Parse arguments
33 try: 34 try:
34 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config","help", "device","silent","verbose"]) 35 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
35 except getopt.GetoptError as e: 36 except getopt.GetoptError as e:
36 help () 37 help()
37 print(str (e)) 38 print(str(e))
38 exit (1) 39 exit(1)
39 for o,a in opts: 40 for o, a in opts:
40 if o in ("-h", "--help"): 41 if o in ("-h", "--help"):
41 help () 42 help()
42 sys.exit (0) 43 sys.exit(0)
43 elif o in ("-c", "--config"): 44 elif o in ("-c", "--config"):
44 configuration = a 45 configuration = a
45 elif o in ("-d", "--device"): 46 elif o in ("-d", "--device"):
46 device = a 47 device = a
47 elif o in ("-s", "--silent"): 48 elif o in ("-s", "--silent"):
48 silent = True 49 silent = True
49 elif o in ("-v", "--verbose"): 50 elif o in ("-v", "--verbose"):
50 verbose = True 51 verbose = True
51 if (True == verbose): 52 if (True == verbose):
52 print('Initializing') 53 print('Initializing')
53 # create a Processor 54 # create a Processor
54 proc = zbar.Processor() 55 proc = zbar.Processor()
56
57 # configure the Processor
58 proc.parse_config('enable')
59
60 # initialize the Processor
61 try:
62 if (True == verbose):
63 print('Opening video device ' + device)
64 proc.init(device)
65 except Exception as e:
66 print('Failed to open device ' + device)
67 exit(1)
68
69 # enable the preview window
70 # if (True == silent):
71 # proc.visible = True
72 # else:
73 # proc.visible = False
74
75 proc.visible = True
76 # read at least one barcode (or until window closed)
77 try:
78 if (True == verbose):
79 print('Capturing')
80 proc.process_one()
81 except Exception as e:
82 # Window was closed without finding code
83 exit(1)
55 84
56 # configure the Processor 85 # hide the preview window
57 proc.parse_config('enable') 86 proc.visible = False
58 87
59 # initialize the Processor 88 # extract results
60 try: 89 for symbol in proc.results:
61 if (True == verbose): 90 # do something useful with results
62 print('Opening video device ' + device) 91 if (True == verbose):
63 proc.init(device) 92 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
64 except Exception as e: 93 args = list()
65 print('Failed to open device ' + device) 94 args.append("gnunet-uri")
66 exit (1) 95 if (configuration != ''):
67 96 args.append(str("-c " + str(configuration)))
68 # enable the preview window 97 args.append(str(symbol.data))
69 #if (True == silent): 98 cmd = ''
70 # proc.visible = True 99 for a in args:
71 #else: 100 cmd += " " + str(a)
72 # proc.visible = False 101 if (verbose):
73 102 print('Running `' + cmd +'`')
74 proc.visible = True 103 res=subprocess.call(args)
75 # read at least one barcode (or until window closed) 104 if (0 != res):
76 try: 105 print('Failed to add URI ' + str(symbol.data))
77 if (True == verbose): 106 else:
78 print('Capturing') 107 print('Added URI ' + str(symbol.data))
79 proc.process_one() 108 exit(res)
80 except Exception as e: 109 exit(1)
81 # Window was closed without finding code
82 exit (1)
83
84 # hide the preview window
85 proc.visible = False
86
87 # extract results
88 for symbol in proc.results:
89 # do something useful with results
90 if (True == verbose):
91 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
92 args = list()
93 args.append("gnunet-uri")
94 if (configuration != ''):
95 args.append (str("-c " + str(configuration)))
96 args.append (str(symbol.data))
97 cmd = ''
98 for a in args:
99 cmd += " " + str(a)
100 if (verbose):
101 print('Running `' + cmd +'`')
102 res=subprocess.call(args)
103 if (0 != res):
104 print('Failed to add URI ' + str(symbol.data))
105 else:
106 print('Added URI ' + str(symbol.data))
107 exit (res)
108 exit (1)