Search name in all directories specified in lookup. First without, then with common extensions. Return first hit.
(cls, name, lookup=None)
| 4221 | |
| 4222 | @classmethod |
| 4223 | def search(cls, name, lookup=None): |
| 4224 | """ Search name in all directories specified in lookup. |
| 4225 | First without, then with common extensions. Return first hit. """ |
| 4226 | if not lookup: |
| 4227 | raise depr(0, 12, "Empty template lookup path.", "Configure a template lookup path.") |
| 4228 | |
| 4229 | if os.path.isabs(name): |
| 4230 | raise depr(0, 12, "Use of absolute path for template name.", |
| 4231 | "Refer to templates with names or paths relative to the lookup path.") |
| 4232 | |
| 4233 | for spath in lookup: |
| 4234 | spath = os.path.abspath(spath) + os.sep |
| 4235 | fname = os.path.abspath(os.path.join(spath, name)) |
| 4236 | if not fname.startswith(spath): continue |
| 4237 | if os.path.isfile(fname): return fname |
| 4238 | for ext in cls.extensions: |
| 4239 | if os.path.isfile('%s.%s' % (fname, ext)): |
| 4240 | return '%s.%s' % (fname, ext) |
| 4241 | |
| 4242 | @classmethod |
| 4243 | def global_config(cls, key, *args): |