def main(): """ The generic syntax is: atest <topic> <action> <options> atest-<topic> <action> <options> atest --help """ cli = os.path.basename(sys.argv[0]) syntax_obj = topic_common.atest() # Normalize the various --help, -h and help to -h sys.argv = [re.sub('--help|help', '-h', arg) for arg in sys.argv] match = re.search('^atest-(\w+)$', cli) if match: topic = match.group(1) else: if len(sys.argv) > 1: topic = sys.argv.pop(1) else: syntax_obj.invalid_syntax('No topic argument') if topic == '-h': sys.argv.insert(1, '-h') syntax_obj.parse() # The ignore flag should *only* be used by unittests. ignore_site = '--ignore_site_file' in sys.argv if ignore_site: sys.argv.remove('--ignore_site_file') # Import the topic specific file cli_dir = os.path.abspath(os.path.dirname(__file__)) if (not ignore_site and os.path.exists(os.path.join(cli_dir, 'site_%s.py' % topic))): topic = 'site_%s' % topic elif not os.path.exists(os.path.join(cli_dir, '%s.py' % topic)): syntax_obj.invalid_syntax('Invalid topic %s' % topic) topic_module = common.setup_modules.import_module(topic, 'autotest_lib.cli') # If we have a syntax error now, it should # refer to the topic class. topic_class = getattr(topic_module, topic) topic_obj = topic_class() if len(sys.argv) > 1: action = sys.argv.pop(1) if action == '-h': action = 'help' sys.argv.insert(1, '-h') else: topic_obj.invalid_syntax('No action argument') # Any backward compatibility changes? action = topic_obj.backward_compatibility(action, sys.argv) # Instantiate a topic object try: action_class = getattr(topic_module, topic + '_' + action) except AttributeError: topic_obj.invalid_syntax('Invalid action %s' % action) action_obj = action_class() action_obj.parse() try: try: results = action_obj.execute() except topic_common.CliError: pass except Exception, err: traceback.print_exc() action_obj.generic_error("Unexpected exception: %s" % err) else:
def setUp(self): super(atest_unittest, self).setUp() self.atest = topic_common.atest() self.atest.afe = rpc.afe_comm() if 'AUTOTEST_WEB' in os.environ: del os.environ['AUTOTEST_WEB']
def main(): """ The generic syntax is: atest <topic> <action> <options> atest-<topic> <action> <options> atest --help """ _disallow_root_user_on_moblab() cli = os.path.basename(sys.argv[0]) syntax_obj = topic_common.atest() # Normalize the various --help, -h and help to -h sys.argv = [re.sub('--help|help', '-h', arg) for arg in sys.argv] match = re.search('^atest-(\w+)$', cli) if match: topic = match.group(1) else: if len(sys.argv) > 1: topic = sys.argv.pop(1) else: syntax_obj.invalid_syntax('No topic argument') if topic == '-h': sys.argv.insert(1, '-h') syntax_obj.parse() # Import the topic specific file cli_dir = os.path.abspath(os.path.dirname(__file__)) if not os.path.exists(os.path.join(cli_dir, '%s.py' % topic)): syntax_obj.invalid_syntax('Invalid topic %s' % topic) topic_module = common.setup_modules.import_module(topic, 'autotest_lib.cli') # If we have a syntax error now, it should # refer to the topic class. topic_class = getattr(topic_module, topic) topic_obj = topic_class() if len(sys.argv) > 1: action = sys.argv.pop(1) if action == '-h': action = 'help' sys.argv.insert(1, '-h') else: topic_obj.invalid_syntax('No action argument') # Any backward compatibility changes? action = topic_obj.backward_compatibility(action, sys.argv) # Instantiate a topic object try: action_class = getattr(topic_module, topic + '_' + action) except AttributeError: topic_obj.invalid_syntax('Invalid action %s' % action) action_obj = action_class() action_obj.parse() try: try: results = action_obj.execute() except topic_common.CliError: pass except Exception, err: traceback.print_exc() action_obj.generic_error("Unexpected exception: %s" % err) else: