1
  ,   ˆl–Ým_JJh¥ ² ¸È®41hßÁ„ì¾ß_‡I|¥ŠèªÁÀ ?÷     :mod:`msilib` --- Read and write Microsoft Installer files
==========================================================

.. module:: msilib
   :platform: Windows
   :synopsis: Creation of Microsoft Installer files, and CAB files.
.. moduleauthor:: Martin v. LÃ¶wis <martin@v.loewis.de>
.. sectionauthor:: Martin v. LÃ¶wis <martin@v.loewis.de>


.. index:: single: msi

.. versionadded:: 2.5

The :mod:`msilib` supports the creation of Microsoft Installer (``.msi``) files.
Because these files often contain an embedded "cabinet" file (``.cab``), it also
exposes an API to create CAB files. Support for reading ``.cab`` files is
currently not implemented; read support for the ``.msi`` database is possible.

This package aims to provide complete access to all tables in an ``.msi`` file,
therefore, it is a fairly low-level API. Two primary applications of this
package are the :mod:`distutils` command ``bdist_msi``, and the creation of
Python installer package itself (although that currently uses a different
version of ``msilib``).

The package contents can be roughly split into four parts: low-level CAB
routines, low-level MSI routines, higher-level MSI routines, and standard table
structures.


.. function:: FCICreate(cabname, files)

   Create a new CAB file named *cabname*. *files* must be a list of tuples, each
   containing the name of the file on disk, and the name of the file inside the CAB
   file.

   The files are added to the CAB file in the order they appear in the list. All
   files are added into a single CAB file, using the MSZIP compression algorithm.

   Callbacks to Python for the various steps of MSI creation are currently not
   exposed.


.. function:: UuidCreate()

   Return the string representation of a new unique identifier. This wraps the
   Windows API functions :c:func:`UuidCreate` and :c:func:`UuidToString`.


.. function:: OpenDatabase(path, persist)

   Return a new database object by calling MsiOpenDatabase.   *path* is the file
   name of the MSI file; *persist* can be one of the constants
   ``MSIDBOPEN_CREATEDIRECT``, ``MSIDBOPEN_CREATE``, ``MSIDBOPEN_DIRECT``,
   ``MSIDBOPEN_READONLY``, or ``MSIDBOPEN_TRANSACT``, and may include the flag
   ``MSIDBOPEN_PATCHFILE``. See the Microsoft documentation for the meaning of
   these flags; depending on the flags, an existing database is opened, or a new
   one created.


.. function:: CreateRecord(count)

   Return a new record object by calling :c:func:`MSICreateRecord`. *count* is the
   number of fields of the record.


.. function:: init_database(name, schema, ProductName, ProductCode, ProductVersion, Manufacturer)

   Create and return a new database *name*, initialize it with *schema*, and set
   the properties *ProductName*, *ProductCode*, *ProductVersion*, and
   *Manufacturer*.

   *schema* must be a module object containing ``tables`` and
   ``_Validation_records`` attributes; typically, :mod:`msilib.schema` should be
   used.

   The database will contain just the schema and the validation records when this
   function returns.


.. function:: add_data(database, table, records)

   Add all *records* to the table named *table* in *database*.

   The *table* argument must be one of the predefined tables in the MSI schema,
   e.g. ``'Feature'``, ``'File'``, ``'Component'``, ``'Dialog'``, ``'Control'``,
   etc.

   *records* should be a list of tuples, each one containing all fields of a
   record according to the schema of the table.  For optional fields,
   ``None`` can be passed.

   Field values can be int or long numbers, strings, or instances of the Binary
   class.


.. class:: Binary(filename)

   Represents entries in the Binary table; inserting such an object using
   :func:`add_data` reads the file named *filename* into the table.


.. function:: add_tables(database, module)

   Add all table content from *module* to *database*. *module* must contain an
   attribute *tables* listing all tables for which content should be added, and one
   attribute per table that has the actua