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