Skip to content

Commit a606e38

Browse files
committed
Start to generalize trivial-validate.py input
Previously. trivial-validate.py took either a single specified file or all the files in a specified directory. Seth pointed out that we can generalize it to take a list of files / directories.
1 parent 83c0d88 commit a606e38

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

utils/trivial-validate.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ def get_all_names_and_targets(d):
179179
targets.add(target)
180180
return names, targets
181181

182+
def nomes(where=sys.argv[1:]):
183+
"""Returns generator to extract files from a list of files / directories"""
184+
# TODO: extract files recursively to a certain depth?
185+
orig = os.getcwd()
186+
if not where: where=["."]
187+
for i in where:
188+
if os.path.isdir(i):
189+
os.chdir(i)
190+
for f in os.listdir("."):
191+
if os.path.isfile(f): yield open(f)
192+
os.chdir(orig)
193+
elif os.path.isfile(i):
194+
yield open(i)
195+
182196
tests = [test_not_anchored, test_bad_regexp, test_unescaped_dots, test_missing_to,
183197
test_space_in_to, test_unencrypted_to, test_backslash_in_to,
184198
test_no_trailing_slash, test_lacks_target_host, test_bad_target_host,
@@ -190,7 +204,7 @@ def get_all_names_and_targets(d):
190204
all_names = set()
191205

192206
if multi_file_validate:
193-
for fi in os.listdir("."):
207+
for fi in nomes():
194208
try:
195209
tree = etree.parse(fi)
196210
if fi[-4:] != ".xml":
@@ -219,6 +233,7 @@ def get_all_names_and_targets(d):
219233
# pattern matches target
220234
sys.stdout.write("warning: duplicate target: %s\n" % target)
221235
all_targets.add(target)
236+
fi.close()
222237
else:
223238
fi = os.path.basename(args[0])
224239
if len(args) > 1:

0 commit comments

Comments
 (0)