summaryrefslogtreecommitdiff
path: root/utils/source_builder/P4.py
blob: 0eac203ffe587a7b79fa59ef22d0779bc345a0d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import sys, os, string, re, time, smtplib, getopt

# syncs the current clientspec
def Sync( szP4SrcFilesToWatch, bForce ):
    print "syncing to files " + szP4SrcFilesToWatch + "..."
    sForce = ""
    if bForce:
        sForce = "-f "
    aszSyncLines = string.split( szP4SrcFilesToWatch, ";" )

    for szLine in aszSyncLines:
        if szLine:
            print "p4 sync " + sForce + szLine
            os.popen('p4 sync ' + sForce + szLine)
    print "  sync completed"

# current changelist number for this clientspec
def SubmittedChangelist( szP4SrcFilesToWatch ):
    szChangeText = os.popen('p4 changes -m1 -s submitted ' + szP4SrcFilesToWatch).read()
    line = []
    line = string.split( szChangeText )
    if len(line) > 0:
        return line[1]
    
# returns a set of changes of range [start, end]    
def GetChangelistRange(start, end, szP4SrcFilesToWatch):
	if start and end:
		szChangeText = os.popen('p4 changes -m10 ' + szP4SrcFilesToWatch + '@' + start + ',' + end).read()
		return string.split(szChangeText, '\n');
	szResult = []
	return szResult
	
# returns the raw text of a set of the most recent submissions
def GetRecentCheckins( szP4SrcFilesToWatch ):
    szChangeText = os.popen('p4 changes -m5 -s submitted ' + szP4SrcFilesToWatch).read()
    return "Most recent checkins:\n" + szChangeText
    
# perforce counter access
def GetCounter(counter):
    return string.split(os.popen('p4 counter ' + counter).read(), '\n')[0]

#returns the raw text of all unverified checkins
def GetUnverifiedCheckins( szP4SrcFilesToWatch, szVerifiedCounter, szChangeCounter ):
    szCounter = GetCounter( szVerifiedCounter )
    szLastVerified = str( int( szCounter ) + 1 )
    szCurrentChange = GetCounter( szChangeCounter )
    szChangeText = os.popen('p4 changes -s submitted ' + szP4SrcFilesToWatch + '@' + szLastVerified + ',@' + szCurrentChange).read()
    return "Unverified checkins:\n" + szChangeText
    
# extracts an email from a "changes" output line
def GetEmailFromChangeLine(changeline):
    change = (string.split(changeline, ' '))[1]
    output = os.popen('p4 change -o ' + change).read()
    user = string.split(string.split(output, "User:")[2])[0]
    output = os.popen('p4 user -o ' + user).read()
    return string.split(string.split(output, "Email:")[2])[0]


# perforce counter setting
def SetCounter(counter, value):
    os.popen('p4 counter ' + counter + ' ' + value).read()

# checks to see if any update is currently available
def AnyNewCheckins( szChangeCounter, szP4SrcFilesToWatch ):    
    szChange = GetCounter(szChangeCounter)
    if not szChange:
        #is this the problem?  Every night all these things fail.
        return 0
    return szChange <> SubmittedChangelist( szP4SrcFilesToWatch )

def LockMutex( szMutex ):    
    szLogLines = os.popen('newp4mutex lock ' + szMutex + ' 3 steambuilder perforce:1666').read()
    count = string.count( szLogLines, '\n' )
    if ( count < 3 ):
        print szLogLines
        print "HERE IS THE WEIRD LOCK ERROR!"
        print szMutex + "mutex lock failed."
        return 0
    szT = string.split(szLogLines, '\n')[2]
    successLine = string.split( szT, ' ')
    if successLine[0] == "Success:":
        print szMutex + " mutex locked."
        return 1
    else:
        print szMutex + " mutex lock failed."
        return 0

def LockMutexOld( szMutex ):
    szLogLines = os.popen('p4mutex lock ' + szMutex + ' 3 steambuilder perforce:1666').read()
    count = string.count( szLogLines, '\n' )
    if ( count < 3 ):
        print szLogLines
        print "HERE IS THE WEIRD LOCK ERROR!"
        print szMutex + "mutex lock failed."
        return 0
    szT = string.split(szLogLines, '\n')[3]
    successLine = string.split( szT, ' ')
    if successLine[0] == "Success:":
        print szMutex + " mutex locked."
        return 1
    else:
        print szMutex + " mutex lock failed."
        return 0

def UnlockMutex( szMutex ):
    szLogLines = os.popen('newp4mutex release ' + szMutex + ' 3 steambuilder perforce:1666').read()
    count = string.count( szLogLines, '\n' )
    if ( count < 3 ):
        print szLogLines
        print "HERE IS THE WEIRD RELEASE ERROR!"
        print szMutex + "mutex release failed."
        return 0
    szT = string.split(szLogLines, '\n')[2]
   # print szT
    successLine = string.split( szT, ' ')
   # print successLine
    if successLine[0] == "Success:":
        print szMutex + " mutex released."
        return 1
    else:
        print szMutex + " mutex release failed."
        return 0

def Integrate( szBranch ):
    return os.popen('p4 integ -b ' + szBranch + ' -1 -i' ).read()

def Revert( szFiles ):
    return os.popen('p4 revert ' + szFiles).read()

def Resolve():
    return os.popen('p4 resolve -am').read()

def Fstat( szFiles ):
    szConflicts = os.popen('p4 fstat -Ru ' + szFiles).read()
    return szConflicts

def Changes( szFile, iNumResults ):
    return os.popen('p4 changes -m' + iNumResults + ' ' + szFile).read()

def Query( szMutex ):
    szLines = os.popen( 'p4mutex query ' + szMutex ).read()
    count = string.count( szLines, 'HELD' )
    if (count == 0 ):
        return 1
    else:
        print "Lock held"
        return 0

def SetClient( szClient ):
    os.environ['P4CLIENT'] = szClient