|
6 | 6 | # library: http://code.google.com/p/zxing/ |
7 | 7 | # |
8 | 8 |
|
| 9 | +import glob |
9 | 10 | import os |
10 | 11 | import pathlib |
11 | 12 | import re |
|
14 | 15 | import zipfile |
15 | 16 | from enum import Enum |
16 | 17 | from io import IOBase |
| 18 | +from itertools import chain |
17 | 19 |
|
18 | 20 | try: |
19 | 21 | from PIL.Image import Image |
@@ -50,12 +52,17 @@ def __init__(self, classpath=None, java=None): |
50 | 52 | else: |
51 | 53 | self.classpath = os.path.join(os.path.dirname(__file__), 'java', '*') |
52 | 54 |
|
53 | | - with zipfile.ZipFile(os.path.join(os.path.dirname(__file__), 'java', 'core.jar')) as c: |
54 | | - for line in c.open('META-INF/MANIFEST.MF'): |
55 | | - if line.startswith(b'Bundle-Version: '): |
56 | | - self.zxing_version = line.split(b' ', 1)[1].strip().decode() |
57 | | - self.zxing_version_info = tuple(int(n) for n in self.zxing_version.split('.')) |
58 | | - break |
| 55 | + for fn in chain.from_iterable(glob.glob(cp) for cp in self.classpath.split(':')): |
| 56 | + if os.path.basename(fn) == 'core.jar': |
| 57 | + self.core_jar = fn |
| 58 | + with zipfile.ZipFile(self.core_jar) as c: |
| 59 | + for line in c.open('META-INF/MANIFEST.MF'): |
| 60 | + if line.startswith(b'Bundle-Version: '): |
| 61 | + self.zxing_version = line.split(b' ', 1)[1].strip().decode() |
| 62 | + self.zxing_version_info = tuple(int(n) for n in self.zxing_version.split('.')) |
| 63 | + break |
| 64 | + return |
| 65 | + raise BarCodeReaderException("Java JARs not found in classpath (%s)" % self.classpath, self.classpath) |
59 | 66 |
|
60 | 67 | def decode(self, filenames, try_harder=False, possible_formats=None, pure_barcode=False, products_only=False): |
61 | 68 | possible_formats = (possible_formats,) if isinstance(possible_formats, str) else possible_formats |
|
0 commit comments