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