|
| 1 | +import pathlib |
1 | 2 | import sys
|
2 | 3 | from pathlib import Path
|
3 | 4 | from typing import Literal
|
@@ -77,15 +78,23 @@ def get_apps( # noqa: C901
|
77 | 78 | `exclude`. The incoming filter and exclude params may come in as a list or commastring.
|
78 | 79 | For the purpose of this filtering, app names and image tag prefixes are also considered as
|
79 | 80 | tags. For instance, you can do get_apps(tags=[emeriss, production], exclude=[arafire]).
|
| 81 | +
|
| 82 | + If filter is a file like name; read a list of app names from the file. |
| 83 | +
|
80 | 84 | Calling this method without any args returns all apps.
|
81 | 85 | There are three modes for communicating selected apps to the user:
|
82 | 86 | - PROMPT: Prints selected apps and asks for confirmation to proceed.
|
83 | 87 | - PREVIEW: Prints selected apps then proceeds.
|
84 | 88 | - SILENT: Proceeds without printing.
|
85 | 89 | Apps with the `inactive` tag are excluded by default, unless requested otherwise.
|
86 | 90 | """
|
| 91 | + app_names: list[str] = [] |
| 92 | + |
87 | 93 | if filter == "all":
|
88 | 94 | filter = set()
|
| 95 | + elif isinstance(filter, str) and pathlib.Path(filter).is_file(): |
| 96 | + app_names = [f.strip() for f in pathlib.Path(filter).read_text().splitlines() if f.strip()] |
| 97 | + filter = set() |
89 | 98 | else:
|
90 | 99 | filter = set(filter.split(",") if filter and isinstance(filter, str) else filter)
|
91 | 100 |
|
@@ -114,7 +123,12 @@ def get_apps( # noqa: C901
|
114 | 123 |
|
115 | 124 | tags = set(app.tags + pseudotags)
|
116 | 125 | existing_tags |= tags
|
117 |
| - if filter <= tags and not exclude & tags: |
| 126 | + |
| 127 | + # Decide whether to include the app based on the filter and exclude tags. |
| 128 | + if app_names: |
| 129 | + if app.name in app_names: |
| 130 | + apps.append(app) |
| 131 | + elif filter <= tags and not exclude & tags: |
118 | 132 | apps.append(app)
|
119 | 133 |
|
120 | 134 | validate_tags(filter | exclude, existing_tags)
|
|
0 commit comments