8 except ImportError as e:
9 print('Cannot run gnunet-qr, please install zbar-python')
15 Scan a QR code using a video device and import\n\
16 Arguments mandatory for long options are also mandatory for short options.\n\
17 -c, --config=FILENAME use configuration file FILENAME\n\
18 -d, --device=DEVICE use device DEVICE\n\
19 -s, --silent do not show preview windows\n\
20 -h, --help print this help\n\
21 -v, --verbose be verbose\n\
22 Report bugs to gnunet-developers@gnu.org.\n\
23 GNUnet home page: http://www.gnu.org/software/gnunet/\n\
24 General help using GNU software: http://www.gnu.org/gethelp/')
27 if __name__ == '__main__':
29 device = '/dev/video0'
35 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
36 except getopt.GetoptError as e:
41 if o in ("-h", "--help"):
44 elif o in ("-c", "--config"):
46 elif o in ("-d", "--device"):
48 elif o in ("-s", "--silent"):
50 elif o in ("-v", "--verbose"):
55 proc = zbar.Processor()
57 # configure the Processor
58 proc.parse_config('enable')
60 # initialize the Processor
63 print('Opening video device ' + device)
65 except Exception as e:
66 print('Failed to open device ' + device)
69 # enable the preview window
70 # if (True == silent):
73 # proc.visible = False
76 # read at least one barcode (or until window closed)
81 except Exception as e:
82 # Window was closed without finding code
85 # hide the preview window
89 for symbol in proc.results:
90 # do something useful with results
92 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
94 args.append("gnunet-uri")
95 if (configuration != ''):
96 args.append(str("-c " + str(configuration)))
97 args.append(str(symbol.data))
102 print('Running `' + cmd +'`')
103 res=subprocess.call(args)
105 print('Failed to add URI ' + str(symbol.data))
107 print('Added URI ' + str(symbol.data))