msilib
— Read and write Microsoft Installer files读取和写入Microsoft Installer文件¶
Source code: Lib/msilib/__init__.py
Deprecated since version 3.11: 自3.11版起已弃用:The msilib
module is deprecated (see PEP 594 for details).msilib
模块已弃用(有关详细信息,请参阅PEP 594)。
The msilib
supports the creation of Microsoft Installer (.msi
) files. msilib
支持创建Microsoft安装程序(.msi
)文件。Because these files often contain an embedded “cabinet” file (因为这些文件通常包含嵌入式“cab”文件(.cab
), it also exposes an API to create CAB files. .cab
),所以它还公开了创建cab文件的API。Support for reading 当前未实现对读取.cab
files is currently not implemented; read support for the .msi
database is possible..cab
文件的支持;.msi
数据库的读取支持是可能的。
This package aims to provide complete access to all tables in an 这个包旨在提供对.msi
file, therefore, it is a fairly low-level API. .msi
文件中所有表的完全访问,因此,它是一个相当低级的API。Two primary applications of this package are the 这个包的两个主要应用程序是distutils
command bdist_msi
, and the creation of Python installer package itself (although that currently uses a different version of msilib
).distutils
命令bdist_msi
,以及Python安装程序包本身的创建(尽管目前使用不同版本的msilib
)。
The package contents can be roughly split into four parts: low-level CAB routines, low-level MSI routines, higher-level MSI routines, and standard table structures.包的内容可以大致分为四个部分:低级CAB例程、低级MSI例程、高级MSI例程和标准表结构。
-
msilib.
FCICreate
(cabname, files)¶ Create a new CAB file named cabname.创建名为cabname的新CAB文件。filesmust be a list of tuples, each containing the name of the file on disk, and the name of the file inside the CAB file.必须是一个元组列表,每个元组包含磁盘上文件的名称以及CAB文件中文件的名称。The files are added to the CAB file in the order they appear in the list.文件将按照列表中显示的顺序添加到CAB文件中。All files are added into a single CAB file, using the MSZIP compression algorithm.使用MSZIP压缩算法将所有文件添加到单个CAB文件中。Callbacks to Python for the various steps of MSI creation are currently not exposed.MSI创建的各个步骤对Python的回调目前尚未公开。
-
msilib.
UuidCreate
()¶ Return the string representation of a new unique identifier.返回新的唯一标识符的字符串表示形式。This wraps the Windows API functions这包装了Windows API函数UuidCreate()
andUuidToString()
.UuidCreate()
和UuidToString()
。
-
msilib.
OpenDatabase
(path, persist)¶ Return a new database object by calling MsiOpenDatabase.通过调用MsiOpenDatabase返回新的数据库对象。path is the file name of the MSI file; persist can be one of the constantspath是MSI文件的文件名;persistent可以是常量MSIDBOPEN_CREATEDIRECT
,MSIDBOPEN_CREATE
,MSIDBOPEN_DIRECT
,MSIDBOPEN_READONLY
, orMSIDBOPEN_TRANSACT
, and may include the flagMSIDBOPEN_PATCHFILE
.MSIDBOPEN_CREATEDIRECT
、MSIDBOPEN_CREATE
、MSIDBOPEN DIRECT
、MSIDBOPEN_READONLY
或MSIDBOPEN_TRANSACT
之一,并且可以包括标志MSIDBOPEN-PATCHFILE
。See the Microsoft documentation for the meaning of these flags; depending on the flags, an existing database is opened, or a new one created.有关这些标志的含义,请参阅Microsoft文档;根据标志,将打开现有数据库或创建新数据库。
-
msilib.
CreateRecord
(count)¶ Return a new record object by calling通过调用MSICreateRecord()
.MSICreateRecord()
返回新的记录对象。count is the number of fields of the record.count是记录的字段数。
-
msilib.
init_database
(name, schema, ProductName, ProductCode, ProductVersion, Manufacturer)¶ Create and return a new database name, initialize it with schema, and set the properties ProductName, ProductCode, ProductVersion, and Manufacturer.创建并返回新的数据库name,使用schema对其进行初始化,并设置财产ProductName、ProductCode、ProductVersion和Manufacturer。schema must be a module object containingschema必须是包含表和tables
and_Validation_records
attributes; typically,msilib.schema
should be used._Validation_records
属性的模块对象;通常应使用msilib.schema
。The database will contain just the schema and the validation records when this function returns.当此函数返回时,数据库将仅包含模式和验证记录。
-
msilib.
add_data
(database, table, records)¶ Add all records to the table named table in database.将所有records添加到database中名为table的表中。The table argument must be one of the predefined tables in the MSI schema, e.g.table参数必须是MSI架构中预定义的表之一,例如'Feature'
,'File'
,'Component'
,'Dialog'
,'Control'
, etc.'Feature'
、'File'
、'Component'
、'Dialog'
、'Control'
等。records
should be a list of tuples, each one containing all fields of a record according to the schema of the table.应该是一个元组列表,每个元组根据表的模式包含记录的所有字段。For optional fields,对于可选字段,可以传递None
can be passed.None
。Field values can be ints, strings, or instances of the Binary class.字段值可以是int、字符串或Binary类的实例。
-
class
msilib.
Binary
(filename)¶ Represents entries in the Binary table; inserting such an object using表示二进制表中的条目;使用add_data()
reads the file named filename into the table.add_data()
插入这样的对象会将名为filename的文件读取到表中。
-
msilib.
add_tables
(database, module)¶ Add all table content from module to database.将module中的所有表内容添加到database中。module must contain an attribute tables listing all tables for which content should be added, and one attribute per table that has the actual content.module必须包含一个属性tables,列出应为其添加内容的所有表,以及每个具有实际内容的表的一个属性。This is typically used to install the sequence tables.这通常用于安装序列表。
-
msilib.
add_stream
(database, name, path)¶ Add the file path into the使用流名称name将文件path添加到database的_Stream
table of database, with the stream name name._Stream
表中。
-
msilib.
gen_uuid
()¶ Return a new UUID, in the format that MSI typically requires (i.e. in curly braces, and with all hexdigits in upper-case).返回一个新的UUID,格式为MSI通常要求的格式(即大括号,所有十六进制数字均为大写)。
See also
Database Objects数据库对象¶
-
Database.
OpenView
(sql)¶ Return a view object, by calling通过调用MSIDatabaseOpenView()
.MSIDatabaseOpenView()
返回视图对象。sql is the SQL statement to execute.sql是要执行的sql语句。
-
Database.
Commit
()¶ Commit the changes pending in the current transaction, by calling通过调用MSIDatabaseCommit()
.MSIDatabaseCommit()
,提交当前事务中挂起的更改。
-
Database.
GetSummaryInformation
(count)¶ Return a new summary information object, by calling通过调用MsiGetSummaryInformation()
.MsiGetSummaryInformation()
返回新的摘要信息对象。countis the maximum number of updated values.是更新值的最大数量。
-
Database.
Close
()¶ Close the database object, through通过MsiCloseHandle()
.MsiCloseHandle()
关闭数据库对象。New in version 3.7.版本3.7中新增。
View Objects¶
-
View.
Execute
(params)¶ Execute the SQL query of the view, through通过MSIViewExecute()
.MSIViewExecute()
执行视图的SQL查询。If params is not如果params不是None
, it is a record describing actual values of the parameter tokens in the query.None
,则它是描述查询中参数标记的实际值的记录。
-
View.
GetColumnInfo
(kind)¶ Return a record describing the columns of the view, through calling通过调用MsiViewGetColumnInfo()
.MsiViewGetColumnInfo()
返回描述视图列的记录。kind can be eitherkind可以是MSICOLINFO_NAMES
orMSICOLINFO_TYPES
.MSICOLINFO_NAMES
或MSICOLINFO_TYPE
。
-
View.
Fetch
()¶ Return a result record of the query, through calling通过调用MsiViewFetch()
.MsiViewFetch()
返回查询的结果记录。
-
View.
Modify
(kind, data)¶ Modify the view, by calling
MsiViewModify()
. kind can be one ofMSIMODIFY_SEEK
,MSIMODIFY_REFRESH
,MSIMODIFY_INSERT
,MSIMODIFY_UPDATE
,MSIMODIFY_ASSIGN
,MSIMODIFY_REPLACE
,MSIMODIFY_MERGE
,MSIMODIFY_DELETE
,MSIMODIFY_INSERT_TEMPORARY
,MSIMODIFY_VALIDATE
,MSIMODIFY_VALIDATE_NEW
,MSIMODIFY_VALIDATE_FIELD
, orMSIMODIFY_VALIDATE_DELETE
.data
must be a record describing the new data.必须是描述新数据的记录。
-
View.
Close
()¶ Close the view, through通过MsiViewClose()
.MsiViewClose()
关闭视图。
Summary Information Objects摘要信息对象¶
-
SummaryInformation.
GetProperty
(field)¶ Return a property of the summary, through通过MsiSummaryInfoGetProperty()
.MsiSummaryInfoGetProperty()
返回摘要的属性。field is the name of the property, and can be one of the constantsPID_CODEPAGE
,PID_TITLE
,PID_SUBJECT
,PID_AUTHOR
,PID_KEYWORDS
,PID_COMMENTS
,PID_TEMPLATE
,PID_LASTAUTHOR
,PID_REVNUMBER
,PID_LASTPRINTED
,PID_CREATE_DTM
,PID_LASTSAVE_DTM
,PID_PAGECOUNT
,PID_WORDCOUNT
,PID_CHARCOUNT
,PID_APPNAME
, orPID_SECURITY
.
-
SummaryInformation.
GetPropertyCount
()¶ Return the number of summary properties, through通过MsiSummaryInfoGetPropertyCount()
.MsiSummaryInfoGetPropertyCount()
返回摘要属性的数量。
-
SummaryInformation.
SetProperty
(field, value)¶ Set a property through通过MsiSummaryInfoSetProperty()
.MsiSummaryInfoSetProperty()
设置属性。field can have the same values as in字段可以具有与GetProperty()
, value is the new value of the property.GetProperty()
中相同的值,value是属性的新值。Possible value types are integer and string.可能的值类型有整数和字符串。
-
SummaryInformation.
Persist
()¶ Write the modified properties to the summary information stream, using使用MsiSummaryInfoPersist()
.MsiSummaryInfoPersist()
将修改后的财产写入摘要信息流。
Record Objects¶
-
Record.
GetFieldCount
()¶ Return the number of fields of the record, through
MsiRecordGetFieldCount()
.
-
Record.
GetInteger
(field)¶ Return the value of field as an integer where possible. field must be an integer.
-
Record.
GetString
(field)¶ Return the value of field as a string where possible. field must be an integer.
-
Record.
SetString
(field, value)¶ Set field to value through
MsiRecordSetString()
. field must be an integer; value a string.
-
Record.
SetStream
(field, value)¶ Set field to the contents of the file named value, through
MsiRecordSetStream()
. field must be an integer; value a string.
-
Record.
SetInteger
(field, value)¶ Set field to value through
MsiRecordSetInteger()
. Both field and value must be an integer.
-
Record.
ClearData
()¶ Set all fields of the record to 0, through
MsiRecordClearData()
.
Errors¶
All wrappers around MSI functions raise MSIError
; the string inside the exception will contain more detail.
CAB Objects¶
-
class
msilib.
CAB
(name)¶ The class
CAB
represents a CAB file. During MSI construction, files will be added simultaneously to theFiles
table, and to a CAB file. Then, when all files have been added, the CAB file can be written, then added to the MSI file.name is the name of the CAB file in the MSI file.
-
append
(full, file, logical)¶ Add the file with the pathname full to the CAB file, under the name logical. If there is already a file named logical, a new file name is created.
Return the index of the file in the CAB file, and the new name of the file inside the CAB file.
-
commit
(database)¶ Generate a CAB file, add it as a stream to the MSI file, put it into the
Media
table, and remove the generated file from the disk.
-
Directory Objects¶
-
class
msilib.
Directory
(database, cab, basedir, physical, logical, default[, componentflags])¶ Create a new directory in the Directory table. There is a current component at each point in time for the directory, which is either explicitly created through
start_component()
, or implicitly when files are added for the first time. Files are added into the current component, and into the cab file. To create a directory, a base directory object needs to be specified (can beNone
), the path to the physical directory, and a logical directory name. default specifies the DefaultDir slot in the directory table. componentflags specifies the default flags that new components get.-
start_component
(component=None, feature=None, flags=None, keyfile=None, uuid=None)¶ Add an entry to the Component table, and make this component the current component for this directory. If no component name is given, the directory name is used. If no feature is given, the current feature is used. If no flags are given, the directory’s default flags are used. If no keyfile is given, the KeyPath is left null in the Component table.
-
add_file
(file, src=None, version=None, language=None)¶ Add a file to the current component of the directory, starting a new one if there is no current component. By default, the file name in the source and the file table will be identical. If the src file is specified, it is interpreted relative to the current directory. Optionally, a version and a language can be specified for the entry in the File table.
-
glob
(pattern, exclude=None)¶ Add a list of files to the current component as specified in the glob pattern. Individual files can be excluded in the exclude list.
-
remove_pyc
()¶ Remove
.pyc
files on uninstall.
-
Features¶
-
class
msilib.
Feature
(db, id, title, desc, display, level=1, parent=None, directory=None, attributes=0)¶ Add a new record to the
Feature
table, using the values id, parent.id, title, desc, display, level, directory, and attributes. The resulting feature object can be passed to thestart_component()
method ofDirectory
.
See also
GUI classes¶
msilib
provides several classes that wrap the GUI tables in an MSI database. However, no standard user interface is provided; use bdist_msi
to create MSI files with a user-interface for installing Python packages.
-
class
msilib.
Control
(dlg, name)¶ Base class of the dialog controls. dlg is the dialog object the control belongs to, and name is the control’s name.
-
event
(event, argument, condition=1, ordering=None)¶ Make an entry into the
ControlEvent
table for this control.
-
mapping
(event, attribute)¶ Make an entry into the
EventMapping
table for this control.
-
condition
(action, condition)¶ Make an entry into the
ControlCondition
table for this control.
-
-
class
msilib.
RadioButtonGroup
(dlg, name, property)¶ Create a radio button control named name. property is the installer property that gets set when a radio button is selected.
-
add
(name, x, y, width, height, text, value=None)¶ Add a radio button named name to the group, at the coordinates x, y, width, height, and with the label text. If value is
None
, it defaults to name.
-
-
class
msilib.
Dialog
(db, name, x, y, w, h, attr, title, first, default, cancel)¶ Return a new
Dialog
object. An entry in theDialog
table is made, with the specified coordinates, dialog attributes, title, name of the first, default, and cancel controls.-
control
(name, type, x, y, width, height, attributes, property, text, control_next, help)¶ Return a new
Control
object. An entry in theControl
table is made with the specified parameters.This is a generic method; for specific types, specialized methods are provided.
-
text
(name, x, y, width, height, attributes, text)¶ Add and return a
Text
control.
-
bitmap
(name, x, y, width, height, text)¶ Add and return a
Bitmap
control.
-
line
(name, x, y, width, height)¶ Add and return a
Line
control.
Add and return a
PushButton
control.
-
radiogroup
(name, x, y, width, height, attributes, property, text, next_control)¶ Add and return a
RadioButtonGroup
control.
-
checkbox
(name, x, y, width, height, attributes, property, text, next_control)¶ Add and return a
CheckBox
control.
-
Precomputed tables¶
msilib
provides a few subpackages that contain only schema and table definitions. Currently, these definitions are based on MSI version 2.0.
-
msilib.
schema
¶ This is the standard MSI schema for MSI 2.0, with the tables variable providing a list of table definitions, and _Validation_records providing the data for MSI validation.
-
msilib.
sequence
¶ This module contains table contents for the standard sequence tables: AdminExecuteSequence, AdminUISequence, AdvtExecuteSequence, InstallExecuteSequence, and InstallUISequence.
-
msilib.
text
¶ This module contains definitions for the UIText and ActionText tables, for the standard installer actions.