[Linux] RBTools 出現 Path xxx does not match a valid Perforce path 的錯誤

[Linux] RBTools 出現 Path xxx does not match a valid Perforce path 的錯誤

裝好 Review Board server 之後,

原本我看 yum 上有 RBTools,很高興地安裝好,

可是想要用 rbt 指令,將 Perforce changelist 推上 Review Board 時,

卻發生了 Path xxx does not match a valid Perforce path 的錯誤:

[testuser@localhost Perforce]$ rbt post -p --submit-as testuser 4634913
CRITICAL: Path 4634913 does not match a valid Perforce path.

 

檢查了一下 Perforce 相關的環境變數,

像是 P4CLIENT, P4PORT, P4USER, P4PASSWD 等等,

看來都有設定,而且執行 p4 一些指令也都正常,

說明這些環境變數設置沒有問題。

 

在 rbt 指令加上 -d 參數,看看能不能吐出多一點除錯訊息:

[testuser@localhost Perforce]$ rbt post -d -p --submit-as testuser 4634913
>>> RBTools 1.0.2
>>> Python 3.6.8 (default, Apr 25 2019, 21:02:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
>>> Running on Linux-3.10.0-957.el7.x86_64-x86_64-with-centos-7.6.1810-Core
>>> Home = /home/testuser
>>> Current directory = /home/testuser/Perforce
>>> Command line: rbt post -d -p --submit-as testuser 4634913
>>> Running: tf vc help
>>> Checking for a Perforce repository...
>>> Running: p4 info
>>> Running: diff --version
>>> Repository info: Path: perforce.test.com:1666, Base path: None, Supports changesets: True
>>> Making HTTP GET request to http://10.1.2.3:8000/api/
>>> Running: p4 info
Traceback (most recent call last):
  File "/usr/bin/rbt", line 11, in 
    load_entry_point('RBTools==1.0.2', 'console_scripts', 'rbt')()
  File "/usr/lib/python3.6/site-packages/rbtools/commands/main.py", line 120, in main
    command.run_from_argv([RB_MAIN, command_name] + args)
  File "/usr/lib/python3.6/site-packages/rbtools/commands/__init__.py", line 725, in run_from_argv
    exit_code = self.main(*args) or 0
  File "/usr/lib/python3.6/site-packages/rbtools/commands/post.py", line 806, in main
    extra_args=extra_args)
  File "/usr/lib/python3.6/site-packages/rbtools/clients/perforce.py", line 729, in diff
    return self._path_diff(extra_args, exclude_patterns)
  File "/usr/lib/python3.6/site-packages/rbtools/clients/perforce.py", line 1470, in _path_diff
    % path)
rbtools.clients.errors.SCMError: Path 4634913 does not match a valid Perforce path.

 

上面的除錯訊息多了一些資訊,

我們知道現在出錯的是 perforce.py,

在 perforce.py 裡面相關的地方加上 pdb 指令來除錯:

import pdb; pdb.set_trace()

 

試了幾次,終於逼近到出錯的地方,

change[0] 是一個 dict,

程式裡看起來是想要取 change[0][“Status”] 取不到,

但是 change[0][b”Status”] 是取的到的:

(Pdb) change[0]
{b'code': b'stat', b'Change': b'4634913', b'Date': b'2019/06/18 14:49:19', b'Client': b'testuser_localhost', b'User': b'testuser', b'Status': b'submitted', b'Description': b'Refactor\n', b'Type': b'public'}

(Pdb) change[0]["Status"]
*** KeyError: 'Status'

(Pdb) change[0][b"Status"]
b'submitted'

 

看來這是 Python 3 造成的問題,

dict 裡存的是 binary 型的純 ASCII 文字,

因此在 Python 3 中會以 b”Status” 來表示。

但 RBTools 的程式取的是 “Status”,跑在 Python 2 不會有問題,

跑在 Python 3 的話就不行了…

 

明白這點之後,猜測 yum 安裝的 RBTools 預設是用 Python 3 來跑,

但其實 RBTools 並沒辦法在 Python 3 上面跑…

暫時解決的方法,就是自己用 pip 或 easy_install 安裝 RBTools,

這樣就能保證使用 Python 2 了:

sudo yum remove RBTools
sudo easy_install rbtools

 

使用 easy_install 安裝 Python 2 的 rbtools 之後,

上面的問題果然就消失囉~

(本頁面已被瀏覽過 359 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料