blob: 1c50d822f0b5fdb717870058d9976140bae1c9db [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`msilib` --- Read and write Microsoft Installer files
3==========================================================
4
5.. module:: msilib
6 :platform: Windows
7 :synopsis: Creation of Microsoft Installer files, and CAB files.
8.. moduleauthor:: Martin v. Löwis <martin@v.loewis.de>
9.. sectionauthor:: Martin v. Löwis <martin@v.loewis.de>
10
11
12.. index:: single: msi
13
Georg Brandl116aa622007-08-15 14:28:22 +000014The :mod:`msilib` supports the creation of Microsoft Installer (``.msi``) files.
15Because these files often contain an embedded "cabinet" file (``.cab``), it also
16exposes an API to create CAB files. Support for reading ``.cab`` files is
17currently not implemented; read support for the ``.msi`` database is possible.
18
19This package aims to provide complete access to all tables in an ``.msi`` file,
20therefore, it is a fairly low-level API. Two primary applications of this
21package are the :mod:`distutils` command ``bdist_msi``, and the creation of
22Python installer package itself (although that currently uses a different
23version of ``msilib``).
24
25The package contents can be roughly split into four parts: low-level CAB
26routines, low-level MSI routines, higher-level MSI routines, and standard table
27structures.
28
29
30.. function:: FCICreate(cabname, files)
31
32 Create a new CAB file named *cabname*. *files* must be a list of tuples, each
33 containing the name of the file on disk, and the name of the file inside the CAB
34 file.
35
36 The files are added to the CAB file in the order they appear in the list. All
37 files are added into a single CAB file, using the MSZIP compression algorithm.
38
39 Callbacks to Python for the various steps of MSI creation are currently not
40 exposed.
41
42
43.. function:: UUIDCreate()
44
45 Return the string representation of a new unique identifier. This wraps the
46 Windows API functions :cfunc:`UuidCreate` and :cfunc:`UuidToString`.
47
48
49.. function:: OpenDatabase(path, persist)
50
51 Return a new database object by calling MsiOpenDatabase. *path* is the file
52 name of the MSI file; *persist* can be one of the constants
53 ``MSIDBOPEN_CREATEDIRECT``, ``MSIDBOPEN_CREATE``, ``MSIDBOPEN_DIRECT``,
54 ``MSIDBOPEN_READONLY``, or ``MSIDBOPEN_TRANSACT``, and may include the flag
55 ``MSIDBOPEN_PATCHFILE``. See the Microsoft documentation for the meaning of
56 these flags; depending on the flags, an existing database is opened, or a new
57 one created.
58
59
60.. function:: CreateRecord(count)
61
62 Return a new record object by calling :cfunc:`MSICreateRecord`. *count* is the
63 number of fields of the record.
64
65
66.. function:: init_database(name, schema, ProductName, ProductCode, ProductVersion, Manufacturer)
67
68 Create and return a new database *name*, initialize it with *schema*, and set
69 the properties *ProductName*, *ProductCode*, *ProductVersion*, and
70 *Manufacturer*.
71
72 *schema* must be a module object containing ``tables`` and
73 ``_Validation_records`` attributes; typically, :mod:`msilib.schema` should be
74 used.
75
76 The database will contain just the schema and the validation records when this
77 function returns.
78
79
80.. function:: add_data(database, records)
81
82 Add all *records* to *database*. *records* should be a list of tuples, each one
83 containing all fields of a record according to the schema of the table. For
84 optional fields, ``None`` can be passed.
85
Georg Brandl5c106642007-11-29 17:41:05 +000086 Field values can be integers, strings, or instances of the Binary class.
Georg Brandl116aa622007-08-15 14:28:22 +000087
88
89.. class:: Binary(filename)
90
91 Represents entries in the Binary table; inserting such an object using
92 :func:`add_data` reads the file named *filename* into the table.
93
94
95.. function:: add_tables(database, module)
96
97 Add all table content from *module* to *database*. *module* must contain an
98 attribute *tables* listing all tables for which content should be added, and one
99 attribute per table that has the actual content.
100
101 This is typically used to install the sequence tables.
102
103
104.. function:: add_stream(database, name, path)
105
106 Add the file *path* into the ``_Stream`` table of *database*, with the stream
107 name *name*.
108
109
110.. function:: gen_uuid()
111
112 Return a new UUID, in the format that MSI typically requires (i.e. in curly
113 braces, and with all hexdigits in upper-case).
114
115
116.. seealso::
117
118 `FCICreateFile <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devnotes/winprog/fcicreate.asp>`_
119 `UuidCreate <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/uuidcreate.asp>`_
120 `UuidToString <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/uuidtostring.asp>`_
121
122.. _database-objects:
123
124Database Objects
125----------------
126
127
128.. method:: Database.OpenView(sql)
129
130 Return a view object, by calling :cfunc:`MSIDatabaseOpenView`. *sql* is the SQL
131 statement to execute.
132
133
134.. method:: Database.Commit()
135
136 Commit the changes pending in the current transaction, by calling
137 :cfunc:`MSIDatabaseCommit`.
138
139
140.. method:: Database.GetSummaryInformation(count)
141
142 Return a new summary information object, by calling
143 :cfunc:`MsiGetSummaryInformation`. *count* is the maximum number of updated
144 values.
145
146
147.. seealso::
148
149 `MSIOpenView <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiopenview.asp>`_
150 `MSIDatabaseCommit <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msidatabasecommit.asp>`_
151 `MSIGetSummaryInformation <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msigetsummaryinformation.asp>`_
152
153.. _view-objects:
154
155View Objects
156------------
157
158
159.. method:: View.Execute([params=None])
160
161 Execute the SQL query of the view, through :cfunc:`MSIViewExecute`. *params* is
162 an optional record describing actual values of the parameter tokens in the
163 query.
164
165
166.. method:: View.GetColumnInfo(kind)
167
168 Return a record describing the columns of the view, through calling
169 :cfunc:`MsiViewGetColumnInfo`. *kind* can be either ``MSICOLINFO_NAMES`` or
170 ``MSICOLINFO_TYPES``.
171
172
173.. method:: View.Fetch()
174
175 Return a result record of the query, through calling :cfunc:`MsiViewFetch`.
176
177
178.. method:: View.Modify(kind, data)
179
180 Modify the view, by calling :cfunc:`MsiViewModify`. *kind* can be one of
181 ``MSIMODIFY_SEEK``, ``MSIMODIFY_REFRESH``, ``MSIMODIFY_INSERT``,
182 ``MSIMODIFY_UPDATE``, ``MSIMODIFY_ASSIGN``, ``MSIMODIFY_REPLACE``,
183 ``MSIMODIFY_MERGE``, ``MSIMODIFY_DELETE``, ``MSIMODIFY_INSERT_TEMPORARY``,
184 ``MSIMODIFY_VALIDATE``, ``MSIMODIFY_VALIDATE_NEW``,
185 ``MSIMODIFY_VALIDATE_FIELD``, or ``MSIMODIFY_VALIDATE_DELETE``.
186
187 *data* must be a record describing the new data.
188
189
190.. method:: View.Close()
191
192 Close the view, through :cfunc:`MsiViewClose`.
193
194
195.. seealso::
196
197 `MsiViewExecute <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiviewexecute.asp>`_
198 `MSIViewGetColumnInfo <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiviewgetcolumninfo.asp>`_
199 `MsiViewFetch <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiviewfetch.asp>`_
200 `MsiViewModify <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiviewmodify.asp>`_
201 `MsiViewClose <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiviewclose.asp>`_
202
203.. _summary-objects:
204
205Summary Information Objects
206---------------------------
207
208
209.. method:: SummaryInformation.GetProperty(field)
210
211 Return a property of the summary, through :cfunc:`MsiSummaryInfoGetProperty`.
212 *field* is the name of the property, and can be one of the constants
213 ``PID_CODEPAGE``, ``PID_TITLE``, ``PID_SUBJECT``, ``PID_AUTHOR``,
214 ``PID_KEYWORDS``, ``PID_COMMENTS``, ``PID_TEMPLATE``, ``PID_LASTAUTHOR``,
215 ``PID_REVNUMBER``, ``PID_LASTPRINTED``, ``PID_CREATE_DTM``,
216 ``PID_LASTSAVE_DTM``, ``PID_PAGECOUNT``, ``PID_WORDCOUNT``, ``PID_CHARCOUNT``,
217 ``PID_APPNAME``, or ``PID_SECURITY``.
218
219
220.. method:: SummaryInformation.GetPropertyCount()
221
222 Return the number of summary properties, through
223 :cfunc:`MsiSummaryInfoGetPropertyCount`.
224
225
226.. method:: SummaryInformation.SetProperty(field, value)
227
228 Set a property through :cfunc:`MsiSummaryInfoSetProperty`. *field* can have the
229 same values as in :meth:`GetProperty`, *value* is the new value of the property.
230 Possible value types are integer and string.
231
232
233.. method:: SummaryInformation.Persist()
234
235 Write the modified properties to the summary information stream, using
236 :cfunc:`MsiSummaryInfoPersist`.
237
238
239.. seealso::
240
241 `MsiSummaryInfoGetProperty <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msisummaryinfogetproperty.asp>`_
242 `MsiSummaryInfoGetPropertyCount <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msisummaryinfogetpropertycount.asp>`_
243 `MsiSummaryInfoSetProperty <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msisummaryinfosetproperty.asp>`_
244 `MsiSummaryInfoPersist <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msisummaryinfopersist.asp>`_
245
246.. _record-objects:
247
248Record Objects
249--------------
250
251
252.. method:: Record.GetFieldCount()
253
254 Return the number of fields of the record, through
255 :cfunc:`MsiRecordGetFieldCount`.
256
257
258.. method:: Record.SetString(field, value)
259
260 Set *field* to *value* through :cfunc:`MsiRecordSetString`. *field* must be an
261 integer; *value* a string.
262
263
264.. method:: Record.SetStream(field, value)
265
266 Set *field* to the contents of the file named *value*, through
267 :cfunc:`MsiRecordSetStream`. *field* must be an integer; *value* a string.
268
269
270.. method:: Record.SetInteger(field, value)
271
272 Set *field* to *value* through :cfunc:`MsiRecordSetInteger`. Both *field* and
273 *value* must be an integer.
274
275
276.. method:: Record.ClearData()
277
278 Set all fields of the record to 0, through :cfunc:`MsiRecordClearData`.
279
280
281.. seealso::
282
283 `MsiRecordGetFieldCount <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msirecordgetfieldcount.asp>`_
284 `MsiRecordSetString <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msirecordsetstring.asp>`_
285 `MsiRecordSetStream <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msirecordsetstream.asp>`_
286 `MsiRecordSetInteger <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msirecordsetinteger.asp>`_
287 `MsiRecordClear <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msirecordclear.asp>`_
288
289.. _msi-errors:
290
291Errors
292------
293
294All wrappers around MSI functions raise :exc:`MsiError`; the string inside the
295exception will contain more detail.
296
297
298.. _cab:
299
300CAB Objects
301-----------
302
303
304.. class:: CAB(name)
305
306 The class :class:`CAB` represents a CAB file. During MSI construction, files
307 will be added simultaneously to the ``Files`` table, and to a CAB file. Then,
308 when all files have been added, the CAB file can be written, then added to the
309 MSI file.
310
311 *name* is the name of the CAB file in the MSI file.
312
313
314.. method:: CAB.append(full, file, logical)
315
316 Add the file with the pathname *full* to the CAB file, under the name *logical*.
317 If there is already a file named *logical*, a new file name is created.
318
319 Return the index of the file in the CAB file, and the new name of the file
320 inside the CAB file.
321
322
323.. method:: CAB.commit(database)
324
325 Generate a CAB file, add it as a stream to the MSI file, put it into the
326 ``Media`` table, and remove the generated file from the disk.
327
328
329.. _msi-directory:
330
331Directory Objects
332-----------------
333
334
335.. class:: Directory(database, cab, basedir, physical, logical, default, component, [componentflags])
336
337 Create a new directory in the Directory table. There is a current component at
338 each point in time for the directory, which is either explicitly created through
339 :meth:`start_component`, or implicitly when files are added for the first time.
340 Files are added into the current component, and into the cab file. To create a
341 directory, a base directory object needs to be specified (can be ``None``), the
342 path to the physical directory, and a logical directory name. *default*
343 specifies the DefaultDir slot in the directory table. *componentflags* specifies
344 the default flags that new components get.
345
346
347.. method:: Directory.start_component([component[, feature[, flags[, keyfile[, uuid]]]]])
348
349 Add an entry to the Component table, and make this component the current
350 component for this directory. If no component name is given, the directory name
351 is used. If no *feature* is given, the current feature is used. If no *flags*
352 are given, the directory's default flags are used. If no *keyfile* is given, the
353 KeyPath is left null in the Component table.
354
355
356.. method:: Directory.add_file(file[, src[, version[, language]]])
357
358 Add a file to the current component of the directory, starting a new one if
359 there is no current component. By default, the file name in the source and the
360 file table will be identical. If the *src* file is specified, it is interpreted
361 relative to the current directory. Optionally, a *version* and a *language* can
362 be specified for the entry in the File table.
363
364
365.. method:: Directory.glob(pattern[, exclude])
366
367 Add a list of files to the current component as specified in the glob pattern.
368 Individual files can be excluded in the *exclude* list.
369
370
371.. method:: Directory.remove_pyc()
372
373 Remove ``.pyc``/``.pyo`` files on uninstall.
374
375
376.. seealso::
377
378 `Directory Table <http://msdn.microsoft.com/library/en-us/msi/setup/directory_table.asp>`_
379 `File Table <http://msdn.microsoft.com/library/en-us/msi/setup/file_table.asp>`_
380 `Component Table <http://msdn.microsoft.com/library/en-us/msi/setup/component_table.asp>`_
381 `FeatureComponents Table <http://msdn.microsoft.com/library/en-us/msi/setup/featurecomponents_table.asp>`_
382
383.. _features:
384
385Features
386--------
387
388
389.. class:: Feature(database, id, title, desc, display[, level=1[, parent[, directory[, attributes=0]]]])
390
391 Add a new record to the ``Feature`` table, using the values *id*, *parent.id*,
392 *title*, *desc*, *display*, *level*, *directory*, and *attributes*. The
393 resulting feature object can be passed to the :meth:`start_component` method of
394 :class:`Directory`.
395
396
397.. method:: Feature.set_current()
398
399 Make this feature the current feature of :mod:`msilib`. New components are
400 automatically added to the default feature, unless a feature is explicitly
401 specified.
402
403
404.. seealso::
405
406 `Feature Table <http://msdn.microsoft.com/library/en-us/msi/setup/feature_table.asp>`_
407
408.. _msi-gui:
409
410GUI classes
411-----------
412
413:mod:`msilib` provides several classes that wrap the GUI tables in an MSI
414database. However, no standard user interface is provided; use :mod:`bdist_msi`
415to create MSI files with a user-interface for installing Python packages.
416
417
418.. class:: Control(dlg, name)
419
420 Base class of the dialog controls. *dlg* is the dialog object the control
421 belongs to, and *name* is the control's name.
422
423
424.. method:: Control.event(event, argument[, condition=1[, ordering]])
425
426 Make an entry into the ``ControlEvent`` table for this control.
427
428
429.. method:: Control.mapping(event, attribute)
430
431 Make an entry into the ``EventMapping`` table for this control.
432
433
434.. method:: Control.condition(action, condition)
435
436 Make an entry into the ``ControlCondition`` table for this control.
437
438
439.. class:: RadioButtonGroup(dlg, name, property)
440
441 Create a radio button control named *name*. *property* is the installer property
442 that gets set when a radio button is selected.
443
444
445.. method:: RadioButtonGroup.add(name, x, y, width, height, text [, value])
446
447 Add a radio button named *name* to the group, at the coordinates *x*, *y*,
448 *width*, *height*, and with the label *text*. If *value* is omitted, it defaults
449 to *name*.
450
451
452.. class:: Dialog(db, name, x, y, w, h, attr, title, first, default, cancel)
453
454 Return a new :class:`Dialog` object. An entry in the ``Dialog`` table is made,
455 with the specified coordinates, dialog attributes, title, name of the first,
456 default, and cancel controls.
457
458
459.. method:: Dialog.control(name, type, x, y, width, height, attributes, property, text, control_next, help)
460
461 Return a new :class:`Control` object. An entry in the ``Control`` table is made
462 with the specified parameters.
463
464 This is a generic method; for specific types, specialized methods are provided.
465
466
467.. method:: Dialog.text(name, x, y, width, height, attributes, text)
468
469 Add and return a ``Text`` control.
470
471
472.. method:: Dialog.bitmap(name, x, y, width, height, text)
473
474 Add and return a ``Bitmap`` control.
475
476
477.. method:: Dialog.line(name, x, y, width, height)
478
479 Add and return a ``Line`` control.
480
481
482.. method:: Dialog.pushbutton(name, x, y, width, height, attributes, text, next_control)
483
484 Add and return a ``PushButton`` control.
485
486
487.. method:: Dialog.radiogroup(name, x, y, width, height, attributes, property, text, next_control)
488
489 Add and return a ``RadioButtonGroup`` control.
490
491
492.. method:: Dialog.checkbox(name, x, y, width, height, attributes, property, text, next_control)
493
494 Add and return a ``CheckBox`` control.
495
496
497.. seealso::
498
499 `Dialog Table <http://msdn.microsoft.com/library/en-us/msi/setup/dialog_table.asp>`_
500 `Control Table <http://msdn.microsoft.com/library/en-us/msi/setup/control_table.asp>`_
501 `Control Types <http://msdn.microsoft.com/library/en-us/msi/setup/controls.asp>`_
502 `ControlCondition Table <http://msdn.microsoft.com/library/en-us/msi/setup/controlcondition_table.asp>`_
503 `ControlEvent Table <http://msdn.microsoft.com/library/en-us/msi/setup/controlevent_table.asp>`_
504 `EventMapping Table <http://msdn.microsoft.com/library/en-us/msi/setup/eventmapping_table.asp>`_
505 `RadioButton Table <http://msdn.microsoft.com/library/en-us/msi/setup/radiobutton_table.asp>`_
506
507.. _msi-tables:
508
509Precomputed tables
510------------------
511
512:mod:`msilib` provides a few subpackages that contain only schema and table
513definitions. Currently, these definitions are based on MSI version 2.0.
514
515
516.. data:: schema
517
518 This is the standard MSI schema for MSI 2.0, with the *tables* variable
519 providing a list of table definitions, and *_Validation_records* providing the
520 data for MSI validation.
521
522
523.. data:: sequence
524
525 This module contains table contents for the standard sequence tables:
526 *AdminExecuteSequence*, *AdminUISequence*, *AdvtExecuteSequence*,
527 *InstallExecuteSequence*, and *InstallUISequence*.
528
529
530.. data:: text
531
532 This module contains definitions for the UIText and ActionText tables, for the
533 standard installer actions.
534