diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-12-06 10:55:43 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-12-06 10:55:43 +0000 |
commit | 85fd71464332610eb7cb6a97a946b085e791d3d5 (patch) | |
tree | d4f7b048184dc2a68cc24828ef0f8ce5615d8c99 /src/util | |
parent | d36b092325e6b819da5d7d7bb591fee9ed71d57c (diff) | |
download | gnunet-85fd71464332610eb7cb6a97a946b085e791d3d5.tar.gz gnunet-85fd71464332610eb7cb6a97a946b085e791d3d5.zip |
basic qr code reading
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 3 | ||||
-rwxr-xr-x | src/util/gnunet-qr | 64 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index a9b4e09da..851b4b521 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -128,6 +128,9 @@ endif | |||
128 | libexec_PROGRAMS = \ | 128 | libexec_PROGRAMS = \ |
129 | gnunet-service-resolver | 129 | gnunet-service-resolver |
130 | 130 | ||
131 | bin_SCRIPTS =\ | ||
132 | gnunet-qr | ||
133 | |||
131 | bin_PROGRAMS = \ | 134 | bin_PROGRAMS = \ |
132 | gnunet-resolver \ | 135 | gnunet-resolver \ |
133 | gnunet-config \ | 136 | gnunet-config \ |
diff --git a/src/util/gnunet-qr b/src/util/gnunet-qr new file mode 100755 index 000000000..a025d0479 --- /dev/null +++ b/src/util/gnunet-qr | |||
@@ -0,0 +1,64 @@ | |||
1 | #!/usr/bin/python | ||
2 | import sys | ||
3 | import getopt | ||
4 | from sys import argv | ||
5 | try: | ||
6 | import zbar | ||
7 | except ImportError as e: | ||
8 | print 'Cannot run gnunet-qr, please install zbar-python' | ||
9 | sys.exit (1) | ||
10 | |||
11 | def help (): | ||
12 | print 'gnunet-qr\n\ | ||
13 | Scan a QR code using a video device and import\n\ | ||
14 | Arguments mandatory for long options are also mandatory for short options.\n\ | ||
15 | -d, --device=DEVICE use device DEVICE\n\ | ||
16 | -h, --help print this help\n\ | ||
17 | Report bugs to gnunet-developers@gnu.org.\n\ | ||
18 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ | ||
19 | General help using GNU software: http://www.gnu.org/gethelp/' | ||
20 | |||
21 | |||
22 | if __name__ == '__main__': | ||
23 | # Parse arguments | ||
24 | try: | ||
25 | opts, args = getopt.gnu_getopt(sys.argv[1:], "hd:", ["help", "device"]) | ||
26 | except getopt.GetoptError as e: | ||
27 | help () | ||
28 | print str (e) | ||
29 | exit (1) | ||
30 | |||
31 | device = '/dev/video0' | ||
32 | for o,a in opts: | ||
33 | if o in ("-h", "--help"): | ||
34 | help () | ||
35 | sys.exit (0) | ||
36 | elif o in ("-d", "--device"): | ||
37 | device = a | ||
38 | |||
39 | # create a Processor | ||
40 | proc = zbar.Processor() | ||
41 | |||
42 | # configure the Processor | ||
43 | proc.parse_config('enable') | ||
44 | |||
45 | # initialize the Processor | ||
46 | proc.init(device) | ||
47 | |||
48 | # enable the preview window | ||
49 | proc.visible = True | ||
50 | |||
51 | # read at least one barcode (or until window closed) | ||
52 | try: | ||
53 | proc.process_one() | ||
54 | except Exception as e: | ||
55 | # Window was closed without finding code | ||
56 | exit (1) | ||
57 | |||
58 | # hide the preview window | ||
59 | proc.visible = False | ||
60 | |||
61 | # extract results | ||
62 | for symbol in proc.results: | ||
63 | # do something useful with results | ||
64 | print 'Found ', symbol.type, ' symbol ', '"%s"' % symbol.data | ||