blob: d0df7132ea9248c1f8a079dd33ee12d459734ecd [file] [log] [blame]
mbligh7c8ea992009-06-22 19:03:08 +00001#!/usr/bin/python
showard909c7a62008-07-15 21:52:38 +00002#
3# Copyright 2008 Google Inc. All Rights Reserved.
4"""
5This utility allows for easy updating, removing and importing
showardeab66ce2009-12-23 00:03:56 +00006of tests into the autotest_web afe_autotests table.
showard909c7a62008-07-15 21:52:38 +00007
8Example of updating client side tests:
mbligh4b5c31e2009-07-11 00:55:34 +00009./test_importer.py -t /usr/local/autotest/client/tests
showard909c7a62008-07-15 21:52:38 +000010
mbligh4b5c31e2009-07-11 00:55:34 +000011If, for example, not all of your control files adhere to the standard outlined
12at http://autotest.kernel.org/wiki/ControlRequirements, you can force options:
showard909c7a62008-07-15 21:52:38 +000013
mbligh4b5c31e2009-07-11 00:55:34 +000014./test_importer.py --test-type server -t /usr/local/autotest/server/tests
showard909c7a62008-07-15 21:52:38 +000015
mbligh4b5c31e2009-07-11 00:55:34 +000016You would need to pass --add-noncompliant to include such control files,
17however. An easy way to check for compliance is to run in dry mode:
showard909c7a62008-07-15 21:52:38 +000018
mbligh4b5c31e2009-07-11 00:55:34 +000019./test_importer.py --dry-run -t /usr/local/autotest/server/tests/mytest
20
21Or to check a single control file, you can use check_control_file_vars.py.
22
23Running with no options is equivalent to --add-all --db-clear-tests.
24
25Most options should be fairly self explanatory, use --help to display them.
showard909c7a62008-07-15 21:52:38 +000026"""
27
28
showard909c7a62008-07-15 21:52:38 +000029import common
showardcd5131c2010-01-12 18:54:33 +000030import logging, re, os, sys, optparse, compiler
31from autotest_lib.frontend import setup_django_environment
32from autotest_lib.frontend.afe import models
mbligh61be4cd2010-03-30 02:02:40 +000033from autotest_lib.client.common_lib import control_data, utils
showard909c7a62008-07-15 21:52:38 +000034
showard909c7a62008-07-15 21:52:38 +000035
mbligh61be4cd2010-03-30 02:02:40 +000036logging.basicConfig(level=logging.ERROR)
showard909c7a62008-07-15 21:52:38 +000037# Global
38DRY_RUN = False
showard989f25d2008-10-01 11:38:11 +000039DEPENDENCIES_NOT_FOUND = set()
showard909c7a62008-07-15 21:52:38 +000040
showardcd5131c2010-01-12 18:54:33 +000041
mbligh61be4cd2010-03-30 02:02:40 +000042def update_all(autotest_dir, add_noncompliant, add_experimental):
43 """
44 Function to scan through all tests and add them to the database.
45
46 This function invoked when no parameters supplied to the command line.
47 It 'synchronizes' the test database with the current contents of the
48 client and server test directories. When test code is discovered
49 in the file system new tests may be added to the db. Likewise,
50 if test code is not found in the filesystem, tests may be removed
51 from the db. The base test directories are hard-coded to client/tests,
52 client/site_tests, server/tests and server/site_tests.
53
54 @param autotest_dir: prepended to path strings (/usr/local/autotest).
55 @param add_noncompliant: attempt adding test with invalid control files.
56 @param add_experimental: add tests with experimental attribute set.
57 """
showardcd5131c2010-01-12 18:54:33 +000058 for path in [ 'server/tests', 'server/site_tests', 'client/tests',
59 'client/site_tests']:
60 test_path = os.path.join(autotest_dir, path)
61 if not os.path.exists(test_path):
62 continue
mbligh61be4cd2010-03-30 02:02:40 +000063 logging.info("Scanning %s", test_path)
showardcd5131c2010-01-12 18:54:33 +000064 tests = []
65 tests = get_tests_from_fs(test_path, "^control.*",
66 add_noncompliant=add_noncompliant)
67 update_tests_in_db(tests, add_experimental=add_experimental,
68 add_noncompliant=add_noncompliant,
mbligh61be4cd2010-03-30 02:02:40 +000069 autotest_dir=autotest_dir)
showardcd5131c2010-01-12 18:54:33 +000070 test_suite_path = os.path.join(autotest_dir, 'test_suites')
71 if os.path.exists(test_suite_path):
mbligh61be4cd2010-03-30 02:02:40 +000072 logging.info("Scanning %s", test_suite_path)
showardcd5131c2010-01-12 18:54:33 +000073 tests = get_tests_from_fs(test_suite_path, '.*',
74 add_noncompliant=add_noncompliant)
75 update_tests_in_db(tests, add_experimental=add_experimental,
76 add_noncompliant=add_noncompliant,
mbligh61be4cd2010-03-30 02:02:40 +000077 autotest_dir=autotest_dir)
showardcd5131c2010-01-12 18:54:33 +000078
79 profilers_path = os.path.join(autotest_dir, "client/profilers")
80 if os.path.exists(profilers_path):
mbligh61be4cd2010-03-30 02:02:40 +000081 logging.info("Scanning %s", profilers_path)
showardcd5131c2010-01-12 18:54:33 +000082 profilers = get_tests_from_fs(profilers_path, '.*py$')
mbligh61be4cd2010-03-30 02:02:40 +000083 update_profilers_in_db(profilers, add_noncompliant=add_noncompliant,
showardcd5131c2010-01-12 18:54:33 +000084 description='NA')
85 # Clean bad db entries
mbligh61be4cd2010-03-30 02:02:40 +000086 db_clean_broken(autotest_dir)
showardcd5131c2010-01-12 18:54:33 +000087
88
mbligh61be4cd2010-03-30 02:02:40 +000089def update_samples(autotest_dir, add_noncompliant, add_experimental):
90 """
91 Add only sample tests to the database from the filesystem.
92
93 This function invoked when -S supplied on command line.
94 Only adds tests to the database - does not delete any.
95 Samples tests are formatted slightly differently than other tests.
96
97 @param autotest_dir: prepended to path strings (/usr/local/autotest).
98 @param add_noncompliant: attempt adding test with invalid control files.
99 @param add_experimental: add tests with experimental attribute set.
100 """
showardcd5131c2010-01-12 18:54:33 +0000101 sample_path = os.path.join(autotest_dir, 'server/samples')
102 if os.path.exists(sample_path):
mbligh61be4cd2010-03-30 02:02:40 +0000103 logging.info("Scanning %s", sample_path)
showardcd5131c2010-01-12 18:54:33 +0000104 tests = get_tests_from_fs(sample_path, '.*srv$',
105 add_noncompliant=add_noncompliant)
106 update_tests_in_db(tests, add_experimental=add_experimental,
107 add_noncompliant=add_noncompliant,
mbligh61be4cd2010-03-30 02:02:40 +0000108 autotest_dir=autotest_dir)
showardcd5131c2010-01-12 18:54:33 +0000109
110
mbligh61be4cd2010-03-30 02:02:40 +0000111def db_clean_broken(autotest_dir):
112 """
113 Remove tests from autotest_web that do not have valid control files
showardcd5131c2010-01-12 18:54:33 +0000114
mbligh61be4cd2010-03-30 02:02:40 +0000115 This function invoked when -c supplied on the command line and when
116 running update_all(). Removes tests from database which are not
117 found in the filesystem. Also removes profilers which are just
118 a special case of tests.
119
120 @param autotest_dir: prepended to path strings (/usr/local/autotest).
showardcd5131c2010-01-12 18:54:33 +0000121 """
122 for test in models.Test.objects.all():
123 full_path = os.path.join(autotest_dir, test.path)
124 if not os.path.isfile(full_path):
mbligh61be4cd2010-03-30 02:02:40 +0000125 logging.info("Removing %s", test.path)
showardcd5131c2010-01-12 18:54:33 +0000126 _log_or_execute(repr(test), test.delete)
127
128 # Find profilers that are no longer present
129 for profiler in models.Profiler.objects.all():
130 full_path = os.path.join(autotest_dir, "client", "profilers",
131 profiler.name)
132 if not os.path.exists(full_path):
mbligh61be4cd2010-03-30 02:02:40 +0000133 logging.info("Removing %s", profiler.name)
showardcd5131c2010-01-12 18:54:33 +0000134 _log_or_execute(repr(profiler), profiler.delete)
135
136
mbligh61be4cd2010-03-30 02:02:40 +0000137def db_clean_all(autotest_dir):
138 """
139 Remove all tests from autotest_web - very destructive
140
141 This function invoked when -C supplied on the command line.
142 Removes ALL tests from the database.
143
144 @param autotest_dir: prepended to path strings (/usr/local/autotest).
145 """
146 for test in models.Test.objects.all():
147 full_path = os.path.join(autotest_dir, test.path)
148 logging.info("Removing %s", test.path)
149 _log_or_execute(repr(test), test.delete)
150
151 # Find profilers that are no longer present
152 for profiler in models.Profiler.objects.all():
153 full_path = os.path.join(autotest_dir, "client", "profilers",
154 profiler.name)
155 logging.info("Removing %s", profiler.name)
156 _log_or_execute(repr(profiler), profiler.delete)
157
158
159def update_profilers_in_db(profilers, description='NA',
showardcd5131c2010-01-12 18:54:33 +0000160 add_noncompliant=False):
mbligh61be4cd2010-03-30 02:02:40 +0000161 """
162 Add only profilers to the database from the filesystem.
163
164 This function invoked when -p supplied on command line.
165 Only adds profilers to the database - does not delete any.
166 Profilers are formatted slightly differently than tests.
167
168 @param profilers: list of profilers found in the file system.
169 @param description: simple text to satisfy docstring.
170 @param add_noncompliant: attempt adding test with invalid control files.
171 """
showardcd5131c2010-01-12 18:54:33 +0000172 for profiler in profilers:
173 name = os.path.basename(profiler).rstrip(".py")
174 if not profilers[profiler]:
175 if add_noncompliant:
176 doc = description
177 else:
mbligh61be4cd2010-03-30 02:02:40 +0000178 logging.info("Skipping %s, missing docstring", profiler)
showardcd5131c2010-01-12 18:54:33 +0000179 else:
180 doc = profilers[profiler]
181
182 model = models.Profiler.objects.get_or_create(name=name)[0]
183 model.description = doc
184 _log_or_execute(repr(model), model.save)
185
186
187def update_tests_in_db(tests, dry_run=False, add_experimental=False,
mbligh61be4cd2010-03-30 02:02:40 +0000188 add_noncompliant=False, autotest_dir=None):
189 """
190 Scans through all tests and add them to the database.
191
192 This function invoked when -t supplied and for update_all.
193 When test code is discovered in the file system new tests may be added
194
195 @param tests: list of tests found in the filesystem.
196 @param dry_run: not used at this time.
197 @param add_experimental: add tests with experimental attribute set.
198 @param add_noncompliant: attempt adding test with invalid control files.
199 @param autotest_dir: prepended to path strings (/usr/local/autotest).
200 """
201 site_set_attributes_module = utils.import_site_module(
202 __file__, 'autotest_lib.utils.site_test_importer_attributes')
203
showardcd5131c2010-01-12 18:54:33 +0000204 for test in tests:
205 new_test = models.Test.objects.get_or_create(
206 path=test.replace(autotest_dir, '').lstrip('/'))[0]
mbligh61be4cd2010-03-30 02:02:40 +0000207 logging.info("Processing %s", new_test.path)
showardcd5131c2010-01-12 18:54:33 +0000208
209 # Set the test's attributes
210 data = tests[test]
211 _set_attributes_clean(new_test, data)
212
mbligh61be4cd2010-03-30 02:02:40 +0000213 # Custom Attribute Update
214 if site_set_attributes_module:
215 site_set_attributes_module._set_attributes_custom(new_test, data)
216
showardcd5131c2010-01-12 18:54:33 +0000217 # This only takes place if --add-noncompliant is provided on the CLI
218 if not new_test.name:
219 test_new_test = test.split('/')
220 if test_new_test[-1] == 'control':
221 new_test.name = test_new_test[-2]
222 else:
223 control_name = "%s:%s"
224 control_name %= (test_new_test[-2],
225 test_new_test[-1])
226 new_test.name = control_name.replace('control.', '')
227
228 # Experimental Check
229 if not add_experimental and new_test.experimental:
230 continue
231
232 _log_or_execute(repr(new_test), new_test.save)
233 add_label_dependencies(new_test)
234
235
236def _set_attributes_clean(test, data):
mbligh61be4cd2010-03-30 02:02:40 +0000237 """
238 First pass sets the attributes of the Test object from file system.
showardcd5131c2010-01-12 18:54:33 +0000239
mbligh61be4cd2010-03-30 02:02:40 +0000240 @param test: a test object to be populated for the database.
241 @param data: object with test data from the file system.
242 """
showardcd5131c2010-01-12 18:54:33 +0000243 test_type = { 'client' : 1,
244 'server' : 2, }
245 test_time = { 'short' : 1,
246 'medium' : 2,
247 'long' : 3, }
248
249
250 string_attributes = ('name', 'author', 'test_class', 'test_category',
251 'test_category', 'sync_count')
252 for attribute in string_attributes:
253 setattr(test, attribute, getattr(data, attribute))
254
255 test.description = data.doc
256 test.dependencies = ", ".join(data.dependencies)
257
258 int_attributes = ('experimental', 'run_verify')
259 for attribute in int_attributes:
260 setattr(test, attribute, int(getattr(data, attribute)))
261
262 try:
263 test.test_type = int(data.test_type)
264 if test.test_type != 1 and test.test_type != 2:
265 raise Exception('Incorrect number %d for test_type' %
266 test.test_type)
267 except ValueError:
268 pass
269 try:
270 test.test_time = int(data.time)
271 if test.test_time < 1 or test.time > 3:
272 raise Exception('Incorrect number %d for time' % test.time)
273 except ValueError:
274 pass
275
276 if not test.test_time and str == type(data.time):
277 test.test_time = test_time[data.time.lower()]
278 if not test.test_type and str == type(data.test_type):
279 test.test_type = test_type[data.test_type.lower()]
280
281
282def add_label_dependencies(test):
283 """
mbligh61be4cd2010-03-30 02:02:40 +0000284 Add proper many-to-many relationships from DEPENDENCIES field.
285
286 @param test: test object for the database.
showardcd5131c2010-01-12 18:54:33 +0000287 """
mbligh61be4cd2010-03-30 02:02:40 +0000288
showardcd5131c2010-01-12 18:54:33 +0000289 # clear out old relationships
290 _log_or_execute(repr(test), test.dependency_labels.clear,
291 subject='clear dependencies from')
292
293 for label_name in test.dependencies.split(','):
294 label_name = label_name.strip().lower()
295 if not label_name:
296 continue
297
298 try:
299 label = models.Label.objects.get(name=label_name)
300 except models.Label.DoesNotExist:
301 log_dependency_not_found(label_name)
302 continue
303
304 _log_or_execute(repr(label), test.dependency_labels.add, label,
305 subject='add dependency to %s' % test.name)
306
307
308def log_dependency_not_found(label_name):
mbligh61be4cd2010-03-30 02:02:40 +0000309 """
310 Exception processing when label not found in database.
311
312 @param label_name: from test dependencies.
313 """
showardcd5131c2010-01-12 18:54:33 +0000314 if label_name in DEPENDENCIES_NOT_FOUND:
315 return
mbligh61be4cd2010-03-30 02:02:40 +0000316 logging.info("Dependency %s not found", label_name)
showardcd5131c2010-01-12 18:54:33 +0000317 DEPENDENCIES_NOT_FOUND.add(label_name)
318
319
320def get_tests_from_fs(parent_dir, control_pattern, add_noncompliant=False):
mbligh61be4cd2010-03-30 02:02:40 +0000321 """
322 Find control files in file system and load a list with their info.
showardcd5131c2010-01-12 18:54:33 +0000323
mbligh61be4cd2010-03-30 02:02:40 +0000324 @param parent_dir: directory to search recursively.
325 @param control_pattern: name format of control file.
326 @param add_noncompliant: ignore control file parse errors.
327
328 @return: dictionary of the form: tests[file_path] = parsed_object
showardcd5131c2010-01-12 18:54:33 +0000329 """
330 tests = {}
331 profilers = False
332 if 'client/profilers' in parent_dir:
333 profilers = True
334 for dir in [ parent_dir ]:
335 files = recursive_walk(dir, control_pattern)
336 for file in files:
337 if '__init__.py' in file or '.svn' in file:
338 continue
339 if not profilers:
340 if not add_noncompliant:
341 try:
342 found_test = control_data.parse_control(file,
343 raise_warnings=True)
344 tests[file] = found_test
345 except control_data.ControlVariableException, e:
mbligh61be4cd2010-03-30 02:02:40 +0000346 logging.info("Skipping %s\n%s", file, e)
showardcd5131c2010-01-12 18:54:33 +0000347 pass
348 else:
349 found_test = control_data.parse_control(file)
350 tests[file] = found_test
351 else:
352 script = file.rstrip(".py")
353 tests[file] = compiler.parseFile(file).doc
354 return tests
355
356
357def recursive_walk(path, wildcard):
mbligh61be4cd2010-03-30 02:02:40 +0000358 """
359 Recursively go through a directory.
360
361 This function invoked by get_tests_from_fs().
362
363 @param path: base directory to start search.
364 @param wildcard: name format to match.
365
366 @return: A list of files that match wildcard
showardcd5131c2010-01-12 18:54:33 +0000367 """
368 files = []
369 directories = [ path ]
370 while len(directories)>0:
371 directory = directories.pop()
372 for name in os.listdir(directory):
373 fullpath = os.path.join(directory, name)
374 if os.path.isfile(fullpath):
375 # if we are a control file
376 if re.search(wildcard, name):
377 files.append(fullpath)
378 elif os.path.isdir(fullpath):
379 directories.append(fullpath)
380 return files
381
382
383def _log_or_execute(content, func, *args, **kwargs):
mbligh61be4cd2010-03-30 02:02:40 +0000384 """
385 Log a message if dry_run is enabled, or execute the given function.
showardcd5131c2010-01-12 18:54:33 +0000386
mbligh61be4cd2010-03-30 02:02:40 +0000387 Relies on the DRY_RUN global variable.
388
389 @param content: the actual log message.
390 @param func: function to execute if dry_run is not enabled.
391 @param subject: (Optional) The type of log being written. Defaults to
392 the name of the provided function.
showardcd5131c2010-01-12 18:54:33 +0000393 """
394 subject = kwargs.get('subject', func.__name__)
395
396 if DRY_RUN:
mbligh61be4cd2010-03-30 02:02:40 +0000397 logging.info("Would %s: %s", subject, content)
showardcd5131c2010-01-12 18:54:33 +0000398 else:
399 func(*args)
400
401
mbligh61be4cd2010-03-30 02:02:40 +0000402def _create_whitelist_set(whitelist_path):
403 """
404 Create a set with contents from a whitelist file for membership testing.
405
406 @param whitelist_path: full path to the whitelist file.
407
408 @return: set with files listed one/line - newlines included.
409 """
410 f = open(whitelist_path, 'r')
411 whitelist_set = set([line.strip() for line in f])
412 f.close()
413 return whitelist_set
414
415
416def update_from_whitelist(whitelist_set, add_experimental, add_noncompliant,
417 autotest_dir):
418 """
419 Scans through all tests in the whitelist and add them to the database.
420
421 This function invoked when -w supplied.
422
423 @param whitelist_set: set of tests in full-path form from a whitelist.
424 @param add_experimental: add tests with experimental attribute set.
425 @param add_noncompliant: attempt adding test with invalid control files.
426 @param autotest_dir: prepended to path strings (/usr/local/autotest).
427 """
428 tests = {}
429 profilers = {}
430 for file_path in whitelist_set:
431 if file_path.find('client/profilers') == -1:
432 try:
433 found_test = control_data.parse_control(file_path,
434 raise_warnings=True)
435 tests[file_path] = found_test
436 except control_data.ControlVariableException, e:
437 logging.info("Skipping %s\n%s", file, e)
438 pass
439 else:
440 profilers[file_path] = compiler.parseFile(file_path).doc
441
442 if len(tests) > 0:
443 update_tests_in_db(tests, add_experimental=add_experimental,
444 add_noncompliant=add_noncompliant,
445 autotest_dir=autotest_dir)
446 if len(profilers) > 0:
447 update_profilers_in_db(profilers, add_noncompliant=add_noncompliant,
448 description='NA')
449
450
showard909c7a62008-07-15 21:52:38 +0000451def main(argv):
452 """Main function"""
mbligh61be4cd2010-03-30 02:02:40 +0000453
showard909c7a62008-07-15 21:52:38 +0000454 global DRY_RUN
455 parser = optparse.OptionParser()
mbligh61be4cd2010-03-30 02:02:40 +0000456 parser.add_option('-c', '--db-clean-tests',
457 dest='clean_tests', action='store_true',
showard909c7a62008-07-15 21:52:38 +0000458 default=False,
mbligh61be4cd2010-03-30 02:02:40 +0000459 help='Clean client and server tests with invalid control files')
460 parser.add_option('-C', '--db-clear-all-tests',
461 dest='clear_all_tests', action='store_true',
462 default=False,
463 help='Clear ALL client and server tests')
showard909c7a62008-07-15 21:52:38 +0000464 parser.add_option('-d', '--dry-run',
465 dest='dry_run', action='store_true', default=False,
466 help='Dry run for operation')
mbligh322ec1a2008-09-26 16:48:10 +0000467 parser.add_option('-A', '--add-all',
468 dest='add_all', action='store_true',
469 default=False,
mbligh25d656c2009-08-24 22:04:02 +0000470 help='Add site_tests, tests, and test_suites')
471 parser.add_option('-S', '--add-samples',
472 dest='add_samples', action='store_true',
473 default=False,
474 help='Add samples.')
mbligh322ec1a2008-09-26 16:48:10 +0000475 parser.add_option('-E', '--add-experimental',
showard909c7a62008-07-15 21:52:38 +0000476 dest='add_experimental', action='store_true',
mbligh79410e12008-11-20 17:59:15 +0000477 default=True,
showard909c7a62008-07-15 21:52:38 +0000478 help='Add experimental tests to frontend')
479 parser.add_option('-N', '--add-noncompliant',
480 dest='add_noncompliant', action='store_true',
481 default=False,
mbligh4b5c31e2009-07-11 00:55:34 +0000482 help='Add non-compliant tests (i.e. tests that do not '
483 'define all required control variables)')
mbligh322ec1a2008-09-26 16:48:10 +0000484 parser.add_option('-p', '--profile-dir', dest='profile_dir',
485 help='Directory to recursively check for profiles')
showard909c7a62008-07-15 21:52:38 +0000486 parser.add_option('-t', '--tests-dir', dest='tests_dir',
487 help='Directory to recursively check for control.*')
showard909c7a62008-07-15 21:52:38 +0000488 parser.add_option('-r', '--control-pattern', dest='control_pattern',
489 default='^control.*',
490 help='The pattern to look for in directories for control files')
mbligh322ec1a2008-09-26 16:48:10 +0000491 parser.add_option('-v', '--verbose',
492 dest='verbose', action='store_true', default=False,
493 help='Run in verbose mode')
mbligh61be4cd2010-03-30 02:02:40 +0000494 parser.add_option('-w', '--whitelist-file', dest='whitelist_file',
495 help='Filename for list of test names that must match')
496 parser.add_option('-z', '--autotest-dir', dest='autotest_dir',
mbligh322ec1a2008-09-26 16:48:10 +0000497 default=os.path.join(os.path.dirname(__file__), '..'),
showard909c7a62008-07-15 21:52:38 +0000498 help='Autotest directory root')
499 options, args = parser.parse_args()
500 DRY_RUN = options.dry_run
mbligh322ec1a2008-09-26 16:48:10 +0000501 # Make sure autotest_dir is the absolute path
502 options.autotest_dir = os.path.abspath(options.autotest_dir)
503
504 if len(args) > 0:
mbligh61be4cd2010-03-30 02:02:40 +0000505 logging.error("Invalid option(s) provided: %s", args)
showard909c7a62008-07-15 21:52:38 +0000506 parser.print_help()
507 return 1
508
mbligh61be4cd2010-03-30 02:02:40 +0000509 if options.verbose:
510 logging.getLogger().setLevel(logging.DEBUG)
511
512 if len(argv) == 1 or (len(argv) == 2 and options.verbose):
mbligh322ec1a2008-09-26 16:48:10 +0000513 update_all(options.autotest_dir, options.add_noncompliant,
mbligh61be4cd2010-03-30 02:02:40 +0000514 options.add_experimental)
515 db_clean_broken(options.autotest_dir)
mbligh322ec1a2008-09-26 16:48:10 +0000516 return 0
517
mbligh61be4cd2010-03-30 02:02:40 +0000518 if options.clear_all_tests:
519 if (options.clean_tests or options.add_all or options.add_samples or
520 options.add_noncompliant):
521 logging.error(
522 "Can only pass --autotest-dir, --dry-run and --verbose with "
523 "--db-clear-all-tests")
524 return 1
525 db_clean_all(options.autotest_dir)
526
527 whitelist_set = None
528 if options.whitelist_file:
529 if options.add_all:
530 logging.error("Cannot pass both --add-all and --whitelist-file")
531 return 1
532 whitelist_path = os.path.abspath(options.whitelist_file)
533 if not os.path.isfile(whitelist_path):
534 logging.error("--whitelist-file (%s) not found", whitelist_path)
535 return 1
536 logging.info("Using whitelist file %s", whitelist_path)
537 whitelist_set = _create_whitelist_set(whitelist_path)
538 update_from_whitelist(whitelist_set,
539 add_experimental=options.add_experimental,
540 add_noncompliant=options.add_noncompliant,
541 autotest_dir=options.autotest_dir)
mbligh322ec1a2008-09-26 16:48:10 +0000542 if options.add_all:
543 update_all(options.autotest_dir, options.add_noncompliant,
mbligh61be4cd2010-03-30 02:02:40 +0000544 options.add_experimental)
mbligh25d656c2009-08-24 22:04:02 +0000545 if options.add_samples:
546 update_samples(options.autotest_dir, options.add_noncompliant,
mbligh61be4cd2010-03-30 02:02:40 +0000547 options.add_experimental)
showard909c7a62008-07-15 21:52:38 +0000548 if options.tests_dir:
mbligh4b5c31e2009-07-11 00:55:34 +0000549 options.tests_dir = os.path.abspath(options.tests_dir)
showard909c7a62008-07-15 21:52:38 +0000550 tests = get_tests_from_fs(options.tests_dir, options.control_pattern,
551 add_noncompliant=options.add_noncompliant)
mbligh322ec1a2008-09-26 16:48:10 +0000552 update_tests_in_db(tests, add_experimental=options.add_experimental,
showard909c7a62008-07-15 21:52:38 +0000553 add_noncompliant=options.add_noncompliant,
mbligh61be4cd2010-03-30 02:02:40 +0000554 autotest_dir=options.autotest_dir)
mbligh322ec1a2008-09-26 16:48:10 +0000555 if options.profile_dir:
556 profilers = get_tests_from_fs(options.profile_dir, '.*py$')
mbligh61be4cd2010-03-30 02:02:40 +0000557 update_profilers_in_db(profilers,
mbligh322ec1a2008-09-26 16:48:10 +0000558 add_noncompliant=options.add_noncompliant,
559 description='NA')
mbligh61be4cd2010-03-30 02:02:40 +0000560 if options.clean_tests:
561 db_clean_broken(options.autotest_dir)
showard909c7a62008-07-15 21:52:38 +0000562
563
showard909c7a62008-07-15 21:52:38 +0000564if __name__ == "__main__":
565 main(sys.argv)