def __MakeCLI(self, top_element): """Generate a CLI object from the given data. Args: top_element: The top element of the command tree (that extends backend.CommandCommon). Returns: CLI, The generated CLI tool. """ # Don't bother setting up logging if we are just doing a completion. if '_ARGCOMPLETE' not in os.environ or '_ARGCOMPLETE_TRACE' in os.environ: log.AddFileLogging(self.__logs_dir) verbosity_string = os.environ.get('_ARGCOMPLETE_TRACE') if verbosity_string: verbosity = log.VALID_VERBOSITY_STRINGS.get(verbosity_string) log.SetVerbosity(verbosity) # Pre-load all commands if lazy loading is disabled. if properties.VALUES.core.disable_command_lazy_loading.GetBool(): top_element.LoadAllSubElements(recursive=True) cli = CLI(self.__name, top_element, self.__pre_run_hooks, self.__post_run_hooks, self.__known_error_handler) return cli
def testMultipleFiles(self): cli = self.GetCLI() logs_dir2 = self.CreateTempDir() log.AddFileLogging(logs_dir2) cli.Execute(['loggingcommand']) self._DoCommonLogCheck() self._DoCommonLogCheck(logs_dir2)
def InitLogging(self, logs_dir=None): """Initialize the logger for testing. Args: logs_dir: str, The root directory to write logs to. If None, use the standard one. """ log.Reset() log.AddFileLogging(logs_dir or self.logs_dir)
def __MakeCLI(self, entry_point, parser, top_element): """Generate a CLI object from the given data. Args: entry_point: The REPL entrypoint for this CLI. parser: The argparse parser for the top of this command tree. top_element: The top element of the command tree (that extends backend.CommandCommon). Returns: CLI, The generated CLI tool. """ if self.__version_func is not None: parser.add_argument('-v', '--version', action=actions.FunctionExitAction( self.__version_func), help='Print version information.') # pylint: disable=protected-access top_element._ai.add_argument( '--verbosity', choices=log.OrderedVerbosityNames(), default=None, help= 'Override the default verbosity for this command. This must be ' 'a standard logging verbosity level: [{values}] (Default: [{default}]).' .format(values=', '.join(log.OrderedVerbosityNames()), default=log.DEFAULT_VERBOSITY_STRING)) top_element._ai.add_argument( '--user-output-enabled', default=None, choices=('true', 'false'), help= 'Control whether user intended output is printed to the console. ' '(true/false)') if '_ARGCOMPLETE' not in os.environ: # Don't bother setting up logging if we are just doing a completion. log.AddFileLogging(self.__logs_dir) cli = CLI(entry_point, parser, self.__pre_run_hooks, self.__post_run_hooks) return cli
def __MakeCLI(self, top_element): """Generate a CLI object from the given data. Args: top_element: The top element of the command tree (that extends backend.CommandCommon). Returns: CLI, The generated CLI tool. """ if '_ARGCOMPLETE' not in os.environ: # Don't bother setting up logging if we are just doing a completion. log.AddFileLogging(self.__logs_dir) # Pre-load all commands if lazy loading is disabled. if properties.VALUES.core.disable_command_lazy_loading.GetBool(): top_element.LoadAllSubElements(recursive=True) cli = CLI(self.__name, top_element, self.__pre_run_hooks, self.__post_run_hooks) return cli
def testDirReregistration(self): cli = self.GetCLI() log.AddFileLogging(self.logs_dir) cli.Execute(['loggingcommand']) self._DoCommonLogCheck()
def SetUp(self): self.logs_dir = self.CreateTempDir() log.AddFileLogging(self.logs_dir)