You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: buildtest/cli/buildspec.py
+37-4Lines changed: 37 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,7 @@ def __init__(
50
50
filterfields=None,
51
51
formatfields=None,
52
52
directory=None,
53
+
buildspec_files=None,
53
54
header=None,
54
55
terse=None,
55
56
pager=None,
@@ -71,6 +72,7 @@ def __init__(
71
72
filterfields (str, optional): The filter options specified via ``buildtest buildspec find --filter`` that contains list of key value pairs for filtering buildspecs
72
73
formatfields (str, optional): The format options used for formating table. The format option is a comma separated list of format fields specified via ``buildtest buildspec find --format``
73
74
directory (list, optional): List of directories to search for buildspecs. This argument contains value of ``buildtest buildspec find --directory``
75
+
buildspec_files (list, optional): List of buildspec files to add to cache. This argument contains value of ``buildtest buildspec find --file``
74
76
headers (bool, optional): Option to control whether header are printed in terse output. This argument contains value of ``buildtest buildspec find --no-header``
75
77
terse (bool, optional): Enable terse mode when printing output. In this mode we don't print output in table format instead output is printed in parseable format. This option can be specified via ``buildtest buildspec find --terse``
76
78
color (str, optional): An instance of a string class that selects the color to use when printing table output
@@ -107,6 +109,8 @@ def __init__(
107
109
# list of buildspec directories to search for .yml files
108
110
self.paths= []
109
111
112
+
self.buildspec_files=buildspec_files
113
+
110
114
# stores invalid buildspecs and the error messages
111
115
self.invalid_buildspecs= {}
112
116
@@ -149,12 +153,12 @@ def load_paths(self):
149
153
ifnotself.directory:
150
154
self.paths+=BUILDSPEC_DEFAULT_PATH
151
155
152
-
# for every root buildspec defined in configuration or via --root option,
156
+
# for every root buildspec defined in configuration or via --directory option,
153
157
# we resolve path and if path exist add to self.paths. The path must be a
154
158
# directory. If its file, we ignore it
155
159
ifself.directory:
156
-
forrootinself.directory:
157
-
path=resolve_path(root, exist=False)
160
+
fordirnameinself.directory:
161
+
path=resolve_path(dirname, exist=False)
158
162
ifnotos.path.exists(path):
159
163
console.print(f"[red]Path: {path} does not exist!")
160
164
@@ -169,6 +173,31 @@ def build(self):
169
173
rebuild cache we remove the file and recreate cache. If cache file
170
174
exists, we simply load from cache
171
175
"""
176
+
buildspecs= []
177
+
# this method will check if buildspec_files are valid files and end with .yml.
178
+
# If it's not a file or does not end with .yml we skip the file and report a message
179
+
180
+
ifself.buildspec_files:
181
+
forbuildspecinself.buildspec_files:
182
+
path=resolve_path(buildspec, exist=False)
183
+
ifnotos.path.exists(path):
184
+
console.print(f"[red]Path: {path} does not exist!")
185
+
continue
186
+
ifnotis_file(path):
187
+
console.print(
188
+
f"[red]{path} is not a file, please specify a file when adding buildspec to cache"
189
+
)
190
+
continue
191
+
ifnotpath.endswith(".yml"):
192
+
console.print(
193
+
f"[red]{path} does not end in .yml extension, please specify a valid buildspec file"
194
+
)
195
+
continue
196
+
197
+
buildspecs.append(path)
198
+
199
+
# set self.buildspec_files to list of valid buildspec files which will be used to build cache
200
+
self.buildspec_files=buildspecs
172
201
173
202
# implements buildtest buildspec find --rebuild which removes cache file
174
203
# before finding all buildspecs. We only remove file if file exists
@@ -192,7 +221,7 @@ def build(self):
192
221
193
222
def_discover_buildspecs(self):
194
223
"""This method retrieves buildspecs based on ``self.paths`` which is a
195
-
list of directory paths to search. If ``--root`` is specified
224
+
list of directory paths to search. If ``--directory`` is specified
196
225
we process each argument and recursively find all .yml files
We can confirm the file is loaded into cache using the `-b` option which list all buildspecs in cache and pipe via `grep` to search for `vars.yml`. Note that
125
+
we specify ``--count=-1`` to show all buildspecs in cache.
0 commit comments