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!')
13 except ImportError as e:
14 print('Cannot run gnunet-qr, please install zbar-python')
20 Scan a QR code using a video device and import\n\
21 Arguments mandatory for long options are also mandatory for short options.\n\
22 -c, --config=FILENAME use configuration file FILENAME\n\
23 -d, --device=DEVICE use device DEVICE\n\
24 -s, --silent do not show preview windows\n\
25 -h, --help print this help\n\
26 -v, --verbose be verbose\n\
27 Report bugs to gnunet-developers@gnu.org.\n\
28 GNUnet home page: http://www.gnu.org/software/gnunet/\n\
29 General help using GNU software: http://www.gnu.org/gethelp/')
32 if __name__ == '__main__':
34 device = '/dev/video0'
40 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
41 except getopt.GetoptError as e:
46 if o in ("-h", "--help"):
49 elif o in ("-c", "--config"):
51 elif o in ("-d", "--device"):
53 elif o in ("-s", "--silent"):
55 elif o in ("-v", "--verbose"):
60 proc = zbar.Processor()
62 # configure the Processor
63 proc.parse_config('enable')
65 # initialize the Processor
68 print('Opening video device ' + device)
70 except Exception as e:
71 print('Failed to open device ' + device)
74 # enable the preview window
75 # if (True == silent):
78 # proc.visible = False
81 # read at least one barcode (or until window closed)
86 except Exception as e:
87 # Window was closed without finding code
90 # hide the preview window
94 for symbol in proc.results:
95 # do something useful with results
97 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
99 args.append("gnunet-uri")
100 if (configuration != ''):
101 args.append(str("-c " + str(configuration)))
102 args.append(str(symbol.data))
107 print('Running `' + cmd +'`')
108 res = subprocess.call(args)
110 print('Failed to add URI ' + str(symbol.data))
112 print('Added URI ' + str(symbol.data))