2 from __future__ import print_function
3 from builtins import str
10 except ImportError as e:
11 print('Cannot run gnunet-qr, please install zbar-python')
17 Scan a QR code using a video device and import\n\
18 Arguments mandatory for long options are also mandatory for short options.\n\
19 -c, --config=FILENAME use configuration file FILENAME\n\
20 -d, --device=DEVICE use device DEVICE\n\
21 -s, --silent do not show preview windows\n\
22 -h, --help print this help\n\
23 -v, --verbose be verbose\n\
24 Report bugs to gnunet-developers@gnu.org.\n\
25 GNUnet home page: http://www.gnu.org/software/gnunet/\n\
26 General help using GNU software: http://www.gnu.org/gethelp/')
29 if __name__ == '__main__':
31 device = '/dev/video0'
37 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
38 except getopt.GetoptError as e:
43 if o in ("-h", "--help"):
46 elif o in ("-c", "--config"):
48 elif o in ("-d", "--device"):
50 elif o in ("-s", "--silent"):
52 elif o in ("-v", "--verbose"):
57 proc = zbar.Processor()
59 # configure the Processor
60 proc.parse_config('enable')
62 # initialize the Processor
65 print('Opening video device ' + device)
67 except Exception as e:
68 print('Failed to open device ' + device)
71 # enable the preview window
72 # if (True == silent):
75 # proc.visible = False
78 # read at least one barcode (or until window closed)
83 except Exception as e:
84 # Window was closed without finding code
87 # hide the preview window
91 for symbol in proc.results:
92 # do something useful with results
94 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
96 args.append("gnunet-uri")
97 if (configuration != ''):
98 args.append(str("-c " + str(configuration)))
99 args.append(str(symbol.data))
104 print('Running `' + cmd +'`')
105 res = subprocess.call(args)
107 print('Failed to add URI ' + str(symbol.data))
109 print('Added URI ' + str(symbol.data))