7 except ImportError as e:
8 print('Cannot run gnunet-qr, please install the zbar module.')
9 print('For Debian, you can obtain it as "python-zbar".')
10 print('Upstream: http://zbar.sourceforge.net/')
16 Scan a QR code using a video device and import\n\
17 Arguments mandatory for long options are also mandatory for short options.\n\
18 -c, --config FILENAME use configuration file FILENAME\n\
19 -d, --device DEVICE use device DEVICE\n\
20 -s, --silent do not show preview windows\n\
21 -h, --help print this help\n\
22 -v, --verbose be verbose\n\
23 Report bugs to gnunet-developers@gnu.org.\n\
24 GNUnet home page: https://gnunet.org/\n\
25 General help using GNU software: https://www.gnu.org/gethelp/')
28 if __name__ == '__main__':
30 device = '/dev/video0'
36 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
37 except getopt.GetoptError as e:
42 if o in ("-h", "--help"):
45 elif o in ("-c", "--config"):
47 elif o in ("-d", "--device"):
49 elif o in ("-s", "--silent"):
51 elif o in ("-v", "--verbose"):
56 proc = zbar.Processor()
58 # configure the Processor
59 proc.parse_config('enable')
61 # initialize the Processor
64 print('Opening video device ' + device)
66 except Exception as e:
67 print('Failed to open device ' + device)
70 # enable the preview window
71 # if (True == silent):
74 # proc.visible = False
77 # read at least one barcode (or until window closed)
82 except Exception as e:
83 # Window was closed without finding code
86 # hide the preview window
90 for symbol in proc.results:
91 # do something useful with results
93 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
95 args.append("gnunet-uri")
96 if (configuration != ''):
97 args.append(str("-c " + str(configuration)))
98 args.append(str(symbol.data))
103 print('Running `' + cmd +'`')
104 res = subprocess.call(args)
106 print('Failed to add URI ' + str(symbol.data))
108 print('Added URI ' + str(symbol.data))