Exemplo n.º 1
0
    def _main_raises(self, toolbelt_root):
        tb_config = self.config_reader.get_tb_config(toolbelt_root,
                                                     self.extensions)

        if not tb_config['config_ok']:
            print("\033[91mWarning: It seems as your alias is not "
                  "set up correctly. Try to run with help\033[0m")

        verbose = False
        command = 'help'
        pos = 1

        if len(sys.argv) > pos:
            arg = sys.argv[pos]
            if arg == '-d':
                verbose = True
                pos += 1

        if len(sys.argv) > pos:
            command = sys.argv[pos]
            pos += 1

        arguments = sys.argv[pos:]

        self.docker.verbose = verbose
        self.extensions.pre_tool_execution(tb_config, command, arguments)

        tool = self._find_tool(tb_config['tools'], command)
        if tool is not None:
            tool.command(tb_config, arguments)
        elif command in tb_config['module_tools']:
            self.bc_module.execute_tool(tb_config, command, arguments)
        else:
            raise exception.ToolbeltException("Don't know how to execute " +
                                              command)
Exemplo n.º 2
0
 def check_call(self, *popenargs, **kwargs):
     try:
         return subprocess.check_call(*popenargs, **kwargs)
     except subprocess.CalledProcessError as e:
         message = "The call '" + " ".join(e.cmd) + \
                   "' failed with error code " + str(e.returncode)
         if e.output:
             message += ", and output '" + e.output.decode('cp437') + "'"
         raise exception.ToolbeltException(message)
Exemplo n.º 3
0
 def image_exists(self, image_name):
     try:
         self._sub_proc.check_output(["docker", "pull", image_name],
                                     stderr=subprocess.STDOUT)
         return True
     except exception.ToolbeltException as e:
         if re.search('Error: .* not found', e.value):
             return False
         raise exception.ToolbeltException("Can not contact registry. " +
                                           e.value)
Exemplo n.º 4
0
 def image_exists(self, image_name):
     try:
         self._sub_proc.check_output(["docker", "pull", image_name],
                                     stderr=subprocess.STDOUT)
         return True
     except exception.ToolbeltException as e:
         # TODO This is pretty brittle, improve! We parse the error text
         #  to determine if the image was not found or if the registry could
         #  not be contacted. Possible solution would be to use the API
         #  instead.
         if re.search(' not found', e.value):
             return False
         raise exception.ToolbeltException("Can not contact registry. " +
                                           e.value)
Exemplo n.º 5
0
    def _main_raises(self, toolbelt_root):
        tb_config = self.config_reader.get_tb_config(toolbelt_root,
                                                     self.extensions)

        if tb_config['host'] == 'native':
            print("Did not detect docker host, the tool belt is running in a "
                  "native environment")

        command = 'help'
        if len(sys.argv) > 1:
            command = sys.argv[1]
        arguments = sys.argv[2:]

        self.extensions.pre_tool_execution(tb_config, command, arguments)

        tool = self._find_tool(tb_config['tools'], command)
        if tool is not None:
            tool.command(tb_config, arguments)
        elif command in tb_config['module_tools']:
            self.bc_module.execute_tool(tb_config, command, arguments)
        else:
            raise exception.ToolbeltException("Don't know how to execute " +
                                              command)