简体   繁体   English

如何为py2exe发行版创建清单文件?

[英]How can I create a manifest file for my py2exe distribution?

I am distributing a python application using py2exe. 我正在使用py2exe分发python应用程序。 When unzipped, in addition to the main exe file, the distribution contains some dll's, config files, etc. I would like to add a manifest file to be included with the distribution. 解压缩后,除主exe文件外,该发行版还包含一些dll,配置文件等。我想添加一个清单文件以包含在发行版中。 This file will list all the required files (dll's, config files) and some sort of cryptographic hash for each of these files, so that if the files are tampered with, the main executable cannot be run. 该文件将列出所有必需的文件(dll,配置文件)以及每个文件的某种加密哈希,因此,如果文件被篡改,则主可执行文件将无法运行。

I could write a script to generate the file during the build and then check this file from within python when the application is run. 我可以编写一个脚本在生成过程中生成文件,然后在运行应用程序时从python中检查该文件。 However, it seems like this should be a common thing to do, so are there are any tools out there for this job? 但是,这似乎应该是一件很平常的事情,那么有没有什么工具可以完成这项工作呢?

Although there may be tools available online to do this, you could probably just add some code to your python compiler program. 尽管在线上可能有可用的工具来执行此操作,但您可能只需要向python编译器程序中添加一些代码即可。 This solution may not be the best or cleanest solution, but it should work. 该解决方案可能不是最佳或最干净的解决方案,但它应该可以工作。 You can find out what dll files and similar dependencies will be created by compiling it once in a non-zip format and listing the files. 您可以通过以非zip格式编译一次并列出文件来找出将创建哪些dll文件和类似的依赖项。 Than you can prepend code to the python program to check if these files are present, and compile it again with the modified python program, still without a zipfile. 比起您可以在python程序前添加代码来检查这些文件是否存在,然后使用修改后的python程序(仍然没有zipfile)再次对其进行编译。 You can than create an index file in the dist directory that all of the dependencies are found in by printing a string into a new file opened in write mode, and than you can compress the directory manually using the python module zipfile. 然后,您可以在dist目录中创建一个索引文件,在该目录中可以找到所有依赖项,方法是将一个字符串打印到以写方式打开的新文件中,然后可以使用python模块zipfile手动压缩该目录。

A much easier alternative that might be what you want is just to bundle all those dependencies into one exe file. 您可能想要的一种更简单的选择就是将所有这些依赖项捆绑到一个exe文件中。 You can do this like so, this one contains a lot of extra options to add to the exe file in raw input: 您可以像这样进行操作,这其中包含许多额外的选项,可以在原始输入中添加到exe文件:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
    windows = [{'script': raw_input("input filename: "),
                "icon_resources": [(1, raw_input("iconfilename: "))]
                }],
    name = raw_input("enter program name: "),
    version = raw_input("enter version: "),
    description = raw_input("enter description: "),
    author = raw_input("enter author: "),
    author_email = raw_input("enter author email: "),
    maintainer = raw_input("enter maintainer: "),
    maintainer_email = raw_input("enter maintainer email: "),
    url = raw_input("enter url: "),
    zipfile = None,
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM