如何让 PyInstaller 在生成的可执行文件中嵌入 SVN 工作副本属性?
How to get PyInstaller to embed SVN Working Copy properties in the generated executable?
我正在使用Python3.5.2和PyInstaller3.2转一个小PyQt5 将应用程序转换为供内部使用的独立实用程序。 PyInstaller 是必需的,因为大多数团队还没有安装 Python3.
我想将生成该实用程序的 WC 的 Subversion 属性放入该实用程序的 Help->About
对话框中,但我正在努力寻找一种合理的方法来执行此操作。
如果我使用不同的构建环境,我会定义一个模板文件并让 TortoiseSVN 的 SubWCRev 生成一个源文件作为预构建步骤。然而,目前我的实用程序的 "build"
是在修改后的规范文件上调用 PyInstaller 的一步过程。我宁愿保持这种方式。
我怀疑可以为 PyInstaller 编写一个自定义挂钩,它将从工作副本中获取所需的属性,(等同于 WCRANGE
、WCMODS
和 WCMIXED
,可能使用 pysvn),并将它们作为生成的 exe
的属性嵌入。有没有人这样做过,或者这种做法是完全错误的?
谢谢。
感谢您的提示。 @Repiklis描述的方向提供了一个很好的解决方案。
我在 PyInstaller
的 .spec 文件顶部添加了以下代码
import json
import os
import pysvn
os.remove('versioninfo.json')
c = pysvn.Client()
entry = c.info('.')
statuses = c.status('.')
mods = [{'Path': s.path,
'CommitRevision': s.entry.commit_revision.number,
'UpdateRevision': s.entry.revision.number,
'Kind': str(s.entry.kind),
'Status': str(s.text_status if
s.entry.kind == pysvn.node_kind.file
else
s.prop_status)
} for s in statuses if (
s.text_status != pysvn.wc_status_kind.none
and
s.text_status != pysvn.wc_status_kind.unversioned
and
s.text_status != pysvn.wc_status_kind.ignored
)]
version = {'URL': entry.url, 'Source': mods}
with open('versioninfo.json', 'w') as fp:
json.dump(version, fp=fp, sort_keys=True, indent=4)
后面还有
a = Analysis(...
datas=[..., ('versioninfo.json', '.')]
...
)
最后,json 文件被加载到 Help->About
对话框中,并呈现给用户。
谢谢大家
我正在使用Python3.5.2和PyInstaller3.2转一个小PyQt5 将应用程序转换为供内部使用的独立实用程序。 PyInstaller 是必需的,因为大多数团队还没有安装 Python3.
我想将生成该实用程序的 WC 的 Subversion 属性放入该实用程序的 Help->About
对话框中,但我正在努力寻找一种合理的方法来执行此操作。
如果我使用不同的构建环境,我会定义一个模板文件并让 TortoiseSVN 的 SubWCRev 生成一个源文件作为预构建步骤。然而,目前我的实用程序的 "build"
是在修改后的规范文件上调用 PyInstaller 的一步过程。我宁愿保持这种方式。
我怀疑可以为 PyInstaller 编写一个自定义挂钩,它将从工作副本中获取所需的属性,(等同于 WCRANGE
、WCMODS
和 WCMIXED
,可能使用 pysvn),并将它们作为生成的 exe
的属性嵌入。有没有人这样做过,或者这种做法是完全错误的?
谢谢。
感谢您的提示。 @Repiklis描述的方向提供了一个很好的解决方案。 我在 PyInstaller
的 .spec 文件顶部添加了以下代码import json
import os
import pysvn
os.remove('versioninfo.json')
c = pysvn.Client()
entry = c.info('.')
statuses = c.status('.')
mods = [{'Path': s.path,
'CommitRevision': s.entry.commit_revision.number,
'UpdateRevision': s.entry.revision.number,
'Kind': str(s.entry.kind),
'Status': str(s.text_status if
s.entry.kind == pysvn.node_kind.file
else
s.prop_status)
} for s in statuses if (
s.text_status != pysvn.wc_status_kind.none
and
s.text_status != pysvn.wc_status_kind.unversioned
and
s.text_status != pysvn.wc_status_kind.ignored
)]
version = {'URL': entry.url, 'Source': mods}
with open('versioninfo.json', 'w') as fp:
json.dump(version, fp=fp, sort_keys=True, indent=4)
后面还有
a = Analysis(...
datas=[..., ('versioninfo.json', '.')]
...
)
最后,json 文件被加载到 Help->About
对话框中,并呈现给用户。
谢谢大家