1
:mod:`msilib` --- Read and write Microsoft Installer files
2
==========================================================
6
:synopsis: Creation of Microsoft Installer files, and CAB files.
7
.. moduleauthor:: Martin v. Löwis <martin@v.loewis.de>
8
.. sectionauthor:: Martin v. Löwis <martin@v.loewis.de>
11
.. index:: single: msi
15
The :mod:`msilib` supports the creation of Microsoft Installer (``.msi``) files.
16
Because these files often contain an embedded "cabinet" file (``.cab``), it also
17
exposes an API to create CAB files. Support for reading ``.cab`` files is
18
currently not implemented; read support for the ``.msi`` database is possible.
20
This package aims to provide complete access to all tables in an ``.msi`` file,
21
therefore, it is a fairly low-level API. Two primary applications of this
22
package are the :mod:`distutils` command ``bdist_msi``, and the creation of
23
Python installer package itself (although that currently uses a different
24
version of ``msilib``).
26
The package contents can be roughly split into four parts: low-level CAB
27
routines, low-level MSI routines, higher-level MSI routines, and standard table
31
.. function:: FCICreate(cabname, files)
33
Create a new CAB file named *cabname*. *files* must be a list of tuples, each
34
containing the name of the file on disk, and the name of the file inside the CAB
37
The files are added to the CAB file in the order they appear in the list. All
38
files are added into a single CAB file, using the MSZIP compression algorithm.
40
Callbacks to Python for the various steps of MSI creation are currently not
44
.. function:: UuidCreate()
46
Return the string representation of a new unique identifier. This wraps the
47
Windows API functions :c:func:`UuidCreate` and :c:func:`UuidToString`.
50
.. function:: OpenDatabase(path, persist)
52
Return a new database object by calling MsiOpenDatabase. *path* is the file
53
name of the MSI file; *persist* can be one of the constants
54
``MSIDBOPEN_CREATEDIRECT``, ``MSIDBOPEN_CREATE``, ``MSIDBOPEN_DIRECT``,
55
``MSIDBOPEN_READONLY``, or ``MSIDBOPEN_TRANSACT``, and may include the flag
56
``MSIDBOPEN_PATCHFILE``. See the Microsoft documentation for the meaning of
57
these flags; depending on the flags, an existing database is opened, or a new
61
.. function:: CreateRecord(count)
63
Return a new record object by calling :c:func:`MSICreateRecord`. *count* is the
64
number of fields of the record.
67
.. function:: init_database(name, schema, ProductName, ProductCode, ProductVersion, Manufacturer)
69
Create and return a new database *name*, initialize it with *schema*, and set
70
the properties *ProductName*, *ProductCode*, *ProductVersion*, and
73
*schema* must be a module object containing ``tables`` and
74
``_Validation_records`` attributes; typically, :mod:`msilib.schema` should be
77
The database will contain just the schema and the validation records when this
81
.. function:: add_data(database, table, records)
83
Add all *records* to the table named *table* in *database*.
85
The *table* argument must be one of the predefined tables in the MSI schema,
86
e.g. ``'Feature'``, ``'File'``, ``'Component'``, ``'Dialog'``, ``'Control'``,
89
*records* should be a list of tuples, each one containing all fields of a
90
record according to the schema of the table. For optional fields,
91
``None`` can be passed.
93
Field values can be int or long numbers, strings, or instances of the Binary
97
.. class:: Binary(filename)
99
Represents entries in the Binary table; inserting such an object using
100
:func:`add_data` reads the file named *filename* into the table.
103
.. function:: add_tables(database, module)
105
Add all table content from *module* to *database*. *module* must contain an
106
attribute *tables* listing all tables for which content should be added, and one
107
attribute per table that has the actual content.
109
This is typically used to install the sequence tables.
112
.. function:: add_stream(database, name, path)
114
Add the file *path* into the ``_Stream`` table of *database*, with the stream
118
.. function:: gen_uuid()
120
Return a new UUID, in the format that MSI typically requires (i.e. in curly
121
braces, and with all hexdigits in upper-case).
126
`FCICreateFile <https://msdn.microsoft.com/library?url=/library/en-us/devnotes/winprog/fcicreate.asp>`_
127
`UuidCreate <https://msdn.microsoft.com/library?url=/library/en-us/rpc/rpc/uuidcreate.asp>`_
128
`UuidToString <https://msdn.microsoft.com/library?url=/library/en-us/rpc/rpc/uuidtostring.asp>`_
130
.. _database-objects:
136
.. method:: Database.OpenView(sql)
138
Return a view object, by calling :c:func:`MSIDatabaseOpenView`. *sql* is the SQL
139
statement to execute.
142
.. method:: Database.Commit()
144
Commit the changes pending in the current transaction, by calling
145
:c:func:`MSIDatabaseCommit`.
148
.. method:: Database.GetSummaryInformation(count)
150
Return a new summary information object, by calling
151
:c:func:`MsiGetSummaryInformation`. *count* is the maximum number of updated
157
`MSIDatabaseOpenView <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msidatabaseopenview.asp>`_
158
`MSIDatabaseCommit <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msidatabasecommit.asp>`_
159
`MSIGetSummaryInformation <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msigetsummaryinformation.asp>`_
167
.. method:: View.Execute(params)
169
Execute the SQL query of the view, through :c:func:`MSIViewExecute`. If
170
*params* is not ``None``, it is a record describing actual values of the
171
parameter tokens in the query.
174
.. method:: View.GetColumnInfo(kind)
176
Return a record describing the columns of the view, through calling
177
:c:func:`MsiViewGetColumnInfo`. *kind* can be either ``MSICOLINFO_NAMES`` or
178
``MSICOLINFO_TYPES``.
181
.. method:: View.Fetch()
183
Return a result record of the query, through calling :c:func:`MsiViewFetch`.
186
.. method:: View.Modify(kind, data)
188
Modify the view, by calling :c:func:`MsiViewModify`. *kind* can be one of
189
``MSIMODIFY_SEEK``, ``MSIMODIFY_REFRESH``, ``MSIMODIFY_INSERT``,
190
``MSIMODIFY_UPDATE``, ``MSIMODIFY_ASSIGN``, ``MSIMODIFY_REPLACE``,
191
``MSIMODIFY_MERGE``, ``MSIMODIFY_DELETE``, ``MSIMODIFY_INSERT_TEMPORARY``,
192
``MSIMODIFY_VALIDATE``, ``MSIMODIFY_VALIDATE_NEW``,
193
``MSIMODIFY_VALIDATE_FIELD``, or ``MSIMODIFY_VALIDATE_DELETE``.
195
*data* must be a record describing the new data.
198
.. method:: View.Close()
200
Close the view, through :c:func:`MsiViewClose`.
205
`MsiViewExecute <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msiviewexecute.asp>`_
206
`MSIViewGetColumnInfo <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msiviewgetcolumninfo.asp>`_
207
`MsiViewFetch <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msiviewfetch.asp>`_
208
`MsiViewModify <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msiviewmodify.asp>`_
209
`MsiViewClose <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msiviewclose.asp>`_
213
Summary Information Objects
214
---------------------------
217
.. method:: SummaryInformation.GetProperty(field)
219
Return a property of the summary, through :c:func:`MsiSummaryInfoGetProperty`.
220
*field* is the name of the property, and can be one of the constants
221
``PID_CODEPAGE``, ``PID_TITLE``, ``PID_SUBJECT``, ``PID_AUTHOR``,
222
``PID_KEYWORDS``, ``PID_COMMENTS``, ``PID_TEMPLATE``, ``PID_LASTAUTHOR``,
223
``PID_REVNUMBER``, ``PID_LASTPRINTED``, ``PID_CREATE_DTM``,
224
``PID_LASTSAVE_DTM``, ``PID_PAGECOUNT``, ``PID_WORDCOUNT``, ``PID_CHARCOUNT``,
225
``PID_APPNAME``, or ``PID_SECURITY``.
228
.. method:: SummaryInformation.GetPropertyCount()
230
Return the number of summary properties, through
231
:c:func:`MsiSummaryInfoGetPropertyCount`.
234
.. method:: SummaryInformation.SetProperty(field, value)
236
Set a property through :c:func:`MsiSummaryInfoSetProperty`. *field* can have the
237
same values as in :meth:`GetProperty`, *value* is the new value of the property.
238
Possible value types are integer and string.
241
.. method:: SummaryInformation.Persist()
243
Write the modified properties to the summary information stream, using
244
:c:func:`MsiSummaryInfoPersist`.
249
`MsiSummaryInfoGetProperty <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msisummaryinfogetproperty.asp>`_
250
`MsiSummaryInfoGetPropertyCount <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msisummaryinfogetpropertycount.asp>`_
251
`MsiSummaryInfoSetProperty <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msisummaryinfosetproperty.asp>`_
252
`MsiSummaryInfoPersist <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msisummaryinfopersist.asp>`_
260
.. method:: Record.GetFieldCount()
262
Return the number of fields of the record, through
263
:c:func:`MsiRecordGetFieldCount`.
266
.. method:: Record.GetInteger(field)
268
Return the value of *field* as an integer where possible. *field* must
272
.. method:: Record.GetString(field)
274
Return the value of *field* as a string where possible. *field* must
278
.. method:: Record.SetString(field, value)
280
Set *field* to *value* through :c:func:`MsiRecordSetString`. *field* must be an
281
integer; *value* a string.
284
.. method:: Record.SetStream(field, value)
286
Set *field* to the contents of the file named *value*, through
287
:c:func:`MsiRecordSetStream`. *field* must be an integer; *value* a string.
290
.. method:: Record.SetInteger(field, value)
292
Set *field* to *value* through :c:func:`MsiRecordSetInteger`. Both *field* and
293
*value* must be an integer.
296
.. method:: Record.ClearData()
298
Set all fields of the record to 0, through :c:func:`MsiRecordClearData`.
303
`MsiRecordGetFieldCount <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msirecordgetfieldcount.asp>`_
304
`MsiRecordSetString <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msirecordsetstring.asp>`_
305
`MsiRecordSetStream <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msirecordsetstream.asp>`_
306
`MsiRecordSetInteger <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msirecordsetinteger.asp>`_
307
`MsiRecordClear <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/msirecordclear.asp>`_
314
All wrappers around MSI functions raise :exc:`MsiError`; the string inside the
315
exception will contain more detail.
326
The class :class:`CAB` represents a CAB file. During MSI construction, files
327
will be added simultaneously to the ``Files`` table, and to a CAB file. Then,
328
when all files have been added, the CAB file can be written, then added to the
331
*name* is the name of the CAB file in the MSI file.
334
.. method:: append(full, file, logical)
336
Add the file with the pathname *full* to the CAB file, under the name
337
*logical*. If there is already a file named *logical*, a new file name is
340
Return the index of the file in the CAB file, and the new name of the file
344
.. method:: commit(database)
346
Generate a CAB file, add it as a stream to the MSI file, put it into the
347
``Media`` table, and remove the generated file from the disk.
356
.. class:: Directory(database, cab, basedir, physical, logical, default, [componentflags])
358
Create a new directory in the Directory table. There is a current component at
359
each point in time for the directory, which is either explicitly created through
360
:meth:`start_component`, or implicitly when files are added for the first time.
361
Files are added into the current component, and into the cab file. To create a
362
directory, a base directory object needs to be specified (can be ``None``), the
363
path to the physical directory, and a logical directory name. *default*
364
specifies the DefaultDir slot in the directory table. *componentflags* specifies
365
the default flags that new components get.
368
.. method:: start_component([component[, feature[, flags[, keyfile[, uuid]]]]])
370
Add an entry to the Component table, and make this component the current
371
component for this directory. If no component name is given, the directory
372
name is used. If no *feature* is given, the current feature is used. If no
373
*flags* are given, the directory's default flags are used. If no *keyfile*
374
is given, the KeyPath is left null in the Component table.
377
.. method:: add_file(file[, src[, version[, language]]])
379
Add a file to the current component of the directory, starting a new one
380
if there is no current component. By default, the file name in the source
381
and the file table will be identical. If the *src* file is specified, it
382
is interpreted relative to the current directory. Optionally, a *version*
383
and a *language* can be specified for the entry in the File table.
386
.. method:: glob(pattern[, exclude])
388
Add a list of files to the current component as specified in the glob
389
pattern. Individual files can be excluded in the *exclude* list.
392
.. method:: remove_pyc()
394
Remove ``.pyc``/``.pyo`` files on uninstall.
399
`Directory Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/directory_table.asp>`_
400
`File Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/file_table.asp>`_
401
`Component Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/component_table.asp>`_
402
`FeatureComponents Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/featurecomponents_table.asp>`_
410
.. class:: Feature(database, id, title, desc, display[, level=1[, parent[, directory[, attributes=0]]]])
412
Add a new record to the ``Feature`` table, using the values *id*, *parent.id*,
413
*title*, *desc*, *display*, *level*, *directory*, and *attributes*. The
414
resulting feature object can be passed to the :meth:`start_component` method of
418
.. method:: set_current()
420
Make this feature the current feature of :mod:`msilib`. New components are
421
automatically added to the default feature, unless a feature is explicitly
427
`Feature Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/feature_table.asp>`_
434
:mod:`msilib` provides several classes that wrap the GUI tables in an MSI
435
database. However, no standard user interface is provided; use
436
:mod:`~distutils.command.bdist_msi` to create MSI files with a user-interface
437
for installing Python packages.
440
.. class:: Control(dlg, name)
442
Base class of the dialog controls. *dlg* is the dialog object the control
443
belongs to, and *name* is the control's name.
446
.. method:: event(event, argument[, condition=1[, ordering]])
448
Make an entry into the ``ControlEvent`` table for this control.
451
.. method:: mapping(event, attribute)
453
Make an entry into the ``EventMapping`` table for this control.
456
.. method:: condition(action, condition)
458
Make an entry into the ``ControlCondition`` table for this control.
461
.. class:: RadioButtonGroup(dlg, name, property)
463
Create a radio button control named *name*. *property* is the installer property
464
that gets set when a radio button is selected.
467
.. method:: add(name, x, y, width, height, text [, value])
469
Add a radio button named *name* to the group, at the coordinates *x*, *y*,
470
*width*, *height*, and with the label *text*. If *value* is omitted, it
474
.. class:: Dialog(db, name, x, y, w, h, attr, title, first, default, cancel)
476
Return a new :class:`Dialog` object. An entry in the ``Dialog`` table is made,
477
with the specified coordinates, dialog attributes, title, name of the first,
478
default, and cancel controls.
481
.. method:: control(name, type, x, y, width, height, attributes, property, text, control_next, help)
483
Return a new :class:`Control` object. An entry in the ``Control`` table is
484
made with the specified parameters.
486
This is a generic method; for specific types, specialized methods are
490
.. method:: text(name, x, y, width, height, attributes, text)
492
Add and return a ``Text`` control.
495
.. method:: bitmap(name, x, y, width, height, text)
497
Add and return a ``Bitmap`` control.
500
.. method:: line(name, x, y, width, height)
502
Add and return a ``Line`` control.
505
.. method:: pushbutton(name, x, y, width, height, attributes, text, next_control)
507
Add and return a ``PushButton`` control.
510
.. method:: radiogroup(name, x, y, width, height, attributes, property, text, next_control)
512
Add and return a ``RadioButtonGroup`` control.
515
.. method:: checkbox(name, x, y, width, height, attributes, property, text, next_control)
517
Add and return a ``CheckBox`` control.
522
`Dialog Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/dialog_table.asp>`_
523
`Control Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/control_table.asp>`_
524
`Control Types <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/controls.asp>`_
525
`ControlCondition Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/controlcondition_table.asp>`_
526
`ControlEvent Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/controlevent_table.asp>`_
527
`EventMapping Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/eventmapping_table.asp>`_
528
`RadioButton Table <https://msdn.microsoft.com/library?url=/library/en-us/msi/setup/radiobutton_table.asp>`_
535
:mod:`msilib` provides a few subpackages that contain only schema and table
536
definitions. Currently, these definitions are based on MSI version 2.0.
541
This is the standard MSI schema for MSI 2.0, with the *tables* variable
542
providing a list of table definitions, and *_Validation_records* providing the
543
data for MSI validation.
548
This module contains table contents for the standard sequence tables:
549
*AdminExecuteSequence*, *AdminUISequence*, *AdvtExecuteSequence*,
550
*InstallExecuteSequence*, and *InstallUISequence*.
555
This module contains definitions for the UIText and ActionText tables, for the
556
standard installer actions.