Overview
Comment:shift warning for undiscoverable modules
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 18c5918a6d4cdba063ae15f344c155e4f3a79343f932b106dd7237068147a127
User & Date: mario on 2022-11-01 23:30:26
Other Links: manifest | tags
Context
2022-11-12
15:25
introduce plugin_icon() for gui window check-in: 64c2c60322 user: mario tags: trunk
2022-11-01
23:30
shift warning for undiscoverable modules check-in: 18c5918a6d user: mario tags: trunk
23:30
predefine conf[plugins], note .base(__package__) as example check-in: 94218baefa user: mario tags: trunk
Changes

Modified pluginconf/__init__.py from [295be38bfd] to [8fbfda3a70].

183
184
185
186
187
188
189
190

191
192
193
194
195
196
197
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197







-
+







        return execute
    return wrapped


# Resource retrieval
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
@renamed_arguments({"fn": "filename", "gz": "gzip"})
def get_data(filename, decode=False, gzip=False, file_root=None):
def get_data(filename, decode=False, gzip=False, file_root=None, warn=True):
    """
    Fetches file content from install path or from within PYZ
    archive. This is just an alias and convenience wrapper for
    pkgutil.get_data().
    Utilizes the data_root as top-level reference.

    | Parameters  | | |
206
207
208
209
210
211
212

213

214
215
216
217
218
219
220
206
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







+
-
+







        data = pkgutil.get_data(file_root or data_root, filename)
        if gzip:
            data = gzip_decode(data)
        if decode:
            return data.decode("utf-8", errors='ignore')
        return str(data)
    except: #(FileNotFoundError, IOError, OSError, ImportError, gzip.BadGzipFile):
        if warn:
        log.warning("get_data() didn't find '%s' in '%s'", filename, file_root)
            log.warning("get_data() didn't find '%s' in '%s'", filename, file_root)


# Plugin name lookup
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
def module_list(extra_paths=None):
    """
    Search through ./plugins/ (and other configured plugin_base
287
288
289
290
291
292
293
294

295
296
297
298


299
300
301
302
303
304
305
288
289
290
291
292
293
294

295
296
297
298
299
300
301
302
303
304
305
306
307
308







-
+




+
+







    # Try via pkgutil first,
    # find any plugins.* modules, or main packages
    if module:
        search = plugin_base + kwargs.get("extra_base", [])
        for base, sfx in itertools.product(search, [".py", "/__init__.py"]):
            try:
                #log.debug(f"mod={base} fn={filename}.py")
                src = get_data(filename=module+sfx, decode=True, file_root=base)
                src = get_data(filename=module+sfx, decode=True, file_root=base, warn=False)
                if src:
                    break
            except (IOError, OSError, FileNotFoundError):
                continue  # plugin_meta_extract() will print a notice later
        else:
            log.warning("Found no source candidate for '%s'", module)
        filename = module

    # Real filename/path
    elif filename and os.path.exists(filename):
        src = open(filename).read(kwargs.get("max_length", 6144))

    # Else get source directly from caller