Esempio n. 1
0
            # get a 0 for errcode and will raise a CommunicationError
            if abs(errCode) == 17:
                #in this case, the args are the package string, so lets try to
                # build a useful error message
                if type(args[0]) == type([]):
                    pkg = args[0]
                else:
                    pkg = args[1]

                if type(pkg) == type([]):
                    pkgName = "%s-%s-%s.%s" % (pkg[0], pkg[1], pkg[2], pkg[4])
                else:
                    pkgName = pkg
                msg = "File Not Found: %s\n%s" % (pkgName, errMsg)
                log.log_me(msg)
                raise up2dateErrors.FileNotFoundError(
                    msg), None, sys.exc_info()[2]

            if not reset:
                if attempt_count >= attempts:
                    raise up2dateErrors.CommunicationError(
                        e.errmsg), None, sys.exc_info()[2]
                else:
                    failure = 1

        except xmlrpclib.ResponseError:
            raise up2dateErrors.CommunicationError(
                "Broken response from the server."), None, sys.exc_info()[2]

        if ret != None:
            break
        else:
Esempio n. 2
0
def doCall(method, *args, **kwargs):
    log = up2dateLog.initLog()
    log.log_debug("rpcServer: Calling XMLRPC %s" %
                  method.__dict__['_Method__name'])
    cfg = config.initUp2dateConfig()
    ret = None

    attempt_count = 1
    try:
        attempts = int(cfg["networkRetries"])
    except ValueError:
        attempts = 1
    if attempts <= 0:
        attempts = 1

    while 1:
        failure = 0
        ret = None
        try:
            ret = method(*args, **kwargs)
        except KeyboardInterrupt:
            raise (up2dateErrors.CommunicationError(
                _("Connection aborted by the user")), None, sys.exc_info()[2])
        # if we get a socket error, keep tryingx2
        except (socket.error, socket.sslerror):
            log.log_me("A socket error occurred: %s, attempt #%s" %
                       (sys.exc_info()[1], attempt_count))
            if attempt_count >= attempts:
                if len(e.args) > 1:
                    raise (up2dateErrors.CommunicationError(e.args[1]), None,
                           sys.exc_info()[2])
                else:
                    raise (up2dateErrors.CommunicationError(e.args[0]), None,
                           sys.exc_info()[2])
            else:
                failure = 1
        except httplib.IncompleteRead:
            print "httplib.IncompleteRead"
            raise (up2dateErrors.CommunicationError("httplib.IncompleteRead"),
                   None, sys.exc_info()[2])

        except urllib2.HTTPError:
            e = sys.exc_info()[1]
            msg = "\nAn HTTP error occurred:\n"
            msg = msg + "URL: %s\n" % e.filename
            msg = msg + "Status Code: %s\n" % e.code
            msg = msg + "Error Message: %s\n" % e.msg
            log.log_me(msg)
            raise (up2dateErrors.CommunicationError(msg), None,
                   sys.exc_info()[2])

        except xmlrpclib.ProtocolError:
            e = sys.exc_info()[1]
            log.log_me("A protocol error occurred: %s , attempt #%s," %
                       (e.errmsg, attempt_count))
            if e.errcode == 404:
                log.log_me("Could not find URL, %s" % (e.url))
                log.log_me("Check server name and/or URL, then retry\n")

            (errCode, errMsg) = rpclib.reportError(e.headers)
            reset = 0
            if abs(errCode) == 34:
                log.log_me("Auth token timeout occurred\n errmsg: %s" % errMsg)
                # this calls login, which in tern calls doCall (ie,
                # this function) but login should never get a 34, so
                # should be safe from recursion

                up2dateAuth.updateLoginInfo()

            # the servers are being throttle to pay users only, catch the
            # exceptions and display a nice error message
            if abs(errCode) == 51:
                log.log_me(_("Server has refused connection due to high load"))
                raise (up2dateErrors.CommunicationError(e.errmsg), None,
                       sys.exc_info()[2])
            # if we get a 404 from our server, thats pretty
            # fatal... no point in retrying over and over. Note that
            # errCode == 17 is specific to our servers, if the
            # serverURL is just pointing somewhere random they will
            # get a 0 for errcode and will raise a CommunicationError
            if abs(errCode) == 17:
                #in this case, the args are the package string, so lets try to
                # build a useful error message
                if type(args[0]) == type([]):
                    pkg = args[0]
                else:
                    pkg = args[1]

                if type(pkg) == type([]):
                    pkgName = "%s-%s-%s.%s" % (pkg[0], pkg[1], pkg[2], pkg[4])
                else:
                    pkgName = pkg
                msg = "File Not Found: %s\n%s" % (pkgName, errMsg)
                log.log_me(msg)
                raise (up2dateErrors.FileNotFoundError(msg), None,
                       sys.exc_info()[2])

            if not reset:
                if attempt_count >= attempts:
                    raise (up2dateErrors.CommunicationError(e.errmsg), None,
                           sys.exc_info()[2])
                else:
                    failure = 1

        except xmlrpclib.ResponseError:
            raise (up2dateErrors.CommunicationError(
                "Broken response from the server."), None, sys.exc_info()[2])

        if ret != None:
            break
        else:
            failure = 1

        if failure:
            # rest for five seconds before trying again
            time.sleep(5)
            attempt_count = attempt_count + 1

        if attempt_count > attempts:
            raise up2dateErrors.CommunicationError(
                "The data returned from the server was incomplete")

    return ret
Esempio n. 3
0
            # get a 0 for errcode and will raise a CommunicationError
            if abs(errCode) == 17:
                #in this case, the args are the package string, so lets try to
                # build a useful error message
                if type(args[0]) == type([]):
                    pkg = args[0]
                else:
                    pkg = args[1]

                if type(pkg) == type([]):
                    pkgName = "%s-%s-%s.%s" % (pkg[0], pkg[1], pkg[2], pkg[4])
                else:
                    pkgName = pkg
                msg = "File Not Found: %s\n%s" % (pkgName, errMsg)
                log.log_me(msg)
                raise up2dateErrors.FileNotFoundError(msg)

            if not reset:
                if attempt_count >= attempts:
                    raise up2dateErrors.CommunicationError(e.errmsg)
                else:
                    failure = 1

        except rpclib.ResponseError:
            raise up2dateErrors.CommunicationError(
                "Broken response from the server.")

        if ret != None:
            break
        else:
            failure = 1