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