Back to index

python3.2  3.2.2
Namespaces | Classes | Functions | Variables
msilib Namespace Reference

Namespaces

namespace  schema
namespace  sequence
namespace  text

Classes

class  Table
class  _Unspecified
class  CAB
class  Directory
class  Binary
class  Feature
class  Control
class  RadioButtonGroup
class  Dialog

Functions

def change_sequence
def add_data
def add_stream
def init_database
def add_tables
def make_id
def gen_uuid
def reset
def EnsureMSI
def EnsureMSM
def MakeInstaller
def MakeMerge2
def gen_schema
def gen_sequence
def init_database
def pe_type
def set_arch_from_file

Variables

string AMD64 = "AMD64"
string Itanium = "Itanium"
 Win64 = AMD64orItanium
int datasizemask = 0x00ff
int type_valid = 0x0100
int type_localizable = 0x0200
int typemask = 0x0c00
int type_long = 0x0000
int type_short = 0x0400
int type_string = 0x0c00
int type_binary = 0x0800
int type_nullable = 0x1000
int type_key = 0x2000
 knownbits = datasizemask|type_valid|type_localizable|\
tuple _directories = set()
tuple basestring = (str, unicode)
int PID_CODEPAGE = 1
int PID_TITLE = 2
int PID_SUBJECT = 3
int PID_AUTHOR = 4
int PID_KEYWORDS = 5
int PID_COMMENTS = 6
int PID_TEMPLATE = 7
int PID_LASTAUTHOR = 8
int PID_REVNUMBER = 9
int PID_LASTPRINTED = 11
int PID_CREATE_DTM = 12
int PID_LASTSAVE_DTM = 13
int PID_PAGECOUNT = 14
int PID_WORDCOUNT = 15
int PID_CHARCOUNT = 16
int PID_APPNAME = 18
int PID_SECURITY = 19

Class Documentation

class msilib::_Unspecified

Definition at line 82 of file __init__.py.


Function Documentation

def msilib.add_data (   db,
  table,
  values 
)

Definition at line 95 of file __init__.py.

00095 
00096 def add_data(db, table, values):
00097     v = db.OpenView("SELECT * FROM `%s`" % table)
00098     count = v.GetColumnInfo(MSICOLINFO_NAMES).GetFieldCount()
00099     r = CreateRecord(count)
00100     for value in values:
00101         assert len(value) == count, value
00102         for i in range(count):
00103             field = value[i]
00104             if isinstance(field, int):
00105                 r.SetInteger(i+1,field)
00106             elif isinstance(field, str):
00107                 r.SetString(i+1,field)
00108             elif field is None:
00109                 pass
00110             elif isinstance(field, Binary):
00111                 r.SetStream(i+1, field.name)
00112             else:
00113                 raise TypeError("Unsupported type %s" % field.__class__.__name__)
00114         try:
00115             v.Modify(MSIMODIFY_INSERT, r)
00116         except Exception as e:
00117             raise MSIError("Could not insert "+repr(values)+" into "+table)
00118 
00119         r.ClearData()
00120     v.Close()
00121 

Here is the caller graph for this function:

def msilib.add_stream (   db,
  name,
  path 
)

Definition at line 122 of file __init__.py.

00122 
00123 def add_stream(db, name, path):
00124     v = db.OpenView("INSERT INTO _Streams (Name, Data) VALUES ('%s', ?)" % name)
00125     r = CreateRecord(1)
00126     r.SetStream(1, path)
00127     v.Execute(r)
00128     v.Close()

Here is the call graph for this function:

Here is the caller graph for this function:

def msilib.add_tables (   db,
  module 
)

Definition at line 170 of file __init__.py.

00170 
00171 def add_tables(db, module):
00172     for table in module.tables:
00173         add_data(db, table, getattr(module, table))

Here is the call graph for this function:

Here is the caller graph for this function:

def msilib.change_sequence (   seq,
  action,
  seqno = _Unspecified,
  cond = _Unspecified 
)

Definition at line 83 of file __init__.py.

00083 
00084 def change_sequence(seq, action, seqno=_Unspecified, cond = _Unspecified):
00085     "Change the sequence number of an action in a sequence list"
00086     for i in range(len(seq)):
00087         if seq[i][0] == action:
00088             if cond is _Unspecified:
00089                 cond = seq[i][1]
00090             if seqno is _Unspecified:
00091                 seqno = seq[i][2]
00092             seq[i] = (action, cond, seqno)
00093             return
00094     raise ValueError("Action not found in sequence")

Here is the caller graph for this function:

Definition at line 55 of file msilib.py.

00055 
00056 def EnsureMSI():
00057     win32com.client.gencache.EnsureModule('{000C1092-0000-0000-C000-000000000046}', 1033, 1, 0)

Here is the caller graph for this function:

Definition at line 58 of file msilib.py.

00058 
00059 def EnsureMSM():
00060     try:
00061         win32com.client.gencache.EnsureModule('{0ADDA82F-2C26-11D2-AD65-00A0C9AF11A6}', 0, 1, 0)
00062     except pywintypes.com_error:
00063         win32com.client.gencache.EnsureModule('{0ADDA82F-2C26-11D2-AD65-00A0C9AF11A6}', 0, 2, 0)
00064 
_Installer=None

Here is the caller graph for this function:

def msilib.gen_schema (   destpath,
  schemapath 
)

Definition at line 142 of file msilib.py.

00142 
00143 def gen_schema(destpath, schemapath):
00144     d = MakeInstaller()
00145     schema = d.OpenDatabase(schemapath,
00146             win32com.client.constants.msiOpenDatabaseModeReadOnly)
00147 
00148     # XXX ORBER BY
00149     v=schema.OpenView("SELECT * FROM _Columns")
00150     curtable=None
00151     tables = []
00152     v.Execute(None)
00153     f = open(destpath, "wt")
00154     f.write("from msilib import Table\n")
00155     while 1:
00156         r=v.Fetch()
00157         if not r:break
00158         name=r.StringData(1)
00159         if curtable != name:
00160             f.write("\n%s = Table('%s')\n" % (name,name))
00161             curtable = name
00162             tables.append(name)
00163         f.write("%s.add_field(%d,'%s',%d)\n" %
00164                 (name, r.IntegerData(2), r.StringData(3), r.IntegerData(4)))
00165     v.Close()
00166 
00167     f.write("\ntables=[%s]\n\n" % (", ".join(tables)))
00168 
00169     # Fill the _Validation table
00170     f.write("_Validation_records = [\n")
00171     v = schema.OpenView("SELECT * FROM _Validation")
00172     v.Execute(None)
00173     while 1:
00174         r = v.Fetch()
00175         if not r:break
00176         # Table, Column, Nullable
00177         f.write("(%s,%s,%s," %
00178                 (`r.StringData(1)`, `r.StringData(2)`, `r.StringData(3)`))
00179         def put_int(i):
00180             if r.IsNull(i):f.write("None, ")
00181             else:f.write("%d," % r.IntegerData(i))
00182         def put_str(i):
00183             if r.IsNull(i):f.write("None, ")
00184             else:f.write("%s," % `r.StringData(i)`)
00185         put_int(4) # MinValue
00186         put_int(5) # MaxValue
00187         put_str(6) # KeyTable
00188         put_int(7) # KeyColumn
00189         put_str(8) # Category
00190         put_str(9) # Set
00191         put_str(10)# Description
00192         f.write("),\n")
00193     f.write("]\n\n")
00194 
00195     f.close()

Here is the call graph for this function:

def msilib.gen_sequence (   destpath,
  msipath 
)

Definition at line 196 of file msilib.py.

00196 
00197 def gen_sequence(destpath, msipath):
00198     dir = os.path.dirname(destpath)
00199     d = MakeInstaller()
00200     seqmsi = d.OpenDatabase(msipath,
00201             win32com.client.constants.msiOpenDatabaseModeReadOnly)
00202 
00203     v = seqmsi.OpenView("SELECT * FROM _Tables");
00204     v.Execute(None)
00205     f = open(destpath, "w")
00206     print >>f, "import msilib,os;dirname=os.path.dirname(__file__)"
00207     tables = []
00208     while 1:
00209         r = v.Fetch()
00210         if not r:break
00211         table = r.StringData(1)
00212         tables.append(table)
00213         f.write("%s = [\n" % table)
00214         v1 = seqmsi.OpenView("SELECT * FROM `%s`" % table)
00215         v1.Execute(None)
00216         info = v1.ColumnInfo(constants.msiColumnInfoTypes)
00217         while 1:
00218             r = v1.Fetch()
00219             if not r:break
00220             rec = []
00221             for i in range(1,r.FieldCount+1):
00222                 if r.IsNull(i):
00223                     rec.append(None)
00224                 elif info.StringData(i)[0] in "iI":
00225                     rec.append(r.IntegerData(i))
00226                 elif info.StringData(i)[0] in "slSL":
00227                     rec.append(r.StringData(i))
00228                 elif info.StringData(i)[0]=="v":
00229                     size = r.DataSize(i)
00230                     bytes = r.ReadStream(i, size, constants.msiReadStreamBytes)
00231                     bytes = bytes.encode("latin-1") # binary data represented "as-is"
00232                     if table == "Binary":
00233                         fname = rec[0]+".bin"
00234                         open(os.path.join(dir,fname),"wb").write(bytes)
00235                         rec.append(Binary(fname))
00236                     else:
00237                         rec.append(bytes)
00238                 else:
00239                     raise "Unsupported column type", info.StringData(i)
00240             f.write(repr(tuple(rec))+",\n")
00241         v1.Close()
00242         f.write("]\n\n")
00243     v.Close()
00244     f.write("tables=%s\n" % repr(map(str,tables)))
00245     f.close()

Here is the call graph for this function:

def msilib.gen_uuid ( )

Definition at line 182 of file __init__.py.

00182 
00183 def gen_uuid():
00184     return "{"+UuidCreate().upper()+"}"

Here is the caller graph for this function:

def msilib.init_database (   name,
  schema,
  ProductName,
  ProductCode,
  ProductVersion,
  Manufacturer 
)

Definition at line 131 of file __init__.py.

00131 
00132                   Manufacturer):
00133     try:
00134         os.unlink(name)
00135     except OSError:
00136         pass
00137     ProductCode = ProductCode.upper()
00138     # Create the database
00139     db = OpenDatabase(name, MSIDBOPEN_CREATE)
00140     # Create the tables
00141     for t in schema.tables:
00142         t.create(db)
00143     # Fill the validation table
00144     add_data(db, "_Validation", schema._Validation_records)
00145     # Initialize the summary information, allowing atmost 20 properties
00146     si = db.GetSummaryInformation(20)
00147     si.SetProperty(PID_TITLE, "Installation Database")
00148     si.SetProperty(PID_SUBJECT, ProductName)
00149     si.SetProperty(PID_AUTHOR, Manufacturer)
00150     if Itanium:
00151         si.SetProperty(PID_TEMPLATE, "Intel64;1033")
00152     elif AMD64:
00153         si.SetProperty(PID_TEMPLATE, "x64;1033")
00154     else:
00155         si.SetProperty(PID_TEMPLATE, "Intel;1033")
00156     si.SetProperty(PID_REVNUMBER, gen_uuid())
00157     si.SetProperty(PID_WORDCOUNT, 2) # long file names, compressed, original media
00158     si.SetProperty(PID_PAGECOUNT, 200)
00159     si.SetProperty(PID_APPNAME, "Python MSI Library")
00160     # XXX more properties
00161     si.Persist()
00162     add_data(db, "Property", [
00163         ("ProductName", ProductName),
00164         ("ProductCode", ProductCode),
00165         ("ProductVersion", ProductVersion),
00166         ("Manufacturer", Manufacturer),
00167         ("ProductLanguage", "1033")])
00168     db.Commit()
00169     return db

Here is the call graph for this function:

Here is the caller graph for this function:

def msilib.init_database (   name,
  schema,
  ProductName,
  ProductCode,
  ProductVersion,
  Manufacturer,
  request_uac = False 
)

Definition at line 293 of file msilib.py.

00293 
00294                   request_uac = False):
00295     try:
00296         os.unlink(name)
00297     except OSError:
00298         pass
00299     ProductCode = ProductCode.upper()
00300     d = MakeInstaller()
00301     # Create the database
00302     db = d.OpenDatabase(name,
00303          win32com.client.constants.msiOpenDatabaseModeCreate)
00304     # Create the tables
00305     for t in schema.tables:
00306         t.create(db)
00307     # Fill the validation table
00308     add_data(db, "_Validation", schema._Validation_records)
00309     # Initialize the summary information, allowing atmost 20 properties
00310     si = db.GetSummaryInformation(20)
00311     si.SetProperty(PID_TITLE, "Installation Database")
00312     si.SetProperty(PID_SUBJECT, ProductName)
00313     si.SetProperty(PID_AUTHOR, Manufacturer)
00314     si.SetProperty(PID_TEMPLATE, msi_type)
00315     si.SetProperty(PID_REVNUMBER, gen_uuid())
00316     if request_uac:
00317         wc = 2 # long file names, compressed, original media
00318     else:
00319         wc = 2 | 8 # +never invoke UAC
00320     si.SetProperty(PID_WORDCOUNT, wc)
00321     si.SetProperty(PID_PAGECOUNT, 200)
00322     si.SetProperty(PID_APPNAME, "Python MSI Library")
00323     # XXX more properties
00324     si.Persist()
00325     add_data(db, "Property", [
00326         ("ProductName", ProductName),
00327         ("ProductCode", ProductCode),
00328         ("ProductVersion", ProductVersion),
00329         ("Manufacturer", Manufacturer),
00330         ("ProductLanguage", "1033")])
00331     db.Commit()
00332     return db

Here is the call graph for this function:

Here is the caller graph for this function:

def msilib.make_id (   str)

Definition at line 174 of file __init__.py.

00174 
00175 def make_id(str):
00176     identifier_chars = string.ascii_letters + string.digits + "._"
00177     str = "".join([c if c in identifier_chars else "_" for c in str])
00178     if str[0] in (string.digits + "."):
00179         str = "_" + str
00180     assert re.match("^[A-Za-z_][A-Za-z0-9_.]*$", str), "FILE"+str
00181     return str

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 65 of file msilib.py.

00065 
00066 def MakeInstaller():
00067     global _Installer
00068     if _Installer is None:
00069         EnsureMSI()
00070         _Installer = win32com.client.Dispatch('WindowsInstaller.Installer',
00071                      resultCLSID='{000C1090-0000-0000-C000-000000000046}')
00072     return _Installer
00073 
_Merge=None

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 74 of file msilib.py.

00074 
00075 def MakeMerge2():
00076     global _Merge
00077     if _Merge is None:
00078         EnsureMSM()
00079         _Merge = win32com.client.Dispatch("Msm.Merge2.1")
00080     return _Merge

Here is the call graph for this function:

Here is the caller graph for this function:

def msilib.pe_type (   path)

Definition at line 649 of file msilib.py.

00649 
00650 def pe_type(path):
00651     header = open(path, "rb").read(1000)
00652     # offset of PE header is at offset 0x3c
00653     pe_offset = struct.unpack("<i", header[0x3c:0x40])[0]
00654     assert header[pe_offset:pe_offset+4] == "PE\0\0"
00655     machine = struct.unpack("<H", header[pe_offset+4:pe_offset+6])[0]
00656     return machine

Here is the call graph for this function:

Here is the caller graph for this function:

def msilib.reset ( )

Definition at line 51 of file msilib.py.

00051 
00052 def reset():
00053     global _directories
00054     _directories = sets.Set()

def msilib.set_arch_from_file (   path)

Definition at line 657 of file msilib.py.

00657 
00658 def set_arch_from_file(path):
00659     global msi_type, Win64, arch_ext
00660     machine = pe_type(path)
00661     if machine == 0x14c:
00662         # i386
00663         msi_type = "Intel"
00664         Win64 = 0
00665         arch_ext = ''
00666     elif machine == 0x200:
00667         # Itanium
00668         msi_type = "Intel64"
00669         Win64 = 1
00670         arch_ext = '.ia64'
00671     elif machine == 0x8664:
00672         # AMD64
00673         msi_type = "x64"
00674         Win64 = 1
00675         arch_ext = '.amd64'
00676     else:
00677         raise ValueError, "Unsupported architecture"
00678     msi_type += ";1033"

Here is the call graph for this function:


Variable Documentation

tuple msilib._directories = set()

Definition at line 220 of file __init__.py.

string msilib.AMD64 = "AMD64"

Definition at line 6 of file __init__.py.

tuple msilib.basestring = (str, unicode)

Definition at line 13 of file msilib.py.

Definition at line 11 of file __init__.py.

string msilib.Itanium = "Itanium"

Definition at line 7 of file __init__.py.

Definition at line 24 of file __init__.py.

Definition at line 48 of file msilib.py.

Definition at line 36 of file msilib.py.

Definition at line 47 of file msilib.py.

Definition at line 33 of file msilib.py.

Definition at line 38 of file msilib.py.

Definition at line 43 of file msilib.py.

Definition at line 37 of file msilib.py.

Definition at line 40 of file msilib.py.

Definition at line 42 of file msilib.py.

Definition at line 44 of file msilib.py.

Definition at line 45 of file msilib.py.

Definition at line 41 of file msilib.py.

Definition at line 49 of file msilib.py.

Definition at line 35 of file msilib.py.

Definition at line 39 of file msilib.py.

Definition at line 34 of file msilib.py.

Definition at line 46 of file msilib.py.

Definition at line 19 of file __init__.py.

int msilib.type_key = 0x2000

Definition at line 22 of file __init__.py.

Definition at line 13 of file __init__.py.

Definition at line 16 of file __init__.py.

Definition at line 21 of file __init__.py.

Definition at line 17 of file __init__.py.

Definition at line 18 of file __init__.py.

Definition at line 12 of file __init__.py.

int msilib.typemask = 0x0c00

Definition at line 15 of file __init__.py.

msilib.Win64 = AMD64orItanium

Definition at line 8 of file __init__.py.