-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp4pending.py
103 lines (85 loc) · 2.6 KB
/
p4pending.py
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
import os
from .p4core import p4run, p4
from .p4changelist import changelist_payload_fetcher, P4Changelist
class P4Pending(object):
"""
This class provide basic services similar to the Pending tab
in P4V.
"""
def __init__(self, user=None, workspace=None):
"""
user: Perforce user name. None defaults to current user saved in `p4 info`.
workspace: Perforce clientspec name. None defaults to current client save in `p4 info`.
"""
if user is None:
self.__user = p4.user
else:
self.__user = user
if workspace is None:
self.__client = p4.client
else:
self.__client = workspace
self.__changes = []
self.fetch()
@property
def user(self):
"""
User name.
"""
return self.__user
@user.setter
def user(self, u):
"""
Do not forget to call fetch() if user or/and client are updated.
"""
self.__user = u
@property
def workspace(self):
"""
Clientspec name.
"""
return self.__client
@property
def workspace(self, w):
"""
Do not forget to call fetch() if user or/and client are updated.
"""
self.__client = w
@property
def changes(self):
"""
List of changelists within user and client combo.
"""
return self.__changes
def __iter__(self):
"""
Make this class iterable.
yield: P4Changelist object.
"""
for payload in changelist_payload_fetcher(self.__changes):
change = P4Changelist(-1)
change.load(payload)
yield change
def fetch(self):
""""
This method updates the pending changelists by fetching P4 api calls
to Perforce server.
This method generally needs to be invoked every time user and/or client
are updated.
"""
self.__changes = [c['change'] for c in p4run('changes', '-u', self.__user, '-c', self.__client, '-s', 'pending')]
self.__changes.append('default')
def __str__(self):
"""
String representation of the pending changelist class.
"""
_str = []
for c in self.__changes:
_str.append(str(c))
_str.append('')
return os.linesep.join(_str)
def dump(self):
"""
Print the string representation of the pending changelist class.
"""
print(self)