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