aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-qr.py.in
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-12-06 12:12:09 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-12-06 12:12:09 +0000
commitf1b32958e42714ef3200563493f15dc698d837c2 (patch)
tree507cbe3227ce8253ebef95734b58eab26151edf9 /src/util/gnunet-qr.py.in
parent85fd71464332610eb7cb6a97a946b085e791d3d5 (diff)
detect python interpreter
error handling
Diffstat (limited to 'src/util/gnunet-qr.py.in')
-rwxr-xr-xsrc/util/gnunet-qr.py.in67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in
new file mode 100755
index 0000000000..086f6ae84e
--- /dev/null
+++ b/src/util/gnunet-qr.py.in
@@ -0,0 +1,67 @@
+#!@PYTHON@
+import sys
+import getopt
+from sys import argv
+try:
+ import zbar
+except ImportError as e:
+ print 'Cannot run gnunet-qr, please install zbar-python'
+ sys.exit (1)
+
+def help ():
+ print 'gnunet-qr\n\
+Scan a QR code using a video device and import\n\
+Arguments mandatory for long options are also mandatory for short options.\n\
+ -d, --device=DEVICE use device DEVICE\n\
+ -h, --help print this help\n\
+Report bugs to gnunet-developers@gnu.org.\n\
+GNUnet home page: http://www.gnu.org/software/gnunet/\n\
+General help using GNU software: http://www.gnu.org/gethelp/'
+
+
+if __name__ == '__main__':
+ # Parse arguments
+ try:
+ opts, args = getopt.gnu_getopt(sys.argv[1:], "hd:", ["help", "device"])
+ except getopt.GetoptError as e:
+ help ()
+ print str (e)
+ exit (1)
+
+ device = '/dev/video0'
+ for o,a in opts:
+ if o in ("-h", "--help"):
+ help ()
+ sys.exit (0)
+ elif o in ("-d", "--device"):
+ device = a
+ # create a Processor
+ proc = zbar.Processor()
+
+ # configure the Processor
+ proc.parse_config('enable')
+
+ # initialize the Processor
+ try:
+ proc.init(device)
+ except Exception as e:
+ print 'Failed to open device ' + device
+ exit (1)
+
+ # enable the preview window
+ proc.visible = True
+
+ # read at least one barcode (or until window closed)
+ try:
+ proc.process_one()
+ except Exception as e:
+ # Window was closed without finding code
+ exit (1)
+
+ # hide the preview window
+ proc.visible = False
+
+ # extract results
+ for symbol in proc.results:
+ # do something useful with results
+ print 'Found ', symbol.type, ' symbol ', '"%s"' % symbol.data