首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >P4Python不能使用进度类

P4Python不能使用进度类
EN

Stack Overflow用户
提问于 2022-07-21 03:45:00
回答 1查看 66关注 0票数 0

我不知道这为什么会引起AttributeError,但在文件中,这似乎是正确的https://www.perforce.com/manuals/p4python/Content/P4Python/python.p4_progress.html

代码语言:javascript
复制
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版本: 3.10.0

P4Python版本: P4PYTHON/"NTX64"/"2022.1"/"2299330“("2022.1/2285021”API) ("2022"/"06"/"14")。

错误输出:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-21 05:14:24

根据P4类的文档,没有using_progress方法:

https://www.perforce.com/manuals/p4python/Content/P4Python/python.p4.html#Instance_Methods_..39

在此与AttributeError之间,我认为可以安全地假定,文档中提到Progress类的P4.using_progress是文档中的一个错误。由于progressP4的一个属性,所以您应该能够替换:

代码语言:javascript
复制
p4.using_progress(P4ProgressHandler()) 

通过以下方式:

代码语言:javascript
复制
p4.progress = P4ProgressHandler()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73060475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档