diff options
author | Nils Gillmann <ng0@n0.is> | 2018-05-23 17:31:01 +0000 |
---|---|---|
committer | Nils Gillmann <ng0@n0.is> | 2018-05-23 17:31:01 +0000 |
commit | 454935bd76a9106ad6eda4d5c3d0861d6e559777 (patch) | |
tree | 90d716dc77ba50292cd509e1331c4fc68296f008 | |
parent | 4d34c5de8369158f903f2b709e7999cd7b9340c2 (diff) | |
download | gnunet-454935bd76a9106ad6eda4d5c3d0861d6e559777.tar.gz gnunet-454935bd76a9106ad6eda4d5c3d0861d6e559777.zip |
more flakes.
Signed-off-by: Nils Gillmann <ng0@n0.is>
-rwxr-xr-x | src/fs/test_gnunet_fs_idx.py.in | 60 | ||||
-rwxr-xr-x | src/fs/test_gnunet_fs_psd.py.in | 2 | ||||
-rwxr-xr-x | src/fs/test_gnunet_fs_rec.py.in | 134 | ||||
-rwxr-xr-x | src/util/gnunet-qr.py.in | 173 |
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 | |||
25 | import shutil | 25 | import shutil |
26 | 26 | ||
27 | srcdir = "../.." | 27 | srcdir = "../.." |
28 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib/scripts") | 28 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
29 | if gnunet_pyexpect_dir not in sys.path: | 29 | if gnunet_pyexpect_dir not in sys.path: |
30 | sys.path.append (gnunet_pyexpect_dir) | 30 | sys.path.append(gnunet_pyexpect_dir) |
31 | 31 | ||
32 | from gnunet_pyexpect import pexpect | 32 | from gnunet_pyexpect import pexpect |
33 | 33 | ||
34 | if os.name == 'posix': | 34 | if 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' |
39 | elif os.name == 'nt': | 39 | elif 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 | ||
45 | if os.name == "nt": | 45 | if 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) |
47 | else: | 47 | else: |
48 | shutil.rmtree ("/tmp/gnunet-test-fs-py-idx", True) | 48 | shutil.rmtree("/tmp/gnunet-test-fs-py-idx", True) |
49 | 49 | ||
50 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_idx_data.conf']) | 50 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_idx_data.conf']) |
51 | arm.communicate () | 51 | arm.communicate() |
52 | 52 | ||
53 | try: | 53 | try: |
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 | ||
68 | finally: | 68 | finally: |
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) | |||
36 | sys.setdefaultencoding('utf8') | 36 | sys.setdefaultencoding('utf8') |
37 | 37 | ||
38 | srcdir = "../.." | 38 | srcdir = "../.." |
39 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib/scripts") | 39 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
40 | if gnunet_pyexpect_dir not in sys.path: | 40 | if 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 | |||
27 | import filecmp | 27 | import filecmp |
28 | 28 | ||
29 | srcdir = "../.." | 29 | srcdir = "../.." |
30 | gnunet_pyexpect_dir = os.path.join (srcdir, "contrib/scripts") | 30 | gnunet_pyexpect_dir = os.path.join(srcdir, "contrib/scripts") |
31 | if gnunet_pyexpect_dir not in sys.path: | 31 | if gnunet_pyexpect_dir not in sys.path: |
32 | sys.path.append (gnunet_pyexpect_dir) | 32 | sys.path.append(gnunet_pyexpect_dir) |
33 | 33 | ||
34 | from gnunet_pyexpect import pexpect | 34 | from gnunet_pyexpect import pexpect |
35 | from pydiffer import dcdiff | 35 | from pydiffer import dcdiff |
36 | 36 | ||
37 | if os.name == 'posix': | 37 | if 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' |
44 | elif os.name == 'nt': | 44 | elif 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 | ||
52 | if os.name == "nt": | 52 | if 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) |
54 | else: | 54 | else: |
55 | shutil.rmtree ("/tmp/gnunet-test-fs-py-rec", True) | 55 | shutil.rmtree("/tmp/gnunet-test-fs-py-rec", True) |
56 | 56 | ||
57 | arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf']) | 57 | arm = subprocess.Popen([gnunetarm, '-sq', '-c', 'test_gnunet_fs_rec_data.conf']) |
58 | arm.communicate () | 58 | arm.communicate() |
59 | 59 | ||
60 | # pray that `tar' is in PATH | 60 | # pray that `tar' is in PATH. |
61 | tar = tarfile.open ('test_gnunet_fs_rec_data.tgz') | 61 | # FIXME: Actually we should check for that and output |
62 | tar.extractall () | 62 | # a message if it isn't found. |
63 | tar = tarfile.open('test_gnunet_fs_rec_data.tgz') | ||
64 | tar.extractall() | ||
63 | # first, basic publish-search-download run | 65 | # first, basic publish-search-download run |
64 | try: | 66 | try: |
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 | ||
105 | finally: | 107 | finally: |
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 | |||
4 | import subprocess | 4 | import subprocess |
5 | from sys import argv | 5 | from sys import argv |
6 | try: | 6 | try: |
7 | import zbar | 7 | import zbar |
8 | except ImportError as e: | 8 | except 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 | ||
12 | def help (): | 12 | |
13 | print('gnunet-qr\n\ | 13 | def help(): |
14 | print('gnunet-qr\n\ | ||
14 | Scan a QR code using a video device and import\n\ | 15 | Scan a QR code using a video device and import\n\ |
15 | Arguments mandatory for long options are also mandatory for short options.\n\ | 16 | Arguments 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\ |
21 | Report bugs to gnunet-developers@gnu.org.\n\ | 22 | Report bugs to gnunet-developers@gnu.org.\n\ |
22 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ | 23 | GNUnet home page: http://www.gnu.org/software/gnunet/\n\ |
23 | General help using GNU software: http://www.gnu.org/gethelp/') | 24 | General help using GNU software: http://www.gnu.org/gethelp/') |
24 | 25 | ||
25 | 26 | ||
26 | if __name__ == '__main__': | 27 | if __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) | ||