3 from __future__ import print_function
4 from builtins import str
5 except ImportError as e:
6 print('Cannot import future modules, python2.7 future module required!')
7 print('For Debian, you can obtain is as "python-future".')
8 print('Upstream: https://python-future.org/')
15 except ImportError as e:
16 print('Cannot run gnunet-qr, please install the zbar module.')
17 print('For Debian, you can obtain it as "python-zbar".')
18 print('Upstream: http://zbar.sourceforge.net/')
24 Scan a QR code using a video device and import\n\
25 Arguments mandatory for long options are also mandatory for short options.\n\
26 -c, --config=FILENAME use configuration file FILENAME\n\
27 -d, --device=DEVICE use device DEVICE\n\
28 -s, --silent do not show preview windows\n\
29 -h, --help print this help\n\
30 -v, --verbose be verbose\n\
31 Report bugs to gnunet-developers@gnu.org.\n\
32 GNUnet home page: http://www.gnu.org/software/gnunet/\n\
33 General help using GNU software: http://www.gnu.org/gethelp/')
36 if __name__ == '__main__':
38 device = '/dev/video0'
44 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
45 except getopt.GetoptError as e:
50 if o in ("-h", "--help"):
53 elif o in ("-c", "--config"):
55 elif o in ("-d", "--device"):
57 elif o in ("-s", "--silent"):
59 elif o in ("-v", "--verbose"):
64 proc = zbar.Processor()
66 # configure the Processor
67 proc.parse_config('enable')
69 # initialize the Processor
72 print('Opening video device ' + device)
74 except Exception as e:
75 print('Failed to open device ' + device)
78 # enable the preview window
79 # if (True == silent):
82 # proc.visible = False
85 # read at least one barcode (or until window closed)
90 except Exception as e:
91 # Window was closed without finding code
94 # hide the preview window
98 for symbol in proc.results:
99 # do something useful with results
100 if (True == verbose):
101 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
103 args.append("gnunet-uri")
104 if (configuration != ''):
105 args.append(str("-c " + str(configuration)))
106 args.append(str(symbol.data))
111 print('Running `' + cmd +'`')
112 res = subprocess.call(args)
114 print('Failed to add URI ' + str(symbol.data))
116 print('Added URI ' + str(symbol.data))