简体   繁体   中英

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

I am distributing a python application using py2exe. 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. 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.

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. 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. 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. 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. 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.

A much easier alternative that might be what you want is just to bundle all those dependencies into one exe file. You can do this like so, this one contains a lot of extra options to add to the exe file in raw input:

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,
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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