我在 Wasta-Linux 上的 PT9.0 中嘗試使用「Outils personnalisation」>「Admin」>「Show Project Plan HTML」時遇到了錯誤。原來該 Python 腳本試圖使用 Windows 登錄(Registry)來尋找 Paratext 專案資料夾。請注意第三行「from _winreg import…」(來自 cms/ProjectPlanImport.py):
def settingsDirectory():
# Find the directory with Paratext 8 projects using the windows registry
from _winreg import OpenKey, EnumValue, HKEY_LOCAL_MACHINE
strPath = r"SOFTWARE\WOW6432Node\Paratext\8"
try:
aKey = OpenKey(HKEY_LOCAL_MACHINE, strPath)
for i in [0,1,2,3,4,5]:
aName, aValue, irrelevant = EnumValue(aKey,i)
if aName == 'Settings_Directory':
return aValue + '\\'
return None
except WindowsError:
# The registry key was not found
return None
except:
raise
然而,使用 os.path 模組可以透過相對路徑找到同一個資料夾。因此,我將系統上的該函式更新為以下內容:
def settingsDirectory():
# Find the directory with Paratext 8 projects using Python 2 tools.
cms_dir = os.path.dirname(os.path.realpath(__file__))
if os.path.basename(cms_dir) == 'cms' and os.path.isdir(cms_dir):
return os.path.dirname(cms_dir)
else:
return None
所以我想問的是:在非標準安裝中,cms 資料夾是否可能位於 Paratext 專案資料夾以外的位置,從而需要在 Windows 中進行登錄檢查?或者,如果並非如此,是否有人考慮更新 ProjectPlanImport.py 和 ProjectPlanRoot.py 腳本,使其使用內建工具,以增強腳本的通用相容性?
如果我能與相關人員討論,我也願意研究出一種方法來進行作業系統檢查,並以依賴作業系統的方式處理 settingsDirectory 的尋找。順帶一提,這些似乎是 cms 腳本中唯一引用 _winreg 模組的兩個地方。
I got an error trying to use “Outils personnalisation” > “Admin” > “Show Project Plan HTML” on PT9.0 in Wasta-Linux. It turns out the python script attempts to use the Windows Registry to find the Paratext Projects folder. Note the 3rd line, “from _winreg import…” (from cms/ProjectPlanImport.py):
def settingsDirectory():
# Find the directory with Paratext 8 projects using the windows registry
from _winreg import OpenKey, EnumValue, HKEY_LOCAL_MACHINE
strPath = r"SOFTWARE\WOW6432Node\Paratext\8"
try:
aKey = OpenKey(HKEY_LOCAL_MACHINE, strPath)
for i in [0,1,2,3,4,5]:
aName, aValue, irrelevant = EnumValue(aKey,i)
if aName == 'Settings_Directory':
return aValue + '\\'
return None
except WindowsError:
# The registry key was not found
return None
except:
raise
However, this same folder can be found in a relative fashion using the os.path module. So I updated the function on my system to the following:
def settingsDirectory():
# Find the directory with Paratext 8 projects using Python 2 tools.
cms_dir = os.path.dirname(os.path.realpath(__file__))
if os.path.basename(cms_dir) == 'cms' and os.path.isdir(cms_dir):
return os.path.dirname(cms_dir)
else:
return None
So I guess my question is: Is it possible that in a non-standard install the cms folder could be located somewhere other than within the Paratext Projects folder, which would necessitate the registry check in Windows? Or, if not, would someone consider updating the ProjectPlanImport.py and ProjectPlanRoot.py scripts to use the built-in tools to make the scripts more universally compatible?
I’d also be willing to work out a way to do an OS check and handle finding the settingsDirectory in an OS-dependent way if I could discuss this with the right person. By the way, these seem to be the only two places that the _winreg module is referenced in the cms scripts.
機器翻譯自 English