I don’t know why this will raise AttributeError, but in document it seems right https://www.perforce.com/manuals/p4python/Content/P4Python/python.p4_progress.html
from P4 import P4, P4Exception, Progress
from tqdm import tqdm
class P4ProgressHandler(Progress):
TYPES = ["Unknown", "Submit", "Sync", "Clone"]
pbar = None
def init(self, type):
super().init(type)
if self.pbar is not None:
self.pbar.close()
self.pbar = tqdm(desc="P4 Progress: {}".format(self.TYPES[type]))
def setDescription(self, description, units):
super().setDescription(description, units)
def setTotal(self, total):
super().setTotal(total)
self.pbar.total = total
def update(self, position):
super().update(position)
if self.pbar is not None:
self.pbar.update(position)
def done(self, fail):
super().done(fail)
if self.pbar is not None:
self.pbar.close()
p4 = P4()
p4.using_progress(P4ProgressHandler())
Python Version: 3.10.0
P4Python Version: P4PYTHON/"NTX64"/"2022.1"/"2299330" ("2022.1/2285021" API) ("2022"/"06"/"14").
Error Output:
Traceback (most recent call last):
File "E:\ForgeCI\ForgeCI\Utils\P4Methods.py", line 37, in <module>
p4.using_progress(P4ProgressHandler())
File "E:\ForgeCI\venv\lib\site-packages\P4.py", line 517, in __getattr__
raise AttributeError(name)
AttributeError: using_progress
According to the doc for the P4
class, there is no using_progress
method:
https://www.perforce.com/manuals/p4python/Content/P4Python/python.p4.html#Instance_Methods_..39
Between that and the AttributeError
I think it's safe to assume that the mention of P4.using_progress
in the doc for the Progress
class is an error in the doc. Since progress
is a property of P4
, you should be able to replace:
p4.using_progress(P4ProgressHandler())
with:
p4.progress = P4ProgressHandler()