1#
2# Copyright 2008 Google Inc. All Rights Reserved.
3
4"""
5If you need to change the default behavior of some atest commands, you
6can create a site_<topic>.py file to subclass some of the classes from
7<topic>.py.
8
9The following example would prevent the creation of platform labels.
10"""
11
12import inspect, new, sys
13
14from autotest_lib.cli import topic_common, label
15
16
17class site_label(label.label):
18    pass
19
20
21class site_label_create(label.label_create):
22    """Disable the platform option
23    atest label create <labels>|--blist <file>"""
24    def __init__(self):
25        super(site_label_create, self).__init__()
26        self.parser.remove_option("--platform")
27
28
29    def parse(self):
30        (options, leftover) = super(site_label_create, self).parse()
31        self.is_platform = False
32        return (options, leftover)
33
34
35# The following boiler plate code should be added at the end to create
36# all the other site_<topic>_<action> classes that do not modify their
37# <topic>_<action> super class.
38
39# Any classes we don't override in label should be copied automatically
40for cls in [getattr(label, n) for n in dir(label) if not n.startswith("_")]:
41    if not inspect.isclass(cls):
42        continue
43    cls_name = cls.__name__
44    site_cls_name = 'site_' + cls_name
45    if hasattr(sys.modules[__name__], site_cls_name):
46        continue
47    bases = (site_label, cls)
48    members = {'__doc__': cls.__doc__}
49    site_cls = new.classobj(site_cls_name, bases, members)
50    setattr(sys.modules[__name__], site_cls_name, site_cls)
51