Beispiel #1
0
def p4CounterChange(ticket):
    """
    Perforce counter change
    """
    command = 'p4 -P %s counter change' % ticket

    debug(command)

    p = pexpect.spawn(command)
    p.expect(pexpect.EOF)
    counterChange = p.before

    debug(p.before)

    return counterChange
Beispiel #2
0
def p4login(passwd):
    """
    Perforce login and get the ticket, which is valid for next 24 hours.
    """

    p = pexpect.spawn('p4 login -p')
    index = p.expect(["Enter password:", pexpect.EOF])
    if index == 0:
        debug('send password...')
        p.sendline(passwd)
        p.expect(pexpect.EOF)

    ticket = p.before

    if string.find(ticket, 'invalid') != -1:
        return None
    else:
        return ticket.strip()
Beispiel #3
0
def p4LocalPath(p4client, repoPath, ticket):
    """
    Get the local path of given repo path.
    """

    command = 'p4 -P %s -c %s where %s' % (ticket, p4client, repoPath)

    p = pexpect.spawn(command)
    p.expect(pexpect.EOF)

    # there are three path, depo path, workspace path and local path
    # we only need the local path.

    if p.before.find('refer to') != -1:
        return None

    paths = p.before.split()

    return paths[2]
Beispiel #4
0
def p4ClientRoot(p4client, ticket):
    """
    Get client root.
    """

    command = 'p4 -P %s client -o %s' % (ticket, p4client)

    p = pexpect.spawn(command)
    p.expect(pexpect.EOF)

    lines = p.before.splitlines()

    for line in lines:

        groups = re.match(p4.CLIENT_ROOT, line)

        if groups:
            client_root = groups.group(1)
            return client_root.strip()

    return ''
Beispiel #5
0
def p4ChangeList(p4client, startCL, endCL, ticket):
    """
    Get p4 changelist related to given p4 client from startCL to endCL.
    """

    command = 'p4 -P %s -c %s changes -s submitted //%s/...@%d,@%s' % (ticket, p4client, p4client, startCL, endCL)

    p = pexpect.spawn(command)
    p.expect(pexpect.EOF)

    changeListInfo = p.before

    lines = changeListInfo.splitlines(True)

    changeListPattern = 'Change (\d+) on .*'

    clIds = []
    for line in lines:
        groups = re.match(changeListPattern, line)
        clIds.append(int(groups.group(1)))

    clIds.sort()

    return clIds
Beispiel #6
0
def p4DiffFile(p4client, clId, ticket):
    """
    Get diff
    """

    command = 'p4 -P %s -c %s describe %d' % (ticket, p4client, clId)

    p = pexpect.spawn(command)
    p.expect(pexpect.EOF)

    messages = p.before.splitlines(True)

    fileChanges = {}

    currentFileName = None

    for message in messages:

        message = message.strip()

        groups = re.match(p4.FILE_PATTERN, message)

        if groups is not None:

            depotFilePath = groups.group(1)

            currentFileName = p4LocalPath(p4client, depotFilePath, ticket)

            if not currentFileName:
                debug("Can't find the local path of given file") # actually, it's impossible.
                sys.exit(1)

            fileChanges[currentFileName] = []
            continue

        groups = re.match(p4.DIFF_PATTERN, message)
        if groups is not None:

            src = groups.group(1)
            mode = groups.group(2)
            dest = groups.group(3)

            srcLines = src.split(',')
            destLines = dest.split(',')

            srcRange = None
            if len(srcLines) == 1:
                srcRange = Range(int(srcLines[0]), int(srcLines[0]))
            else:
                srcRange = Range(int(srcLines[0]), int(srcLines[1]))

            destRange = None
            if len(destLines) == 1:
                destRange = Range(int(destLines[0]), int(destLines[0]))
            else:
                destRange = Range(int(destLines[0]), int(destLines[1]))


            if currentFileName:
                fileChanges[currentFileName].append(FileChange(srcRange, destRange, mode))

            continue

    return fileChanges