Coverage for src/P4OO/Change.py: 77%
35 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-09-07 17:17 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-09-07 17:17 +0000
1######################################################################
2# Copyright (c)2011-2012, 2015, 2024 David L. Armstrong.
3# Copyright (c)2012, Cisco Systems, Inc.
4#
5# P4OO.Change.py
6#
7######################################################################
9from dataclasses import dataclass, field
11from P4OO.Exceptions import P4Fatal
12from P4OO._SpecObj import _P4OOSpecObj
13from P4OO._Set import _P4OOSet
15@dataclass(unsafe_hash=True)
16class P4OOChange(_P4OOSpecObj):
17 """
18 Perforce Change Spec Object
20 id Required: Yes
22 Forcible: Yes
24 Attributes:
25 change (int): Change #
26 user (P4OOUser): User that created the change spec
27 description (str): Description field
28 client (P4OOClient | str): Current client workspace
29 status (str): [`pending`|`shelved`|`submitted`|`new`]
30 type (str): [`restricted`|`public`]
31 jobs (P4OOJobSet | P4OOJob | str): List of jobs that are fixed by this change
32 date (datetime): Time of last update to the spec
34 See Also:
35 Perforce Helix Core Command Reference:
36 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_change.html
37 """
39 # Subclasses must define SPECOBJ_TYPE
40 _SPECOBJ_TYPE = 'change'
42 def getChangesFromChangeNums(self, otherChange, client):
43 """ Fetch the list of changes from this change to another one.
45 ASSUMPTIONS:
46 - self represents the lower of the two changes. If the other
47 direction is desired, then make the call against the other
48 change instead.
49 """
51 if not isinstance(otherChange, P4OOChange):
52 raise TypeError(otherChange)
54 # +1 to not include the from change
55 firstChange = int(self._getSpecID()) + 1
56 lastChange = int(otherChange._getSpecID())
58 aggregatedChanges = P4OOChangeSet()
59 view = client._getSpecAttr('View')
60 for viewLine in view:
61 viewSpec = viewLine.split(" ", 2)
63 fileChangeRange = '%s@%d,%d' % (viewSpec[0], firstChange,
64 lastChange)
66 changeSet = P4OOChangeSet(_p4Conn=self._getP4Connection())
67 viewChanges = changeSet.query(files=fileChangeRange,
68 longOutput=1)
70 aggregatedChanges |= viewChanges
72 return aggregatedChanges
74# def reopenFiles(self):
75# return self._runCommand('reopen',
76# change=self,
77# files="//%s/..." %
78# self._getSpecAttr('client'),
79# p4client=self._getSpecAttr('client')
80# )
82 def revertOpenedFiles(self):
83 """
84 Executes `p4 revert -k` command for all files in this change
86 Returns:
87 (list(str)): Output returned from _P4OOBase._runCommand()
89 See Also:
90 Perforce Helix Core Command Reference:
91 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_revert.html
92 """
94# self.reopenFiles()
95 return self._runCommand('revert',
96 change=self,
97 noclientrefresh=True,
98 files="//%s/..." % self._getSpecAttr('client'),
99 p4client=self._getSpecAttr('client'))
100# try:
101# return self._runCommand('revert',
102# change=self,
103# noclientrefresh=True,
104# files="//%s/..." %
105# self._getSpecAttr('client'),
106# p4client=self._getSpecAttr('client')
107# )
108# except P4Fatal:
110 def deleteShelf(self):
111 """
112 Executes `p4 shelve -d` command for this change
114 Returns:
115 (list(str)): Output returned from _P4OOBase._runCommand()
117 See Also:
118 Perforce Helix Core Command Reference:
119 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_shelve.html
120 """
122 try:
123 return self._runCommand('shelve',
124 delete=True,
125 change=self,
126 force=True,
127 p4client=self._getSpecAttr('client'))
128 except P4Fatal:
129 return True
131 def deleteWithVengeance(self):
132 """
133 Performs all operations necessary to delete this (pending) change.
135 - Delete shelf
136 - Delete change spec
138 Returns:
139 (Boolean): Result from _P4OOSpecObj.deleteSpec()
141 See Also:
142 Perforce Helix Core Knowledge Base:
143 https://portal.perforce.com/s/article/3452
144 """
146# self.revertOpenedFiles()
147 self.deleteShelf()
148 return self.deleteSpec(force=True)
151@dataclass
152class P4OOChangeSet(_P4OOSet):
153 """ `P4OOSet` of `P4OOChange` objects """
155 def query(self, client: str=None, user: str=None, maxresults: int=None,
156 status: str=None, files: str=None, longoutput: bool=None,
157 **kwargs):
158 """
159 Executes `p4 changes` query
161 Args:
162 client (P4OOClient | str, optional): The client (viewspec) to
163 filter file revisions through
164 user (P4OOUser | str, optional): The user that created the change
165 maxresults (int, optional): Return only the first [max] results
166 status (str, optional): Filter changes by status:
167 [`pending`|`shelved`|`submitted`]
168 files (P4OOFileSet | P4OOFile | str, optional): The set of file
169 revisions to query
170 longoutput (bool, optional): include the full changelist
171 descriptions
173 Returns:
174 (P4OOChangeSet): `P4OOSet` of `P4OOChange` objects matching query
175 parameters
177 See Also:
178 Perforce Helix Core Command Reference:
179 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_changes.html
180 """
182 return self._query(setObjType='changes', client=client, user=user,
183 maxresults=maxresults, status=status, files=files,
184 longoutput=longoutput, **kwargs)