From: ng0 Date: Tue, 26 Feb 2019 08:35:45 +0000 (+0000) Subject: Proposed fix for https://bugs.gnunet.org/view.php?id=5611 X-Git-Tag: v0.11.0~38 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5f80de3fbc0c4b43fb93d0ef4460aea16b2c78e0;p=oweals%2Fgnunet.git Proposed fix for https://bugs.gnunet.org/view.php?id=5611 --- diff --git a/src/util/Makefile.am b/src/util/Makefile.am index d1aa8aa9b..7041004ac 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -204,8 +204,15 @@ libexec_PROGRAMS = \ gnunet-timeout \ $(W32CONSOLEHELPER) +do_subst = $(SED) -e 's,[@]PREFIX[@],$(PREFIX),g' + +gnunet-qr: gnunet-qr.in Makefile + $(do_subst) < $(srcdir)/gnunet-qr.in > gnunet-qr + chmod +x gnunet-qr + bin_SCRIPTS =\ - gnunet-qr + gnunet-qr \ + gnunet-qr.py bin_PROGRAMS = \ gnunet-resolver \ @@ -236,21 +243,6 @@ gnunet_timeout_SOURCES = \ gnunet-timeout-w32.c endif -# This is horrible, but compared to the alternatives and the solution -# which preceded this it is a good compromise and good enough for one -# file. Everyone else is invited to patch it locally. -# In case someone reads this file and is wondering about the -# assignment operator below, it's explained here: -# https://lists.gnu.org/archive/html/make-w32/2013-10/msg00021.html - -xENV != which env - -do_subst = $(SED) -e 's,[@]ENV[@],${xENV},g' - -gnunet-qr: gnunet-qr.py.in Makefile - $(do_subst) < $(top_srcdir)/src/util/gnunet-qr.py.in > gnunet-qr - chmod +x gnunet-qr - gnunet_service_resolver_SOURCES = \ gnunet-service-resolver.c gnunet_service_resolver_LDADD = \ @@ -675,4 +667,5 @@ EXTRA_DIST = \ test_resolver_api_data.conf \ test_service_data.conf \ test_speedup_data.conf \ - gnunet-qr.py.in + gnunet-qr.py \ + gnunet-qr.in diff --git a/src/util/gnunet-qr.in b/src/util/gnunet-qr.in new file mode 100755 index 000000000..5e7a285ac --- /dev/null +++ b/src/util/gnunet-qr.in @@ -0,0 +1,46 @@ +#!/bin/sh +# +# From curl's buildconf, making this script subject to the +# curl license: https://curl.haxx.se/docs/copyright.html +# Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. +# Copyright (C) 2019 GNUnet e.V. + +# findtool works like which without relying on which (which is a problem +# for some limited shells. +findtool(){ + file="$1" + + if { echo "$file" | grep "/" >/dev/null 2>&1; } then + # when file is given with a path check it first + if test -f "$file"; then + echo "$file" + return + fi + fi + + old_IFS=$IFS; IFS=':' + for path in $PATH + do + IFS=$old_IFS + # echo "checks for $file in $path" >&2 + if test "$path" -a "$path" != '.' -a -f "$path/$file"; then + echo "$path/$file" + return + fi + done + IFS=$old_IFS +} + +# end curl licensed code +pythonize=`findtool python2.7 2>/dev/null` +if test ! -x "$pythonize"; then + pythonize=`findtool ${PYTHON2:-python2.7}` +fi + +if test -z "$pythonize"; then + echo "ERROR: python2.7 not found." + echo " You need python2.7 installed." + exit 1 +fi + +${pythonize} @PREFIX@/bin/gnunet-qr.py || echo "ERROR: python2.7 or future not found" && exit 1 diff --git a/src/util/gnunet-qr.py b/src/util/gnunet-qr.py new file mode 100755 index 000000000..bf35b3a7e --- /dev/null +++ b/src/util/gnunet-qr.py @@ -0,0 +1,110 @@ +from __future__ import print_function +from builtins import str +import sys +import getopt +import subprocess +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\ + -c, --config=FILENAME use configuration file FILENAME\n\ + -d, --device=DEVICE use device DEVICE\n\ + -s, --silent do not show preview windows\n\ + -h, --help print this help\n\ + -v, --verbose be verbose\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__': + configuration = '' + device = '/dev/video0' + url = '' + verbose = False + silent = False + # Parse arguments + try: + opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"]) + except getopt.GetoptError as e: + help() + print(str(e)) + exit(1) + for o, a in opts: + if o in ("-h", "--help"): + help() + sys.exit(0) + elif o in ("-c", "--config"): + configuration = a + elif o in ("-d", "--device"): + device = a + elif o in ("-s", "--silent"): + silent = True + elif o in ("-v", "--verbose"): + verbose = True + if (True == verbose): + print('Initializing') + # create a Processor + proc = zbar.Processor() + + # configure the Processor + proc.parse_config('enable') + + # initialize the Processor + try: + if (True == verbose): + print('Opening video device ' + device) + proc.init(device) + except Exception as e: + print('Failed to open device ' + device) + exit(1) + + # enable the preview window + # if (True == silent): + # proc.visible = True + # else: + # proc.visible = False + + proc.visible = True + # read at least one barcode (or until window closed) + try: + if (True == verbose): + print('Capturing') + 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 + if (True == verbose): + print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data) + args = list() + args.append("gnunet-uri") + if (configuration != ''): + args.append(str("-c " + str(configuration))) + args.append(str(symbol.data)) + cmd = '' + for a in args: + cmd += " " + str(a) + if (verbose): + print('Running `' + cmd +'`') + res = subprocess.call(args) + if (0 != res): + print('Failed to add URI ' + str(symbol.data)) + else: + print('Added URI ' + str(symbol.data)) + exit(res) + exit(1) diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in deleted file mode 100755 index ceed8bd77..000000000 --- a/src/util/gnunet-qr.py.in +++ /dev/null @@ -1,111 +0,0 @@ -#!@ENV@ python2.7 -from __future__ import print_function -from builtins import str -import sys -import getopt -import subprocess -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\ - -c, --config=FILENAME use configuration file FILENAME\n\ - -d, --device=DEVICE use device DEVICE\n\ - -s, --silent do not show preview windows\n\ - -h, --help print this help\n\ - -v, --verbose be verbose\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__': - configuration = '' - device = '/dev/video0' - url = '' - verbose = False - silent = False - # Parse arguments - try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"]) - except getopt.GetoptError as e: - help() - print(str(e)) - exit(1) - for o, a in opts: - if o in ("-h", "--help"): - help() - sys.exit(0) - elif o in ("-c", "--config"): - configuration = a - elif o in ("-d", "--device"): - device = a - elif o in ("-s", "--silent"): - silent = True - elif o in ("-v", "--verbose"): - verbose = True - if (True == verbose): - print('Initializing') - # create a Processor - proc = zbar.Processor() - - # configure the Processor - proc.parse_config('enable') - - # initialize the Processor - try: - if (True == verbose): - print('Opening video device ' + device) - proc.init(device) - except Exception as e: - print('Failed to open device ' + device) - exit(1) - - # enable the preview window - # if (True == silent): - # proc.visible = True - # else: - # proc.visible = False - - proc.visible = True - # read at least one barcode (or until window closed) - try: - if (True == verbose): - print('Capturing') - 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 - if (True == verbose): - print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data) - args = list() - args.append("gnunet-uri") - if (configuration != ''): - args.append(str("-c " + str(configuration))) - args.append(str(symbol.data)) - cmd = '' - for a in args: - cmd += " " + str(a) - if (verbose): - print('Running `' + cmd +'`') - res = subprocess.call(args) - if (0 != res): - print('Failed to add URI ' + str(symbol.data)) - else: - print('Added URI ' + str(symbol.data)) - exit(res) - exit(1)