aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Gillmann <ng0@n0.is>2018-05-23 17:31:01 +0000
committerNils Gillmann <ng0@n0.is>2018-05-23 17:31:01 +0000
commit454935bd76a9106ad6eda4d5c3d0861d6e559777 (patch)
tree90d716dc77ba50292cd509e1331c4fc68296f008
parent4d34c5de8369158f903f2b709e7999cd7b9340c2 (diff)
downloadgnunet-454935bd76a9106ad6eda4d5c3d0861d6e559777.tar.gz
gnunet-454935bd76a9106ad6eda4d5c3d0861d6e559777.zip
more flakes.
Signed-off-by: Nils Gillmann <ng0@n0.is>
-rwxr-xr-xsrc/fs/test_gnunet_fs_idx.py.in60
-rwxr-xr-xsrc/fs/test_gnunet_fs_psd.py.in2
-rwxr-xr-xsrc/fs/test_gnunet_fs_rec.py.in134
-rwxr-xr-xsrc/util/gnunet-qr.py.in173
4 files changed, 186 insertions, 183 deletions
diff --git a/src/fs/test_gnunet_fs_idx.py.in b/src/fs/test_gnunet_fs_idx.py.in
index 30592c2e4..a669998fb 100755
--- a/src/fs/test_gnunet_fs_idx.py.in
+++ b/src/fs/test_gnunet_fs_idx.py.in
@@ -25,50 +25,50 @@ import re
25import shutil 25import shutil
26 26
27srcdir = "../.." 27srcdir = "../.."
28gnunet_pyexpect_dir = os.path.join (srcdir, "contrib/scripts") 28gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts")
29if gnunet_pyexpect_dir not in sys.path: 29if gnunet_pyexpect_dir not in sys.path:
30 sys.path.append (gnunet_pyexpect_dir) 30 sys.path.append(gnunet_pyexpect_dir)
31 31
32from gnunet_pyexpect import pexpect 32from gnunet_pyexpect import pexpect
33 33
34if os.name == 'posix': 34if os.name == 'posix':
35 download = './gnunet-download' 35 download = './gnunet-download'
36 gnunetarm = 'gnunet-arm' 36 gnunetarm = 'gnunet-arm'
37 publish = './gnunet-publish' 37 publish = './gnunet-publish'
38 unindex = './gnunet-unindex' 38 unindex = './gnunet-unindex'
39elif os.name == 'nt': 39elif os.name == 'nt':
40 download = './gnunet-download.exe' 40 download = './gnunet-download.exe'
41 gnunetarm = 'gnunet-arm.exe' 41 gnunetarm = 'gnunet-arm.exe'
42 publish = './gnunet-publish.exe' 42 publish = './gnunet-publish.exe'
43 unindex = './gnunet-unindex.exe' 43 unindex = './gnunet-unindex.exe'
44 44
45if os.name == "nt": 45if os.name == "nt":
46 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-idx"), True) 46 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True)
47else: 47else:
48 shutil.rmtree ("/tmp/gnunet-test-fs-py-idx", True) 48 shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True)
49 49
50arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_idx_data.conf']) 50arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_idx_data.conf'])
51arm.communicate () 51arm.communicate()
52 52
53try: 53try:
54 pub = pexpect () 54 pub = pexpect()
55 55
56 pub.spawn (None, [publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 56 pub.spawn(None, [publish, '-c', 'test_gnunet_fs_idx_data.conf', '-m', "description:Test archive", '-k', 'tst', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
57 pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n")) 57 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR\.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG\.17822'\.\r?\n"))
58 58
59 down = pexpect () 59 down = pexpect()
60 down.spawn (None, [download, '-c', 'test_gnunet_fs_idx_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 60 down.spawn(None, [download, '-c', 'test_gnunet_fs_idx_data.conf', '-o', 'test_gnunet_fs_rec_data.tar.gz', 'gnunet://fs/chk/2ZMHKPV74CB6GB1GFKQRR95BXJQA2SER25FN48GAW7WSBPA0GDEM5Y74V1ZJHM0NA6919TVW376BHTFDRE3RYS0KRY92M1QJVKPHFCR.49BT3V5C10KA1695JF71FCT8ZZG4JMJSH04BD9CT22R6KEM915A7CEST17RD0QYTHXV5M4HHEGJMEZSFRDB7JAYC0EMJAN2V781E9DG.17822'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
61 down.expect ("stdout", re.compile (r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n")) 61 down.expect("stdout", re.compile(r"Downloading `test_gnunet_fs_rec_data.tar.gz' done (.*).\r?\n"))
62 os.remove ("test_gnunet_fs_rec_data.tar.gz") 62 os.remove("test_gnunet_fs_rec_data.tar.gz")
63 63
64 un = pexpect () 64 un = pexpect()
65 un.spawn (None, [unindex, '-c', 'test_gnunet_fs_idx_data.conf', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 65 un.spawn(None, [unindex, '-c', 'test_gnunet_fs_idx_data.conf', 'test_gnunet_fs_rec_data.tgz'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
66 un.expect ("stdout", re.compile (r'Unindexing done\.\r?\n')) 66 un.expect("stdout", re.compile(r'Unindexing done\.\r?\n'))
67 67
68finally: 68finally:
69 arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf']) 69 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_idx_data.conf'])
70 arm.communicate () 70 arm.communicate()
71 if os.name == "nt": 71 if os.name == "nt":
72 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-idx"), True) 72 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-idx"), True)
73 else: 73 else:
74 shutil.rmtree ("/tmp/gnunet-test-fs-py-idx", True) 74 shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True)
diff --git a/src/fs/test_gnunet_fs_psd.py.in b/src/fs/test_gnunet_fs_psd.py.in
index b27a24c84..4b27b4532 100755
--- a/src/fs/test_gnunet_fs_psd.py.in
+++ b/src/fs/test_gnunet_fs_psd.py.in
@@ -36,7 +36,7 @@ reload(sys)
36sys.setdefaultencoding('utf8') 36sys.setdefaultencoding('utf8')
37 37
38srcdir = "../.." 38srcdir = "../.."
39gnunet_pyexpect_dir = os.path.join (srcdir, "contrib/scripts") 39gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts")
40if gnunet_pyexpect_dir not in sys.path: 40if gnunet_pyexpect_dir not in sys.path:
41 sys.path.append(gnunet_pyexpect_dir) 41 sys.path.append(gnunet_pyexpect_dir)
42 42
diff --git a/src/fs/test_gnunet_fs_rec.py.in b/src/fs/test_gnunet_fs_rec.py.in
index e20a9ff78..aa9b7b461 100755
--- a/src/fs/test_gnunet_fs_rec.py.in
+++ b/src/fs/test_gnunet_fs_rec.py.in
@@ -27,88 +27,90 @@ import tarfile
27import filecmp 27import filecmp
28 28
29srcdir = "../.." 29srcdir = "../.."
30gnunet_pyexpect_dir = os.path.join (srcdir, "contrib/scripts") 30gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts")
31if gnunet_pyexpect_dir not in sys.path: 31if gnunet_pyexpect_dir not in sys.path:
32 sys.path.append (gnunet_pyexpect_dir) 32 sys.path.append(gnunet_pyexpect_dir)
33 33
34from gnunet_pyexpect import pexpect 34from gnunet_pyexpect import pexpect
35from pydiffer import dcdiff 35from pydiffer import dcdiff
36 36
37if os.name == 'posix': 37if os.name == 'posix':
38 download = './gnunet-download' 38 download = './gnunet-download'
39 gnunetarm = 'gnunet-arm' 39 gnunetarm = 'gnunet-arm'
40 publish = './gnunet-publish' 40 publish = './gnunet-publish'
41 unindex = './gnunet-unindex' 41 unindex = './gnunet-unindex'
42 search = './gnunet-search' 42 search = './gnunet-search'
43 directory = './gnunet-directory' 43 directory = './gnunet-directory'
44elif os.name == 'nt': 44elif os.name == 'nt':
45 download = './gnunet-download.exe' 45 download = './gnunet-download.exe'
46 gnunetarm = 'gnunet-arm.exe' 46 gnunetarm = 'gnunet-arm.exe'
47 publish = './gnunet-publish.exe' 47 publish = './gnunet-publish.exe'
48 unindex = './gnunet-unindex.exe' 48 unindex = './gnunet-unindex.exe'
49 search = './gnunet-search.exe' 49 search = './gnunet-search.exe'
50 directory = './gnunet-directory.exe' 50 directory = './gnunet-directory.exe'
51 51
52if os.name == "nt": 52if os.name == "nt":
53 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-rec"), True) 53 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True)
54else: 54else:
55 shutil.rmtree ("/tmp/gnunet-test-fs-py-rec", True) 55 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True)
56 56
57arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf']) 57arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf'])
58arm.communicate () 58arm.communicate()
59 59
60# pray that `tar' is in PATH 60# pray that `tar' is in PATH.
61tar = tarfile.open ('test_gnunet_fs_rec_data.tgz') 61# FIXME: Actually we should check for that and output
62tar.extractall () 62# a message if it isn't found.
63tar = tarfile.open('test_gnunet_fs_rec_data.tgz')
64tar.extractall()
63# first, basic publish-search-download run 65# first, basic publish-search-download run
64try: 66try:
65 pub = pexpect () 67 pub = pexpect()
66 pub.spawn (None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-d', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 68 pub.spawn(None, [publish, '-c', 'test_gnunet_fs_rec_data.conf', '-d', '-k', 'testdir', 'dir/'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
67 # Can't say much for publishing, except that the last one is the toplevel directory 69 # Can't say much for publishing, except that the last one is the toplevel directory
68 pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) 70 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
69 pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 71 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"))
70 pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) 72 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
71 pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 73 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"))
72 pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) 74 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
73 pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 75 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"))
74 pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) 76 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
75 pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 77 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"))
76 pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) 78 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
77 pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 79 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"))
78 pub.expect ("stdout", re.compile (r"Publishing `.+' done\.\r?\n")) 80 pub.expect("stdout", re.compile(r"Publishing `.+' done\.\r?\n"))
79 pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n")) 81 pub.expect("stdout", re.compile(r"URI is `gnunet://fs/chk/[A-Z0-9]{103}\.[A-Z0-9]{103}\.\d+'\.\r?\n"))
80 pub.expect ("stdout", re.compile (r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n")) 82 pub.expect("stdout", re.compile(r"Publishing `.+[\\/]dir[\\/]' done\.\r?\n"))
81 m = pub.expect ("stdout", re.compile (r".+\r?\n")) 83 m = pub.expect("stdout", re.compile(r".+\r?\n"))
82 if not m: 84 if not m:
83 sys.exit (3) 85 sys.exit(3)
84 output = m.string 86 output = m.string
85 url = output[output.find ("`")+1:output.find("'")] 87 url = output[output.find("`")+1:output.find("'")]
86 88
87 down = pexpect () 89 down = pexpect()
88 down.spawn (None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 90 down.spawn(None, [download, '-c', 'test_gnunet_fs_rec_data.conf', '-R', '-o', 'rdir.gnd', url], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
89 down.expect ("stdout", re.compile (r"Downloading `rdir.gnd' done (.*).\r?\n")) 91 down.expect("stdout", re.compile(r"Downloading `rdir.gnd' done (.*).\r?\n"))
90 92
91 d = pexpect () 93 d = pexpect()
92 d.spawn (None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 94 d.spawn(None, [directory, '-c', 'test_gnunet_fs_rec_data.conf', 'rdir/a.gnd'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
93 d.expect ("stdout", re.compile (r"Directory `a/' meta data:\r?\n")) 95 d.expect("stdout", re.compile(r"Directory `a/' meta data:\r?\n"))
94 d.expect ("stdout", re.compile (r"Directory `a/' contents:\r?\n")) 96 d.expect("stdout", re.compile(r"Directory `a/' contents:\r?\n"))
95 d.expect ("stdout", re.compile (r"COPYING (.*)\r?\n")) 97 d.expect("stdout", re.compile(r"COPYING (.*)\r?\n"))
96 d.expect ("stdout", re.compile (r"INSTALL (.*)\r?\n")) 98 d.expect("stdout", re.compile(r"INSTALL (.*)\r?\n"))
99
100 os.remove("rdir/b.gnd")
101 os.remove("rdir/a.gnd")
102 diff = dcdiff('dir', 'rdir')
103 if len(diff) != 0:
104 raise Exception("Unexpected difference between source directory and downloaded result:\n{}".format(diff))
97 105
98 os.remove ("rdir/b.gnd")
99 os.remove ("rdir/a.gnd")
100 diff = dcdiff ('dir', 'rdir')
101 if len (diff) != 0:
102 raise Exception ("Unexpected difference between source directory and downloaded result:\n{}".format (diff))
103
104 106
105finally: 107finally:
106 arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf']) 108 arm = subprocess.Popen([gnunetarm, '-eq', '-c', 'test_gnunet_fs_rec_data.conf'])
107 arm.communicate () 109 arm.communicate()
108 if os.name == "nt": 110 if os.name == "nt":
109 shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-rec"), True) 111 shutil.rmtree(os.path.join(os.getenv("TEMP"), "gnunet-test-fs-py-rec"), True)
110 else: 112 else:
111 shutil.rmtree ("/tmp/gnunet-test-fs-py-rec", True) 113 shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True)
112 shutil.rmtree ("dir", True) 114 shutil.rmtree("dir", True)
113 shutil.rmtree ("rdir", True) 115 shutil.rmtree("rdir", True)
114 shutil.rmtree ("rdir.gnd", True) 116 shutil.rmtree("rdir.gnd", True)
diff --git a/src/util/gnunet-qr.py.in b/src/util/gnunet-qr.py.in
index 549ce5af1..a5918fdf8 100755
--- a/src/util/gnunet-qr.py.in
+++ b/src/util/gnunet-qr.py.in
@@ -4,105 +4,106 @@ import getopt
4import subprocess 4import subprocess
5from sys import argv 5from sys import argv
6try: 6try:
7 import zbar 7 import zbar
8except ImportError as e: 8except ImportError as e:
9 print('Cannot run gnunet-qr, please install zbar-python') 9 print('Cannot run gnunet-qr, please install zbar-python')
10 sys.exit (1) 10 sys.exit(1)
11 11
12def help (): 12
13 print('gnunet-qr\n\ 13def help():
14 print('gnunet-qr\n\
14Scan a QR code using a video device and import\n\ 15Scan a QR code using a video device and import\n\
15Arguments mandatory for long options are also mandatory for short options.\n\ 16Arguments mandatory for long options are also mandatory for short options.\n\
16 -c, --config=FILENAME use configuration file FILENAME\n\ 17 -c, --config=FILENAME use configuration file FILENAME\n\
17 -d, --device=DEVICE use device DEVICE\n\ 18 -d, --device=DEVICE use device DEVICE\n\
18 -s, --silent do not show preview windows\n\ 19 -s, --silent do not show preview windows\n\
19 -h, --help print this help\n\ 20 -h, --help print this help\n\
20 -v, --verbose be verbose\n\ 21 -v, --verbose be verbose\n\
21Report bugs to gnunet-developers@gnu.org.\n\ 22Report bugs to gnunet-developers@gnu.org.\n\
22GNUnet home page: http://www.gnu.org/software/gnunet/\n\ 23GNUnet home page: http://www.gnu.org/software/gnunet/\n\
23General help using GNU software: http://www.gnu.org/gethelp/') 24General help using GNU software: http://www.gnu.org/gethelp/')
24 25
25 26
26if __name__ == '__main__': 27if __name__ == '__main__':
27 configuration = '' 28 configuration = ''
28 device = '/dev/video0' 29 device = '/dev/video0'
29 url = '' 30 url = ''
30 verbose = False 31 verbose = False
31 silent = False 32 silent = False
32 # Parse arguments 33 # Parse arguments
33 try: 34 try:
34 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config","help", "device","silent","verbose"]) 35 opts, args = getopt.gnu_getopt(sys.argv[1:], "c:hd:sv", ["config", "help", "device", "silent", "verbose"])
35 except getopt.GetoptError as e: 36 except getopt.GetoptError as e:
36 help () 37 help()
37 print(str (e)) 38 print(str(e))
38 exit (1) 39 exit(1)
39 for o,a in opts: 40 for o, a in opts:
40 if o in ("-h", "--help"): 41 if o in ("-h", "--help"):
41 help () 42 help()
42 sys.exit (0) 43 sys.exit(0)
43 elif o in ("-c", "--config"): 44 elif o in ("-c", "--config"):
44 configuration = a 45 configuration = a
45 elif o in ("-d", "--device"): 46 elif o in ("-d", "--device"):
46 device = a 47 device = a
47 elif o in ("-s", "--silent"): 48 elif o in ("-s", "--silent"):
48 silent = True 49 silent = True
49 elif o in ("-v", "--verbose"): 50 elif o in ("-v", "--verbose"):
50 verbose = True 51 verbose = True
51 if (True == verbose): 52 if (True == verbose):
52 print('Initializing') 53 print('Initializing')
53 # create a Processor 54 # create a Processor
54 proc = zbar.Processor() 55 proc = zbar.Processor()
56
57 # configure the Processor
58 proc.parse_config('enable')
59
60 # initialize the Processor
61 try:
62 if (True == verbose):
63 print('Opening video device ' + device)
64 proc.init(device)
65 except Exception as e:
66 print('Failed to open device ' + device)
67 exit(1)
68
69 # enable the preview window
70 # if (True == silent):
71 # proc.visible = True
72 # else:
73 # proc.visible = False
74
75 proc.visible = True
76 # read at least one barcode (or until window closed)
77 try:
78 if (True == verbose):
79 print('Capturing')
80 proc.process_one()
81 except Exception as e:
82 # Window was closed without finding code
83 exit(1)
55 84
56 # configure the Processor 85 # hide the preview window
57 proc.parse_config('enable') 86 proc.visible = False
58 87
59 # initialize the Processor 88 # extract results
60 try: 89 for symbol in proc.results:
61 if (True == verbose): 90 # do something useful with results
62 print('Opening video device ' + device) 91 if (True == verbose):
63 proc.init(device) 92 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
64 except Exception as e: 93 args = list()
65 print('Failed to open device ' + device) 94 args.append("gnunet-uri")
66 exit (1) 95 if (configuration != ''):
67 96 args.append(str("-c " + str(configuration)))
68 # enable the preview window 97 args.append(str(symbol.data))
69 #if (True == silent): 98 cmd = ''
70 # proc.visible = True 99 for a in args:
71 #else: 100 cmd += " " + str(a)
72 # proc.visible = False 101 if (verbose):
73 102 print('Running `' + cmd +'`')
74 proc.visible = True 103 res=subprocess.call(args)
75 # read at least one barcode (or until window closed) 104 if (0 != res):
76 try: 105 print('Failed to add URI ' + str(symbol.data))
77 if (True == verbose): 106 else:
78 print('Capturing') 107 print('Added URI ' + str(symbol.data))
79 proc.process_one() 108 exit(res)
80 except Exception as e: 109 exit(1)
81 # Window was closed without finding code
82 exit (1)
83
84 # hide the preview window
85 proc.visible = False
86
87 # extract results
88 for symbol in proc.results:
89 # do something useful with results
90 if (True == verbose):
91 print('Found ', symbol.type, ' symbol ', '"%s"' % symbol.data)
92 args = list()
93 args.append("gnunet-uri")
94 if (configuration != ''):
95 args.append (str("-c " + str(configuration)))
96 args.append (str(symbol.data))
97 cmd = ''
98 for a in args:
99 cmd += " " + str(a)
100 if (verbose):
101 print('Running `' + cmd +'`')
102 res=subprocess.call(args)
103 if (0 != res):
104 print('Failed to add URI ' + str(symbol.data))
105 else:
106 print('Added URI ' + str(symbol.data))
107 exit (res)
108 exit (1)