-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp4t.py
More file actions
executable file
·103 lines (94 loc) · 3.37 KB
/
p4t.py
File metadata and controls
executable file
·103 lines (94 loc) · 3.37 KB
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
#!/usr/bin/env python
from P4 import P4,P4Exception
import pprint
import shutil
import os.path
import tempfile
import sys
p4 = P4()
p4.connect()
class Impact:
def __init__(self, p4):
self.p4 = p4
def repoToLocal(self,fileref):
x = self.p4.run("fstat",fileref)[0]
return x["clientFile"]
def localToRepo(self,fileref):
x = self.p4.run("fstat",fileref)[0]
return x["depotFile"]
class ImpactPerforceChange:
def __init__(self,changelist, depotFile, rev, fileSize, digest, type_,action):
self.changelist = changelist
self.depotFile = depotFile
self.rev = int(rev)
self.fileSize = fileSize
self.digest = digest
self.type_ = type_
self.action = action
self.localfile = self.changelist.impact.repoToLocal(depotFile)
class ImpactPerforceChangeList:
def __init__(self,impact,change):
self.impact = impact
self.change = change
def updateFields(self,p4dict):
self.change = p4dict["change"]
self.changeType = p4dict["changeType"]
self.client = p4dict["client"]
self.desc = p4dict["desc"]
self.shelved = p4dict.get("shelved",None)
self.status = p4dict["status"]
self.time = p4dict["time"]
self.user = p4dict["user"]
self.depotFile = p4dict.get("depotFile",[])
self.changes = []
def update(self):
details = self.impact.p4.run("describe",self.change)[0]
print(details)
self.updateFields(details)
filedetails = zip(
details['depotFile'],
details['rev'],
details['fileSize'],
details['digest'],
details['type'],
details['action'],
)
self.changes = map(lambda t: ImpactPerforceChange(self,*t),filedetails)
def p4t_change(cl_nr):
impact = Impact(p4)
l = ImpactPerforceChangeList(impact, cl_nr)
l.update()
tempdir = tempfile.mkdtemp("p4t")
scriptpath=tempdir+os.path.sep+"script"
summarypath=tempdir+os.path.sep+"summary.txt"
scriptcontent = ""
def to_tmp_local(depotpath, tempdir):
return depotpath.replace("//depot",tempdir)
for c in l.changes:
newpath = None
oldpath = None
localfile = to_tmp_local(c.depotFile,tempdir)
try:
os.makedirs(os.path.dirname(localfile))
except:
pass
if c.action == "add" or c.action == "edit":
(name,ext) = os.path.splitext(localfile)
newrev = c.rev
newpath = "{}#{}{}".format(name,newrev,ext)
p4.run("print","-o"+newpath,c.depotFile+ "#{}".format(newrev))
scriptcontent += ":tabnew {}\n".format(newpath.replace("#","\#"))
if c.action == "edit":
(name,ext) = os.path.splitext(localfile)
oldrev = c.rev-1
oldpath = "{}#{}{}".format(name,oldrev,ext)
p4.run("print","-o"+oldpath,c.depotFile+ "#{}".format(oldrev))
scriptcontent += ":vert diffsplit {}\n".format(oldpath.replace("#","\#"))
summarycontent=os.popen('p4 describe -s {}'.format(cl_nr)).read()
open(summarypath,'w').write(summarycontent)
open(scriptpath,'w').write(scriptcontent)
os.system("vim {} -s {}".format(summarypath,scriptpath))
shutil.rmtree(tempdir)
if __name__ == "__main__":
if "change" in sys.argv:
p4t_change(sys.argv[2])