我在 Wasta-Linux 上的 PT9.0 中尝试使用“Outils personnalisation” > “Admin” > “Show Project Plan HTML”时遇到了错误。原来该 Python 脚本试图使用 Windows 注册表来查找 Paratext 项目文件夹。请注意第 3 行,“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