Exemplo n.º 1
0
 def __init__(self, platform, msiFileName, productName, manufacturer, productVersion, language):
     self.platform = platform
     self.msiFile  = FileObject(msiFileName) 
     self.tempDir = tempfile.mkdtemp()
     self.productCode = msilib.gen_uuid()
     self.upgradeCode = msilib.gen_uuid()
     self.productVersion = productVersion
     self.manufacturer = manufacturer
     self.language = language
     self.productName = productName
     self.RegsitryComponent = "RegistryComponent"
     self.registryRecords = []
     
     self.template =  QFile(":/files/pyMagicTemplateMSI2.msi")
     self.template.open(QFile.ReadOnly) 
     data = self.template.readAll()
     self.templatePath = msiFileName
     x = QFile(self.templatePath)
     if  x.open(QFile.WriteOnly):
         print "opened file for write"
         x.write(data)
     else:
         print "could not open file for writing"
         
     x.close()
     self.template.close()
Exemplo n.º 2
0
 def run(self):
     if not self.skip_build:
         self.run_command('build')
     install = self.reinitialize_command('install', reinit_subcommands = 1)
     install.prefix = self.bdist_dir
     install.skip_build = self.skip_build
     install.warn_dir = 0
     distutils.log.info("installing to %s", self.bdist_dir)
     install.ensure_finalized()
     install.run()
     self.mkpath(self.dist_dir)
     fullname = self.distribution.get_fullname()
     if os.path.exists(self.target_name):
         os.unlink(self.target_name)
     metadata = self.distribution.metadata
     author = metadata.author or metadata.maintainer or "UNKNOWN"
     version = metadata.get_version()
     sversion = "%d.%d.%d" % \
             distutils.version.StrictVersion(version).version
     self.db = msilib.init_database(self.target_name, msilib.schema,
             self.distribution.metadata.name, msilib.gen_uuid(), sversion,
             author)
     msilib.add_tables(self.db, msilib.sequence)
     self.add_properties()
     self.add_config(fullname)
     self.add_upgrade_config(sversion)
     self.add_ui()
     self.add_files()
     self.db.Commit()
     if not self.keep_temp:
         distutils.dir_util.remove_tree(self.bdist_dir,
                 dry_run = self.dry_run)
Exemplo n.º 3
0
	def run(self):
		if not (os.path.isdir(self.bdist_dir) and self.skip_build):
			self.run_command('py2exe')

		fullname = self.distribution.get_fullname()
		installer_name = self.get_installer_filename(fullname)
		installer_name = os.path.abspath(installer_name)

		if os.path.exists(installer_name):
			os.unlink(installer_name)

		metadata = self.distribution.metadata
		author = metadata.author

		if not author:
			author = metadata.maintainer
		if not author:
			author = 'UNKNOWN'

		version = metadata.get_version()
		sversion = '%d.%d.%d' % StrictVersion(version).version
		product_name = self.distribution.get_name()

		log.info('creating MSI package %s', installer_name)

		self.db = msilib.init_database(installer_name, schema,
				product_name, self.product_code or msilib.gen_uuid(), sversion, author)

		msilib.add_tables(self.db, sequence)

		props = []

		if self.upgrade_code:
			props.extend([
				('UpgradeCode', self.upgrade_code),
				('SecureCustomProperties', 'REPLACE')
			])

			msilib.add_data(self.db, 'Upgrade', [(
				self.upgrade_code,  # UpgradeCode
				None,  # VersionMin, detect all
				sversion,  # VersionMax
				None,  # Language
				0,  # Attributes
				None,  # Remove, REMOVE=ALL
				'REPLACE'  # ActionProperty
			)])

		if props:
			msilib.add_data(self.db, 'Property', props)

		self.add_files()
		self.add_services()

		self.db.Commit()

		if not self.keep_temp:
			remove_tree(self.bdist_dir, dry_run=self.dry_run)
			remove_tree(self.get_finalized_command('build').build_base)
Exemplo n.º 4
0
def create_msi_installer(package, run_node, msi_root_node, installer_name=None, output_dir="dist"):
    meta = PackageMetadata.from_package(package)

    string_version = "%d.%d.%d" % (meta.version_major, meta.version_minor, meta.version_micro)

    fullname = "%s-%s" % (package.name, string_version)
    if installer_name is None:
        installer_name = "%s-%s.msi" % (package.name, string_version)
    parent_node = run_node.make_node(output_dir)
    if parent_node is None:
        raise IOError()
    installer_node = parent_node.make_node(installer_name)
    installer_name = installer_node.abspath()
    installer_node.parent.mkdir()

    author = meta.author

    short_version = sysconfig.get_python_version()

    has_ext_modules = True
    if has_ext_modules:
        target_version = short_version
    else:
        target_version = None

    if target_version:
        product_name = "Python %s %s" % (target_version, meta.fullname)
    else:
        product_name = "Python %s" % meta.fullname

    if target_version:
        versions = [target_version]
    else:
        versions = list(ALL_VERSIONS)

    db = msilib.init_database(installer_name, schema, product_name, msilib.gen_uuid(), string_version, author)
    msilib.add_tables(db, sequence)

    props = [("DistVersion", meta.version)]
    email = meta.author_email or meta.maintainer_email
    if email:
        props.append(("ARPCONTACT", email))
    if meta.url:
        props.append(("ARPURLINFOABOUT", meta.url))
    if props:
        add_data(db, "Property", props)

    add_find_python(db, versions)
    add_files(db, msi_root_node, versions, OTHER_VERSION)
    add_scripts(db)
    add_ui(db, fullname, versions, OTHER_VERSION)
    db.Commit()
Exemplo n.º 5
0
 def run(self):
     isDefaultValueSet = False
     for v in self.values:
         type = v[2]
         if type in WINDOWS_INSTALLER_DOES_NOT_SUPPORT:
             # it is better to log any skipped registry values, 
             continue
         if v[0] == '':
             # this is the default value, its presense means it has a value set
             # because _winreg.EnumValue will skip all default values that do not have values set
             isDefaultValueSet = True
             name = ''
         else:
             name = v[0] 
         
         if type == _winreg.REG_BINARY:
             value =  registry_value_prefix_REG_BINARY + bin.hexlify(v[1])
         elif type == _winreg.REG_DWORD or type == _winreg.REG_DWORD_LITTLE_ENDIAN:
             value = registry_value_prefix_REG_DWORD + str(v[1])
         elif type == _winreg.REG_EXPAND_SZ:
             value = registry_value_prefix_REG_EXPAND_SZ + str(v[1])
         elif type == _winreg.REG_MULTI_SZ:
             value = "[~]".join(v[1])
             #If the value contains the sequence tilde [~], 
             #then the value is interpreted as a Null-delimited list of strings (REG_MULTI_SZ). 
             #For example, to specify a list containing the three strings a, b and c, use "a[~]b[~]c".
         else:
             value = v[1] 
         
         registry  = "reg" + msilib.gen_uuid()[1:-1]
         record = (registry, self.root, self.key, name, value, self.component) 
         yield record
         
     if not isDefaultValueSet:
         name = DefaultValueNameNotSet
         value = ""
         registry  = "reg" + msilib.gen_uuid()[1:-1]
         record = (registry, self.root, self.key, name, value, self.component)
         yield record
Exemplo n.º 6
0
 def __init__(self, platform, exefile, inifile, msifile, template=None):
     self.platform = platform
     self.exefile = ExeFileObj(exefile)
     self.inifile = IniFileObj(inifile)
     self.msifile = FileObj(msifile)
     if template == None:
         config = WpkgConfig.WpkgConfig()
         self.template = os.path.join(config.install_path, "MSI", "wpkg-gp_%s.msitemplate" % self.platform)
     else:
         self.template = template
     self.tempdir = tempfile.mkdtemp()
     self.productcode = msilib.gen_uuid()
     self.productversion = self.exefile.get_fileversion_as_string()
     self.manufacturer = "The Wpkg-GP team"
     self.package_GUID = "{" + msilib.UuidCreate().upper() + "}"
     self.product_GUID = "{" + msilib.UuidCreate().upper() + "}"
    def initialize_db(self):
        dirpath, filepath = os.path.split(self.package_file)
        if not os.path.exists(dirpath):
            os.makedirs(dirpath)
        if os.path.exists(self.package_file):
            os.unlink(self.package_file)
        print self.package_file

        if not self.author:
            author = "UNKNOWN"
        else:
            author = (isinstance(self.author, (list, tuple, set)) and " and ".join([x for x in self.author])) or str(self.author)

        product_name = "%s %s" % (self.package_name, self.package_version)

        self.db = msilib.init_database(self.package_file, msilib.schema,
                                       product_name, self.uuid or msilib.gen_uuid(),
                                       self.package_version, author)
        msilib.add_tables(self.db, msilib.sequence)
        props = [('DistVersion', self.package_version)]
        if self.email:
            props.append(("ARPCONTACT", self.email))
        if self.url:
            props.append(("ARPURLINFOABOUT", self.url))
        print 'install_location', self.install_location
        props.append(("TARGETDIR", self.install_location.replace('/', '\\')))
        if props:
            add_data(self.db, 'Property', props)

        # for some reason, we need to add our own error icon, so do that
        add_data(self.db, "Binary", [
            ("dlgerror.ico", msilib.Binary("./dialog-error.ico")),     # 22x22
            ])
        if self.bitmap:
            add_data(self.db, "Binary", [
                ("InstallerBitmap", msilib.Binary(self.bitmap)),     # 22x22
                ])            
        self.db.Commit()
Exemplo n.º 8
0
    def run(self):
        if not self.skip_build:
            self.run_command('build')

        install = self.reinitialize_command('install', reinit_subcommands=1)
        install.prefix = self.bdist_dir
        install.skip_build = self.skip_build
        install.warn_dir = 0

        install_lib = self.reinitialize_command('install_lib')
        # we do not want to include pyc or pyo files
        install_lib.compile = 0
        install_lib.optimize = 0

        if self.distribution.has_ext_modules():
            # If we are building an installer for a Python version other
            # than the one we are currently running, then we need to ensure
            # our build_lib reflects the other Python version rather than ours.
            # Note that for target_version!=sys.version, we must have skipped the
            # build step, so there is no issue with enforcing the build of this
            # version.
            target_version = self.target_version
            if not target_version:
                assert self.skip_build, "Should have already checked this"
                target_version = '%d.%d' % sys.version_info[:2]
            plat_specifier = ".%s-%s" % (self.plat_name, target_version)
            build = self.get_finalized_command('build')
            build.build_lib = os.path.join(build.build_base,
                                           'lib' + plat_specifier)

        log.info("installing to %s", self.bdist_dir)
        install.ensure_finalized()

        # avoid warning of 'install_lib' about installing
        # into a directory not in sys.path
        sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB'))

        install.run()

        del sys.path[0]

        self.mkpath(self.dist_dir)
        fullname = self.distribution.get_fullname()
        installer_name = self.get_installer_filename(fullname)
        installer_name = os.path.abspath(installer_name)
        if os.path.exists(installer_name): os.unlink(installer_name)

        metadata = self.distribution.metadata
        author = metadata.author
        if not author:
            author = metadata.maintainer
        if not author:
            author = "UNKNOWN"
        version = metadata.get_version()
        # ProductVersion must be strictly numeric
        # XXX need to deal with prerelease versions
        sversion = "%d.%d.%d" % StrictVersion(version).version
        # Prefix ProductName with Python x.y, so that
        # it sorts together with the other Python packages
        # in Add-Remove-Programs (APR)
        fullname = self.distribution.get_fullname()
        if self.target_version:
            product_name = "Python %s %s" % (self.target_version, fullname)
        else:
            product_name = "Python %s" % (fullname)
        self.db = msilib.init_database(installer_name, schema,
                product_name, msilib.gen_uuid(),
                sversion, author)
        msilib.add_tables(self.db, sequence)
        props = [('DistVersion', version)]
        email = metadata.author_email or metadata.maintainer_email
        if email:
            props.append(("ARPCONTACT", email))
        if metadata.url:
            props.append(("ARPURLINFOABOUT", metadata.url))
        if props:
            add_data(self.db, 'Property', props)

        self.add_find_python()
        self.add_files()
        self.add_scripts()
        self.add_ui()
        self.db.Commit()

        if hasattr(self.distribution, 'dist_files'):
            tup = 'bdist_msi', self.target_version or 'any', fullname
            self.distribution.dist_files.append(tup)

        if not self.keep_temp:
            remove_tree(self.bdist_dir, dry_run=self.dry_run)
Exemplo n.º 9
0
 def run(self):
     if not self.skip_build:
         self.run_command("build")
     install = self.reinitialize_command("install", reinit_subcommands=1)
     install.prefix = self.bdist_dir
     install.skip_build = self.skip_build
     install.warn_dir = 0
     install_lib = self.reinitialize_command("install_lib")
     install_lib.compile = 0
     install_lib.optimize = 0
     if self.distribution.has_ext_modules():
         target_version = self.target_version
         if not target_version:
             if not self.skip_build:
                 raise AssertionError("Should have already checked this")
                 target_version = sys.version[0:3]
             plat_specifier = ".%s-%s" % (self.plat_name, target_version)
             build = self.get_finalized_command("build")
             build.build_lib = os.path.join(build.build_base, "lib" + plat_specifier)
         log.info("installing to %s", self.bdist_dir)
         install.ensure_finalized()
         sys.path.insert(0, os.path.join(self.bdist_dir, "PURELIB"))
         install.run()
         del sys.path[0]
         self.mkpath(self.dist_dir)
         fullname = self.distribution.get_fullname()
         installer_name = self.get_installer_filename(fullname)
         installer_name = os.path.abspath(installer_name)
         if os.path.exists(installer_name):
             os.unlink(installer_name)
         metadata = self.distribution.metadata
         author = metadata.author
         if not author:
             author = metadata.maintainer
         if not author:
             author = "UNKNOWN"
         version = metadata.get_version()
         sversion = "%d.%d.%d" % StrictVersion(version).version
         fullname = self.distribution.get_fullname()
         if self.target_version:
             product_name = "Python %s %s" % (self.target_version, fullname)
         else:
             product_name = "Python %s" % fullname
         self.db = msilib.init_database(installer_name, schema, product_name, msilib.gen_uuid(), sversion, author)
         msilib.add_tables(self.db, sequence)
         props = [("DistVersion", version)]
         email = metadata.author_email or metadata.maintainer_email
         if email:
             props.append(("ARPCONTACT", email))
         if metadata.url:
             props.append(("ARPURLINFOABOUT", metadata.url))
         if props:
             add_data(self.db, "Property", props)
         self.add_find_python()
         self.add_files()
         self.add_scripts()
         self.add_ui()
         self.db.Commit()
         if hasattr(self.distribution, "dist_files"):
             tup = ("bdist_msi", self.target_version or "any", fullname)
             self.distribution.dist_files.append(tup)
         self.keep_temp or remove_tree(self.bdist_dir, dry_run=self.dry_run)
Exemplo n.º 10
0
# -*- coding: utf-8 -*-
"""
Created on May 20, 2014

@author: Diana
"""
import msilib

import requests
from cx_Freeze import Executable, setup

import Inno

base = None

GUID = msilib.gen_uuid()

# FOFF
# noinspection PyPep8
shortcut_table = [
    ("DesktopShortcut",  # Shortcut
     "DesktopFolder",  # Directory_
     "Trade Currency Bot",  # Name
     "TARGETDIR",  # Component_
     "[TARGETDIR]TCBot.exe",  # Target
     None,  # Arguments
     None,  # Description
     None,  # Hotkey
     None,  # Icon
     None,  # IconIndex
     None,  # ShowCmd
Exemplo n.º 11
0
from lxml import etree
import msilib

version = '1.2.3'
out = 'machination-core-extras.wsx'

wsx = etree.parse('packaging/machination-core-extras-template.xml')
top = wsx.getroot()

for elt in top.iter(tag=etree.Element):
    for att in elt.attrib:
        if elt.get(att) == 'REP-VERSION': elt.set(att, version)
        if elt.get(att) == 'REP-GUID': elt.set(att, msilib.gen_uuid())

with open(out, "w") as f:
    f.write(etree.tostring(wsx).decode())
Exemplo n.º 12
0
here = path.abspath(path.dirname(__file__))

# Get the long description from the README file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

# Dependencies are automatically detected, but it might need fine tuning.

#中文需要显式用gbk方式编码
product_name = parameters.appName.encode('gbk')
unproduct_name = (parameters.strUninstallApp).encode('gbk')
product_desc = (parameters.appName+" V"+str(helpAbout.versionMajor)+"."+str(helpAbout.versionMinor)).encode("gbk")

#uuid叫通用唯一识别码,后面再卸载快捷方式中要用到
product_code = msilib.gen_uuid()
#主程序手动命名
target_name= 'comtool.exe'


build_exe_options = {
    "include_files":["COMToolData","README.MD","LICENSE"],    
    #包含外围的ini、jpg文件,以及data目录下所有文件,以上所有的文件路径都是相对于cxsetup.py的路径。
    "packages": [],                #包含用到的包
    "includes": [], 
    "excludes": ["unittest"],                #提出wx里tkinter包
    "path": sys.path,                       #指定上述的寻找路径
    #  "icon": "COMToolData/assets/logo.ico"                        #指定ico文件
};

#快捷方式表,这里定义了三个快捷方式
Exemplo n.º 13
0
            os.remove('build/exe.win32-2.7/msvcp90.dll')
            # remove numpy tests that can be left out (some seem needed)
            for module in [
                    'distutils', 'setuptools', 'pydoc_data', 'numpy/core/tests', 'numpy/lib/tests',
                    'numpy/f2py/tests', 'numpy/distutils', 'numpy/doc',]:
                try:
                    shutil.rmtree('build/exe.win32-2.7/lib/%s' % module)
                except EnvironmentError:
                    pass


    SETUP_OPTIONS['cmdclass']['build_exe'] = BuildExeCommand

    numversion = '.'.join(v for v in VERSION.encode('ascii').split('.') if v.isdigit())
    UPGRADE_CODE = '{714d23a9-aa94-4b17-87a5-90e72d0c5b8f}'
    PRODUCT_CODE = msilib.gen_uuid()

    # these must be bytes for cx_Freeze bdist_msi
    SETUP_OPTIONS['name'] = NAME.encode('ascii')
    SETUP_OPTIONS['author'] = AUTHOR.encode('ascii')
    SETUP_OPTIONS['version'] = numversion

    # compile separately, as they end up in the wrong place anyway
    SETUP_OPTIONS['ext_modules'] = []

    directory_table = [
        (
            'StartMenuFolder',
            'TARGETDIR',
            '.',
        ),
Exemplo n.º 14
0
def make_worker_msi(basedir, wname):

    logging.info('making msi for {} in {}'.format(wname, basedir))
    wixdir = r'c:\Program Files (x86)\Windows Installer XML v3.6\bin'
    candle = os.path.join(wixdir, 'candle.exe')
    light = os.path.join(wixdir, 'light.exe')
    version = get_git_version()
    pname = 'machination-client-worker-' + wname
    fullname = 'Python {}-{}'.format(pname, version)
    out = 'build\\{}-{}.wsx'.format(pname, version)
    wsx = etree.parse('packaging/machination-client-worker-template.xml')
    top = wsx.getroot()

    # Change 'macros'
    for elt in top.iter(tag=etree.Element):
        for att in elt.attrib:
            if elt.get(att) == 'REP-WORKERNAME': elt.set(att, wname)
            if elt.get(att) == 'REP-FULLNAME': elt.set(att, fullname)
            if elt.get(att) == 'REP-VERSION': elt.set(att, version)
            if elt.get(att) == 'REP-GUID': elt.set(att, msilib.gen_uuid())

    # Add files
    nsmap = {'w': 'http://schemas.microsoft.com/wix/2006/wi'}
    wdref_elt = top.xpath('//w:DirectoryRef[@Id="THEWORKERDIR"]', namespaces = nsmap)[0]
    feature_elt = top.xpath('//w:Feature[@Id="MachWorker"]', namespaces = nsmap)[0]
    wdir = basedir + '\\' + wname
    for thing in os.listdir(wdir):
        # exceptions
        if thing in ('__pychache__'):
            continue
        if os.path.isdir(wdir + '\\' + thing):
            logging.warning('Found a directory: ' + thing)
        else:
            comp = etree.Element('Component', Id=make_id(thing), Guid=msilib.gen_uuid())
            comp.append(
                etree.Element(
                    'File',
                    Id=make_id(thing),
                    Source='{}\\{}'.format(wdir, thing)
                    )
                )
            wdref_elt.append(comp)
            feature_elt.append(etree.Element('ComponentRef', Id=make_id(thing)))

    # Write the source file out
    logging.info('Creating ' + out)
    with open(out, "w") as f:
        f.write(etree.tostring(wsx).decode())

    # compile
    subprocess.check_call(
        [candle,
         '-arch', 'x64',
         '-out', 'build\\{}-{}.wixobj'.format(pname, version),
         'build\\{}-{}.wsx'.format(pname, version)]
        )
    # link
    subprocess.check_call(
        [light,
         '-out', 'dist\\{}-{}.x64.msi'.format(pname, version),
         'build\\{}-{}.wixobj'.format(pname, version)]
        )
    # remove temporary file
    os.unlink('dist\\{}-{}.x64.wixpdb'.format(pname, version))