(scriptdirname: str, extension: str)
| 241 | |
| 242 | |
| 243 | def list_scripts(scriptdirname: str, extension: str): |
| 244 | tmp_list: list[ScriptFile] = [] |
| 245 | base = os.path.join(paths.script_path, scriptdirname) |
| 246 | if os.path.exists(base): |
| 247 | for filename in sorted(os.listdir(base)): |
| 248 | tmp_list.append(ScriptFile(paths.script_path, filename, os.path.join(base, filename), '50')) |
| 249 | for ext in extensions.active(): |
| 250 | tmp_list += ext.list_files(scriptdirname, extension) |
| 251 | priority_list: list[ScriptFile] = [] |
| 252 | for script in tmp_list: |
| 253 | if os.path.splitext(script.path)[1].lower() == extension and os.path.isfile(script.path): |
| 254 | if script.basedir == paths.script_path: |
| 255 | priority = '0' |
| 256 | elif script.basedir.startswith(os.path.join(paths.script_path, 'scripts')) or script.basedir.startswith('scripts'): |
| 257 | priority = '1' |
| 258 | elif script.basedir.startswith(os.path.join(paths.script_path, 'extensions-builtin')) or script.basedir.startswith('extensions-builtin'): |
| 259 | priority = '2' |
| 260 | elif script.basedir.startswith(os.path.join(paths.script_path, 'extensions')) or script.basedir.startswith('extensions'): |
| 261 | priority = '3' |
| 262 | else: |
| 263 | priority = '9' |
| 264 | if os.path.isfile(os.path.join(base, "..", ".priority")): |
| 265 | with open(os.path.join(base, "..", ".priority"), encoding="utf-8") as f: |
| 266 | priority = priority + str(f.read().strip()) |
| 267 | log.debug(f'Script priority override: ${script.name}:{priority}') |
| 268 | else: |
| 269 | priority = priority + script.priority |
| 270 | priority_list.append(ScriptFile(script.basedir, script.filename, script.path, priority)) |
| 271 | debug(f'Adding script: folder="{script.basedir}" file="{script.filename}" full="{script.path}" priority={priority}') |
| 272 | priority_sort = sorted(priority_list, key=lambda item: item.priority + item.path.lower(), reverse=False) |
| 273 | return priority_sort |
| 274 | |
| 275 | |
| 276 | def list_files_with_name(filename: str): |
no test coverage detected