Beispiel #1
0
    def __str__(self):
        from conans.util.files import exception_message_safe
        msg = super(ConanException, self).__str__()
        if self.remote:
            return "{}.{}".format(exception_message_safe(msg), self.remote_message())

        return exception_message_safe(msg)
Beispiel #2
0
    def _download_file(self, url, auth, headers, file_path):
        t1 = time.time()

        try:
            response = self.requester.get(url,
                                          stream=True,
                                          verify=self.verify,
                                          auth=auth,
                                          headers=headers)
        except Exception as exc:
            raise ConanException("Error downloading file %s: '%s'" %
                                 (url, exception_message_safe(exc)))

        if not response.ok:
            if response.status_code == 404:
                raise NotFoundException("Not found: %s" % url)
            elif response.status_code == 401:
                raise AuthenticationException()
            raise ConanException("Error %d downloading file %s" %
                                 (response.status_code, url))

        try:
            data = self._download_data(response, file_path)
            duration = time.time() - t1
            log_download(url, duration)
            return data
        except Exception as e:
            logger.debug(e.__class__)
            logger.debug(traceback.format_exc())
            # If this part failed, it means problems with the connection to server
            raise ConanConnectionError(
                "Download failed, check server, possibly try again\n%s" %
                str(e))
Beispiel #3
0
    def _download_file(self, url, auth):
        try:
            response = self.requester.get(url, stream=True, verify=self.verify, auth=auth)
        except Exception as exc:
            raise ConanException("Error downloading file %s: '%s'" % (url, exception_message_safe(exc)))

        return response
Beispiel #4
0
    def _upload_file(self, url, data,  headers, auth):
        try:
            response = self.requester.put(url, data=data, verify=self.verify,
                                          headers=headers, auth=auth)
        except Exception as exc:
            raise ConanException(exception_message_safe(exc))

        return response
def call_with_retry(out, retry, retry_wait, method, *args, **kwargs):
    for counter in range(retry):
        try:
            return method(*args, **kwargs)
        except ConanException as exc:
            if counter == (retry - 1):
                raise
            else:
                msg = exception_message_safe(exc)
                out.error(msg)
                out.info("Waiting %d seconds to retry..." % retry_wait)
                time.sleep(retry_wait)
Beispiel #6
0
 def _call_remote(self, remote, method, *argc, **argv):
     self._auth_manager.remote = remote
     try:
         return getattr(self._auth_manager, method)(*argc, **argv)
     except ConnectionError as exc:
         raise ConanConnectionError("%s\n\nUnable to connect to %s=%s"
                                    % (str(exc), remote.name, remote.url))
     except ConanException as exc:
         raise exc.__class__("%s. [Remote: %s]" % (exception_message_safe(exc), remote.name))
     except Exception as exc:
         logger.error(traceback.format_exc())
         raise ConanException(exc)
Beispiel #7
0
 def _call_remote(self, remote, method, *argc, **argv):
     self._auth_manager.remote = remote
     try:
         return getattr(self._auth_manager, method)(*argc, **argv)
     except ConnectionError as exc:
         raise ConanConnectionError("%s\n\nUnable to connect to %s=%s"
                                    % (str(exc), remote.name, remote.url))
     except ConanException as exc:
         raise exc.__class__("%s. [Remote: %s]" % (exception_message_safe(exc), remote.name))
     except Exception as exc:
         logger.error(traceback.format_exc())
         raise ConanException(exc)
Beispiel #8
0
 def wrapper(*args, **kwargs):
     the_self = args[0]
     try:
         log_command(f.__name__, kwargs)
         with tools.environment_append(the_self._client_cache.conan_config.env_vars):
             # Patch the globals in tools
             return f(*args, **kwargs)
     except Exception as exc:
         msg = exception_message_safe(exc)
         try:
             log_exception(exc, msg)
         except:
             pass
         raise
Beispiel #9
0
 def wrapper(*args, **kwargs):
     the_self = args[0]
     try:
         log_command(f.__name__, kwargs)
         with tools.environment_append(the_self._client_cache.conan_config.env_vars):
             # Patch the globals in tools
             return f(*args, **kwargs)
     except Exception as exc:
         msg = exception_message_safe(exc)
         try:
             log_exception(exc, msg)
         except:
             pass
         raise
Beispiel #10
0
    def run(self, *args):
        """HIDDEN: entry point for executing commands, dispatcher to class
        methods
        """
        errors = False
        try:
            try:
                command = args[0][0]
                commands = self._commands()
                method = commands[command]
            except KeyError as exc:
                if command in ["-v", "--version"]:
                    self._user_io.out.success("Conan version %s" % CLIENT_VERSION)
                    return False
                self._show_help()
                if command in ["-h", "--help"]:
                    return False
                raise ConanException("Unknown command %s" % str(exc))
            except IndexError as exc:  # No parameters
                self._show_help()
                return False
            method(args[0][1:])
        except (KeyboardInterrupt, SystemExit) as exc:
            logger.error(exc)
            errors = True
        except ConanException as exc:
            errors = True
            msg = exception_message_safe(exc)
            self._user_io.out.error(msg)
        except Exception as exc:
            import traceback
            print(traceback.format_exc())
            msg = exception_message_safe(exc)
            self._user_io.out.error(msg)

        return errors
Beispiel #11
0
 def wrapper(api, *args, **kwargs):
     try:  # getcwd can fail if Conan runs on an unexisting folder
         old_curdir = os.getcwd()
     except EnvironmentError:
         old_curdir = None
     try:
         # TODO: Removing ConanApp creation, should we make it different for 2.0?
         # Also removing the logger call, maybe conan_command can handle it
         cache = ClientCache(api.cache_folder, api.out)
         with environment_append(cache.config.env_vars):
             return f(api, *args, **kwargs)
     except Exception as exc:
         msg = exception_message_safe(exc)
         try:
             api.out.error("{} ({})".format(str(exc.__class__.__name__), msg))
         except BaseException:
             pass
         raise
     finally:
         if old_curdir:
             os.chdir(old_curdir)
Beispiel #12
0
def main(args):
    """ main entry point of the conan application, using a Command to
    parse parameters

    Exit codes for conan command:

        0: Success (done)
        1: General ConanException error (done)
        2: Migration error
        3: Ctrl+C
        4: Ctrl+Break
        5: SIGTERM
        6: Invalid configuration (done)
    """
    try:
        conan_api, _, _ = Conan.factory()  # FIXME: Conan factory will be removed in Conan 2.0
    except ConanMigrationError:  # Error migrating
        sys.exit(ERROR_MIGRATION)
    except ConanException as e:
        sys.stderr.write("Error in Conan initialization: {}".format(e))
        sys.exit(ERROR_GENERAL)

    def ctrl_c_handler(_, __):
        print('You pressed Ctrl+C!')
        sys.exit(USER_CTRL_C)

    def sigterm_handler(_, __):
        print('Received SIGTERM!')
        sys.exit(ERROR_SIGTERM)

    def ctrl_break_handler(_, __):
        print('You pressed Ctrl+Break!')
        sys.exit(USER_CTRL_BREAK)

    signal.signal(signal.SIGINT, ctrl_c_handler)
    signal.signal(signal.SIGTERM, sigterm_handler)

    if sys.platform == 'win32':
        signal.signal(signal.SIGBREAK, ctrl_break_handler)

    try:
        cli = Cli(conan_api)
        exit_error = cli.run(args)
    except SystemExit as exc:
        if exc.code != 0:
            logger.error(exc)
            conan_api.out.error("Exiting with code: %d" % exc.code)
        exit_error = exc.code
    except ConanInvalidConfiguration as exc:
        exit_error = ERROR_INVALID_CONFIGURATION
        conan_api.out.error(exc)
    except ConanException as exc:
        exit_error = ERROR_GENERAL
        conan_api.out.error(exc)
    except Exception as exc:
        import traceback
        print(traceback.format_exc())
        exit_error = ERROR_GENERAL
        msg = exception_message_safe(exc)
        conan_api.out.error(msg)

    sys.exit(exit_error)