def main():
    """Do the thing."""
    try:
        p4gf_version.git_version_check()

        # Connect.
        global P4PORT, P4USER, p4
        p4 = create_p4(port=P4PORT, user=P4USER)
        P4PORT = p4.port
        P4USER = p4.user
        report(INFO, "P4PORT : {}".format(p4.port))
        report(INFO, "P4USER : {}".format(p4.user))
        p4.connect()
        p4gf_version.p4d_version_check(p4)

        # Require that we have super permission.
        # Might as well keep the result in case we need to write a new protect
        # table later. Saves a 'p4 protect -o' trip to the server
        protect_lines = fetch_protect()

        ensure_user()
        ensure_group()
        ensure_depot()
        ensure_protect(protect_lines)
        ensure_protects_configurable()

    # pylint: disable=W0703
    # Catching too general exception
    except Exception as e:
        sys.stderr.write(e.args[0] + '\n')
        exit(1)
def main():
    """Do the thing."""
    try:
        p4gf_version.git_version_check()

        # Connect.
        global P4PORT, P4USER, p4
        p4 = create_p4(port=P4PORT, user=P4USER)
        P4PORT = p4.port
        P4USER = p4.user
        report(INFO, "P4PORT : {}".format(p4.port))
        report(INFO, "P4USER : {}".format(p4.user))
        p4.connect()
        p4gf_version.p4d_version_check(p4)

        # Require that we have super permission.
        # Might as well keep the result in case we need to write a new protect
        # table later. Saves a 'p4 protect -o' trip to the server
        protect_lines = fetch_protect()

        ensure_user()
        ensure_group()
        ensure_depot()
        ensure_protect(protect_lines)
        ensure_protects_configurable()

    # pylint: disable=W0703
    # Catching too general exception
    except Exception as e:
        sys.stderr.write(e.args[0] + '\n')
        exit(1)
def connect_p4(port=None, user=None, client=None):
    """Connects to a P4D instance and checks the version of the server. The
    connected P4.P4 instance is returned. If the version of the server is
    not acceptable, a message is printed and RuntimeError is raised.
    If the client is unable to connect to the server, then None is returned.
    """
    if not user:
        user = p4gf_const.P4GF_USER
    p4 = create_p4(port, user, client)
    try:
        p4.connect()
        LOG.debug("connect_p4(): u={} {}".format(user, p4))
    except P4.P4Exception as e:
        LOG.error('Failed P4 connect: {}'.format(str(e)))
        sys.stderr.write("error: cannot connect, p4d not running?\n")
        return None
    p4gf_version.p4d_version_check(p4)
    return p4
Ejemplo n.º 4
0
def create_p4(port=None, user=None, client=None, connect=True):
    """Return a new P4.P4() instance with its prog set to
    'P4GF/2012.1.PREP-TEST_ONLY/415678 (2012/04/14)'

    By default the P4 is connected; call with connect=False to skip connection.

    There should be NO bare calls to P4.P4().

    """
    if 'P4PORT' in os.environ:
        LOG.debug("os.environment['P4PORT'] {0}".format(os.environ['P4PORT']))
    p4 = P4.P4()
    LOG.debug("default p4.port = {0}".format(p4.port))

    p4.prog = p4gf_version.as_single_line()
    p4.exception_level = P4.P4.RAISE_ERRORS

    if port:
        p4.port = port
    if user:
        p4.user = user
    else:
        p4.user = p4gf_const.P4GF_USER
    if client:
        p4.client = client

    _CONNECTION_LIST.append(p4)

    if connect:
        try:
            LOG.debug("p4_connect(): u={} {}".format(user, p4))
            p4_connect(p4)

        except P4.P4Exception as e:
            sys.stderr.write(_('error: cannot connect, p4d not running?\n'))
            sys.stderr.write(_('Failed P4 connect: {}'.format(str(e))))
            return None
        p4gf_version.p4d_version_check(p4)

    return p4