Source

cheesecake-service / pypi.py


import socket
import time
import xmlrpclib

from config import PYPI_ADDRESS, PYPI_PASSWORD


def get_releases_list(timestamp):
    """Get list of updated releases since given `timestamp`.
    """
    try:
        server = xmlrpclib.Server(PYPI_ADDRESS)
        return server.updated_releases(timestamp)
    #
    # Anything can happen on the other side, so catch everything.
    #   For the record, exceptions experienced so far:
    #   xmlrpclib.ProtocolError, socket.error, psycopg.OperationalError.
    except:
        return []

def post_results(name, version, score_data):
    """Post score of a release to PyPI.

    Return True on success and False on failure.
    """
    while True:
        try:
            server = xmlrpclib.Server(PYPI_ADDRESS)
            server.post_cheesecake_for_release(name, version, score_data, PYPI_PASSWORD)
            break
        except xmlrpclib.Fault, e:
            return False
        #
        # Anything can happen on the other side, so catch everything.
        #   For the record, exceptions experienced so far:
        #   xmlrpclib.ProtocolError, socket.error, psycopg.OperationalError.
        except:
            # Wait one minute and try again.
            time.sleep(60)

    return True