| 1 | n/a | # Copyright (C) 2005 Martin v. Löwis |
|---|
| 2 | n/a | # Licensed to PSF under a Contributor Agreement. |
|---|
| 3 | n/a | from _msi import * |
|---|
| 4 | n/a | import fnmatch |
|---|
| 5 | n/a | import os |
|---|
| 6 | n/a | import re |
|---|
| 7 | n/a | import string |
|---|
| 8 | n/a | import sys |
|---|
| 9 | n/a | |
|---|
| 10 | n/a | AMD64 = "AMD64" in sys.version |
|---|
| 11 | n/a | Itanium = "Itanium" in sys.version |
|---|
| 12 | n/a | Win64 = AMD64 or Itanium |
|---|
| 13 | n/a | |
|---|
| 14 | n/a | # Partially taken from Wine |
|---|
| 15 | n/a | datasizemask= 0x00ff |
|---|
| 16 | n/a | type_valid= 0x0100 |
|---|
| 17 | n/a | type_localizable= 0x0200 |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | typemask= 0x0c00 |
|---|
| 20 | n/a | type_long= 0x0000 |
|---|
| 21 | n/a | type_short= 0x0400 |
|---|
| 22 | n/a | type_string= 0x0c00 |
|---|
| 23 | n/a | type_binary= 0x0800 |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | type_nullable= 0x1000 |
|---|
| 26 | n/a | type_key= 0x2000 |
|---|
| 27 | n/a | # XXX temporary, localizable? |
|---|
| 28 | n/a | knownbits = datasizemask | type_valid | type_localizable | \ |
|---|
| 29 | n/a | typemask | type_nullable | type_key |
|---|
| 30 | n/a | |
|---|
| 31 | n/a | class Table: |
|---|
| 32 | n/a | def __init__(self, name): |
|---|
| 33 | n/a | self.name = name |
|---|
| 34 | n/a | self.fields = [] |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | def add_field(self, index, name, type): |
|---|
| 37 | n/a | self.fields.append((index,name,type)) |
|---|
| 38 | n/a | |
|---|
| 39 | n/a | def sql(self): |
|---|
| 40 | n/a | fields = [] |
|---|
| 41 | n/a | keys = [] |
|---|
| 42 | n/a | self.fields.sort() |
|---|
| 43 | n/a | fields = [None]*len(self.fields) |
|---|
| 44 | n/a | for index, name, type in self.fields: |
|---|
| 45 | n/a | index -= 1 |
|---|
| 46 | n/a | unk = type & ~knownbits |
|---|
| 47 | n/a | if unk: |
|---|
| 48 | n/a | print("%s.%s unknown bits %x" % (self.name, name, unk)) |
|---|
| 49 | n/a | size = type & datasizemask |
|---|
| 50 | n/a | dtype = type & typemask |
|---|
| 51 | n/a | if dtype == type_string: |
|---|
| 52 | n/a | if size: |
|---|
| 53 | n/a | tname="CHAR(%d)" % size |
|---|
| 54 | n/a | else: |
|---|
| 55 | n/a | tname="CHAR" |
|---|
| 56 | n/a | elif dtype == type_short: |
|---|
| 57 | n/a | assert size==2 |
|---|
| 58 | n/a | tname = "SHORT" |
|---|
| 59 | n/a | elif dtype == type_long: |
|---|
| 60 | n/a | assert size==4 |
|---|
| 61 | n/a | tname="LONG" |
|---|
| 62 | n/a | elif dtype == type_binary: |
|---|
| 63 | n/a | assert size==0 |
|---|
| 64 | n/a | tname="OBJECT" |
|---|
| 65 | n/a | else: |
|---|
| 66 | n/a | tname="unknown" |
|---|
| 67 | n/a | print("%s.%sunknown integer type %d" % (self.name, name, size)) |
|---|
| 68 | n/a | if type & type_nullable: |
|---|
| 69 | n/a | flags = "" |
|---|
| 70 | n/a | else: |
|---|
| 71 | n/a | flags = " NOT NULL" |
|---|
| 72 | n/a | if type & type_localizable: |
|---|
| 73 | n/a | flags += " LOCALIZABLE" |
|---|
| 74 | n/a | fields[index] = "`%s` %s%s" % (name, tname, flags) |
|---|
| 75 | n/a | if type & type_key: |
|---|
| 76 | n/a | keys.append("`%s`" % name) |
|---|
| 77 | n/a | fields = ", ".join(fields) |
|---|
| 78 | n/a | keys = ", ".join(keys) |
|---|
| 79 | n/a | return "CREATE TABLE %s (%s PRIMARY KEY %s)" % (self.name, fields, keys) |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | def create(self, db): |
|---|
| 82 | n/a | v = db.OpenView(self.sql()) |
|---|
| 83 | n/a | v.Execute(None) |
|---|
| 84 | n/a | v.Close() |
|---|
| 85 | n/a | |
|---|
| 86 | n/a | class _Unspecified:pass |
|---|
| 87 | n/a | def change_sequence(seq, action, seqno=_Unspecified, cond = _Unspecified): |
|---|
| 88 | n/a | "Change the sequence number of an action in a sequence list" |
|---|
| 89 | n/a | for i in range(len(seq)): |
|---|
| 90 | n/a | if seq[i][0] == action: |
|---|
| 91 | n/a | if cond is _Unspecified: |
|---|
| 92 | n/a | cond = seq[i][1] |
|---|
| 93 | n/a | if seqno is _Unspecified: |
|---|
| 94 | n/a | seqno = seq[i][2] |
|---|
| 95 | n/a | seq[i] = (action, cond, seqno) |
|---|
| 96 | n/a | return |
|---|
| 97 | n/a | raise ValueError("Action not found in sequence") |
|---|
| 98 | n/a | |
|---|
| 99 | n/a | def add_data(db, table, values): |
|---|
| 100 | n/a | v = db.OpenView("SELECT * FROM `%s`" % table) |
|---|
| 101 | n/a | count = v.GetColumnInfo(MSICOLINFO_NAMES).GetFieldCount() |
|---|
| 102 | n/a | r = CreateRecord(count) |
|---|
| 103 | n/a | for value in values: |
|---|
| 104 | n/a | assert len(value) == count, value |
|---|
| 105 | n/a | for i in range(count): |
|---|
| 106 | n/a | field = value[i] |
|---|
| 107 | n/a | if isinstance(field, int): |
|---|
| 108 | n/a | r.SetInteger(i+1,field) |
|---|
| 109 | n/a | elif isinstance(field, str): |
|---|
| 110 | n/a | r.SetString(i+1,field) |
|---|
| 111 | n/a | elif field is None: |
|---|
| 112 | n/a | pass |
|---|
| 113 | n/a | elif isinstance(field, Binary): |
|---|
| 114 | n/a | r.SetStream(i+1, field.name) |
|---|
| 115 | n/a | else: |
|---|
| 116 | n/a | raise TypeError("Unsupported type %s" % field.__class__.__name__) |
|---|
| 117 | n/a | try: |
|---|
| 118 | n/a | v.Modify(MSIMODIFY_INSERT, r) |
|---|
| 119 | n/a | except Exception as e: |
|---|
| 120 | n/a | raise MSIError("Could not insert "+repr(values)+" into "+table) |
|---|
| 121 | n/a | |
|---|
| 122 | n/a | r.ClearData() |
|---|
| 123 | n/a | v.Close() |
|---|
| 124 | n/a | |
|---|
| 125 | n/a | |
|---|
| 126 | n/a | def add_stream(db, name, path): |
|---|
| 127 | n/a | v = db.OpenView("INSERT INTO _Streams (Name, Data) VALUES ('%s', ?)" % name) |
|---|
| 128 | n/a | r = CreateRecord(1) |
|---|
| 129 | n/a | r.SetStream(1, path) |
|---|
| 130 | n/a | v.Execute(r) |
|---|
| 131 | n/a | v.Close() |
|---|
| 132 | n/a | |
|---|
| 133 | n/a | def init_database(name, schema, |
|---|
| 134 | n/a | ProductName, ProductCode, ProductVersion, |
|---|
| 135 | n/a | Manufacturer): |
|---|
| 136 | n/a | try: |
|---|
| 137 | n/a | os.unlink(name) |
|---|
| 138 | n/a | except OSError: |
|---|
| 139 | n/a | pass |
|---|
| 140 | n/a | ProductCode = ProductCode.upper() |
|---|
| 141 | n/a | # Create the database |
|---|
| 142 | n/a | db = OpenDatabase(name, MSIDBOPEN_CREATE) |
|---|
| 143 | n/a | # Create the tables |
|---|
| 144 | n/a | for t in schema.tables: |
|---|
| 145 | n/a | t.create(db) |
|---|
| 146 | n/a | # Fill the validation table |
|---|
| 147 | n/a | add_data(db, "_Validation", schema._Validation_records) |
|---|
| 148 | n/a | # Initialize the summary information, allowing atmost 20 properties |
|---|
| 149 | n/a | si = db.GetSummaryInformation(20) |
|---|
| 150 | n/a | si.SetProperty(PID_TITLE, "Installation Database") |
|---|
| 151 | n/a | si.SetProperty(PID_SUBJECT, ProductName) |
|---|
| 152 | n/a | si.SetProperty(PID_AUTHOR, Manufacturer) |
|---|
| 153 | n/a | if Itanium: |
|---|
| 154 | n/a | si.SetProperty(PID_TEMPLATE, "Intel64;1033") |
|---|
| 155 | n/a | elif AMD64: |
|---|
| 156 | n/a | si.SetProperty(PID_TEMPLATE, "x64;1033") |
|---|
| 157 | n/a | else: |
|---|
| 158 | n/a | si.SetProperty(PID_TEMPLATE, "Intel;1033") |
|---|
| 159 | n/a | si.SetProperty(PID_REVNUMBER, gen_uuid()) |
|---|
| 160 | n/a | si.SetProperty(PID_WORDCOUNT, 2) # long file names, compressed, original media |
|---|
| 161 | n/a | si.SetProperty(PID_PAGECOUNT, 200) |
|---|
| 162 | n/a | si.SetProperty(PID_APPNAME, "Python MSI Library") |
|---|
| 163 | n/a | # XXX more properties |
|---|
| 164 | n/a | si.Persist() |
|---|
| 165 | n/a | add_data(db, "Property", [ |
|---|
| 166 | n/a | ("ProductName", ProductName), |
|---|
| 167 | n/a | ("ProductCode", ProductCode), |
|---|
| 168 | n/a | ("ProductVersion", ProductVersion), |
|---|
| 169 | n/a | ("Manufacturer", Manufacturer), |
|---|
| 170 | n/a | ("ProductLanguage", "1033")]) |
|---|
| 171 | n/a | db.Commit() |
|---|
| 172 | n/a | return db |
|---|
| 173 | n/a | |
|---|
| 174 | n/a | def add_tables(db, module): |
|---|
| 175 | n/a | for table in module.tables: |
|---|
| 176 | n/a | add_data(db, table, getattr(module, table)) |
|---|
| 177 | n/a | |
|---|
| 178 | n/a | def make_id(str): |
|---|
| 179 | n/a | identifier_chars = string.ascii_letters + string.digits + "._" |
|---|
| 180 | n/a | str = "".join([c if c in identifier_chars else "_" for c in str]) |
|---|
| 181 | n/a | if str[0] in (string.digits + "."): |
|---|
| 182 | n/a | str = "_" + str |
|---|
| 183 | n/a | assert re.match("^[A-Za-z_][A-Za-z0-9_.]*$", str), "FILE"+str |
|---|
| 184 | n/a | return str |
|---|
| 185 | n/a | |
|---|
| 186 | n/a | def gen_uuid(): |
|---|
| 187 | n/a | return "{"+UuidCreate().upper()+"}" |
|---|
| 188 | n/a | |
|---|
| 189 | n/a | class CAB: |
|---|
| 190 | n/a | def __init__(self, name): |
|---|
| 191 | n/a | self.name = name |
|---|
| 192 | n/a | self.files = [] |
|---|
| 193 | n/a | self.filenames = set() |
|---|
| 194 | n/a | self.index = 0 |
|---|
| 195 | n/a | |
|---|
| 196 | n/a | def gen_id(self, file): |
|---|
| 197 | n/a | logical = _logical = make_id(file) |
|---|
| 198 | n/a | pos = 1 |
|---|
| 199 | n/a | while logical in self.filenames: |
|---|
| 200 | n/a | logical = "%s.%d" % (_logical, pos) |
|---|
| 201 | n/a | pos += 1 |
|---|
| 202 | n/a | self.filenames.add(logical) |
|---|
| 203 | n/a | return logical |
|---|
| 204 | n/a | |
|---|
| 205 | n/a | def append(self, full, file, logical): |
|---|
| 206 | n/a | if os.path.isdir(full): |
|---|
| 207 | n/a | return |
|---|
| 208 | n/a | if not logical: |
|---|
| 209 | n/a | logical = self.gen_id(file) |
|---|
| 210 | n/a | self.index += 1 |
|---|
| 211 | n/a | self.files.append((full, logical)) |
|---|
| 212 | n/a | return self.index, logical |
|---|
| 213 | n/a | |
|---|
| 214 | n/a | def commit(self, db): |
|---|
| 215 | n/a | from tempfile import mktemp |
|---|
| 216 | n/a | filename = mktemp() |
|---|
| 217 | n/a | FCICreate(filename, self.files) |
|---|
| 218 | n/a | add_data(db, "Media", |
|---|
| 219 | n/a | [(1, self.index, None, "#"+self.name, None, None)]) |
|---|
| 220 | n/a | add_stream(db, self.name, filename) |
|---|
| 221 | n/a | os.unlink(filename) |
|---|
| 222 | n/a | db.Commit() |
|---|
| 223 | n/a | |
|---|
| 224 | n/a | _directories = set() |
|---|
| 225 | n/a | class Directory: |
|---|
| 226 | n/a | def __init__(self, db, cab, basedir, physical, _logical, default, componentflags=None): |
|---|
| 227 | n/a | """Create a new directory in the Directory table. There is a current component |
|---|
| 228 | n/a | at each point in time for the directory, which is either explicitly created |
|---|
| 229 | n/a | through start_component, or implicitly when files are added for the first |
|---|
| 230 | n/a | time. Files are added into the current component, and into the cab file. |
|---|
| 231 | n/a | To create a directory, a base directory object needs to be specified (can be |
|---|
| 232 | n/a | None), the path to the physical directory, and a logical directory name. |
|---|
| 233 | n/a | Default specifies the DefaultDir slot in the directory table. componentflags |
|---|
| 234 | n/a | specifies the default flags that new components get.""" |
|---|
| 235 | n/a | index = 1 |
|---|
| 236 | n/a | _logical = make_id(_logical) |
|---|
| 237 | n/a | logical = _logical |
|---|
| 238 | n/a | while logical in _directories: |
|---|
| 239 | n/a | logical = "%s%d" % (_logical, index) |
|---|
| 240 | n/a | index += 1 |
|---|
| 241 | n/a | _directories.add(logical) |
|---|
| 242 | n/a | self.db = db |
|---|
| 243 | n/a | self.cab = cab |
|---|
| 244 | n/a | self.basedir = basedir |
|---|
| 245 | n/a | self.physical = physical |
|---|
| 246 | n/a | self.logical = logical |
|---|
| 247 | n/a | self.component = None |
|---|
| 248 | n/a | self.short_names = set() |
|---|
| 249 | n/a | self.ids = set() |
|---|
| 250 | n/a | self.keyfiles = {} |
|---|
| 251 | n/a | self.componentflags = componentflags |
|---|
| 252 | n/a | if basedir: |
|---|
| 253 | n/a | self.absolute = os.path.join(basedir.absolute, physical) |
|---|
| 254 | n/a | blogical = basedir.logical |
|---|
| 255 | n/a | else: |
|---|
| 256 | n/a | self.absolute = physical |
|---|
| 257 | n/a | blogical = None |
|---|
| 258 | n/a | add_data(db, "Directory", [(logical, blogical, default)]) |
|---|
| 259 | n/a | |
|---|
| 260 | n/a | def start_component(self, component = None, feature = None, flags = None, keyfile = None, uuid=None): |
|---|
| 261 | n/a | """Add an entry to the Component table, and make this component the current for this |
|---|
| 262 | n/a | directory. If no component name is given, the directory name is used. If no feature |
|---|
| 263 | n/a | is given, the current feature is used. If no flags are given, the directory's default |
|---|
| 264 | n/a | flags are used. If no keyfile is given, the KeyPath is left null in the Component |
|---|
| 265 | n/a | table.""" |
|---|
| 266 | n/a | if flags is None: |
|---|
| 267 | n/a | flags = self.componentflags |
|---|
| 268 | n/a | if uuid is None: |
|---|
| 269 | n/a | uuid = gen_uuid() |
|---|
| 270 | n/a | else: |
|---|
| 271 | n/a | uuid = uuid.upper() |
|---|
| 272 | n/a | if component is None: |
|---|
| 273 | n/a | component = self.logical |
|---|
| 274 | n/a | self.component = component |
|---|
| 275 | n/a | if Win64: |
|---|
| 276 | n/a | flags |= 256 |
|---|
| 277 | n/a | if keyfile: |
|---|
| 278 | n/a | keyid = self.cab.gen_id(self.absolute, keyfile) |
|---|
| 279 | n/a | self.keyfiles[keyfile] = keyid |
|---|
| 280 | n/a | else: |
|---|
| 281 | n/a | keyid = None |
|---|
| 282 | n/a | add_data(self.db, "Component", |
|---|
| 283 | n/a | [(component, uuid, self.logical, flags, None, keyid)]) |
|---|
| 284 | n/a | if feature is None: |
|---|
| 285 | n/a | feature = current_feature |
|---|
| 286 | n/a | add_data(self.db, "FeatureComponents", |
|---|
| 287 | n/a | [(feature.id, component)]) |
|---|
| 288 | n/a | |
|---|
| 289 | n/a | def make_short(self, file): |
|---|
| 290 | n/a | oldfile = file |
|---|
| 291 | n/a | file = file.replace('+', '_') |
|---|
| 292 | n/a | file = ''.join(c for c in file if not c in r' "/\[]:;=,') |
|---|
| 293 | n/a | parts = file.split(".") |
|---|
| 294 | n/a | if len(parts) > 1: |
|---|
| 295 | n/a | prefix = "".join(parts[:-1]).upper() |
|---|
| 296 | n/a | suffix = parts[-1].upper() |
|---|
| 297 | n/a | if not prefix: |
|---|
| 298 | n/a | prefix = suffix |
|---|
| 299 | n/a | suffix = None |
|---|
| 300 | n/a | else: |
|---|
| 301 | n/a | prefix = file.upper() |
|---|
| 302 | n/a | suffix = None |
|---|
| 303 | n/a | if len(parts) < 3 and len(prefix) <= 8 and file == oldfile and ( |
|---|
| 304 | n/a | not suffix or len(suffix) <= 3): |
|---|
| 305 | n/a | if suffix: |
|---|
| 306 | n/a | file = prefix+"."+suffix |
|---|
| 307 | n/a | else: |
|---|
| 308 | n/a | file = prefix |
|---|
| 309 | n/a | else: |
|---|
| 310 | n/a | file = None |
|---|
| 311 | n/a | if file is None or file in self.short_names: |
|---|
| 312 | n/a | prefix = prefix[:6] |
|---|
| 313 | n/a | if suffix: |
|---|
| 314 | n/a | suffix = suffix[:3] |
|---|
| 315 | n/a | pos = 1 |
|---|
| 316 | n/a | while 1: |
|---|
| 317 | n/a | if suffix: |
|---|
| 318 | n/a | file = "%s~%d.%s" % (prefix, pos, suffix) |
|---|
| 319 | n/a | else: |
|---|
| 320 | n/a | file = "%s~%d" % (prefix, pos) |
|---|
| 321 | n/a | if file not in self.short_names: break |
|---|
| 322 | n/a | pos += 1 |
|---|
| 323 | n/a | assert pos < 10000 |
|---|
| 324 | n/a | if pos in (10, 100, 1000): |
|---|
| 325 | n/a | prefix = prefix[:-1] |
|---|
| 326 | n/a | self.short_names.add(file) |
|---|
| 327 | n/a | assert not re.search(r'[\?|><:/*"+,;=\[\]]', file) # restrictions on short names |
|---|
| 328 | n/a | return file |
|---|
| 329 | n/a | |
|---|
| 330 | n/a | def add_file(self, file, src=None, version=None, language=None): |
|---|
| 331 | n/a | """Add a file to the current component of the directory, starting a new one |
|---|
| 332 | n/a | if there is no current component. By default, the file name in the source |
|---|
| 333 | n/a | and the file table will be identical. If the src file is specified, it is |
|---|
| 334 | n/a | interpreted relative to the current directory. Optionally, a version and a |
|---|
| 335 | n/a | language can be specified for the entry in the File table.""" |
|---|
| 336 | n/a | if not self.component: |
|---|
| 337 | n/a | self.start_component(self.logical, current_feature, 0) |
|---|
| 338 | n/a | if not src: |
|---|
| 339 | n/a | # Allow relative paths for file if src is not specified |
|---|
| 340 | n/a | src = file |
|---|
| 341 | n/a | file = os.path.basename(file) |
|---|
| 342 | n/a | absolute = os.path.join(self.absolute, src) |
|---|
| 343 | n/a | assert not re.search(r'[\?|><:/*]"', file) # restrictions on long names |
|---|
| 344 | n/a | if file in self.keyfiles: |
|---|
| 345 | n/a | logical = self.keyfiles[file] |
|---|
| 346 | n/a | else: |
|---|
| 347 | n/a | logical = None |
|---|
| 348 | n/a | sequence, logical = self.cab.append(absolute, file, logical) |
|---|
| 349 | n/a | assert logical not in self.ids |
|---|
| 350 | n/a | self.ids.add(logical) |
|---|
| 351 | n/a | short = self.make_short(file) |
|---|
| 352 | n/a | full = "%s|%s" % (short, file) |
|---|
| 353 | n/a | filesize = os.stat(absolute).st_size |
|---|
| 354 | n/a | # constants.msidbFileAttributesVital |
|---|
| 355 | n/a | # Compressed omitted, since it is the database default |
|---|
| 356 | n/a | # could add r/o, system, hidden |
|---|
| 357 | n/a | attributes = 512 |
|---|
| 358 | n/a | add_data(self.db, "File", |
|---|
| 359 | n/a | [(logical, self.component, full, filesize, version, |
|---|
| 360 | n/a | language, attributes, sequence)]) |
|---|
| 361 | n/a | #if not version: |
|---|
| 362 | n/a | # # Add hash if the file is not versioned |
|---|
| 363 | n/a | # filehash = FileHash(absolute, 0) |
|---|
| 364 | n/a | # add_data(self.db, "MsiFileHash", |
|---|
| 365 | n/a | # [(logical, 0, filehash.IntegerData(1), |
|---|
| 366 | n/a | # filehash.IntegerData(2), filehash.IntegerData(3), |
|---|
| 367 | n/a | # filehash.IntegerData(4))]) |
|---|
| 368 | n/a | # Automatically remove .pyc files on uninstall (2) |
|---|
| 369 | n/a | # XXX: adding so many RemoveFile entries makes installer unbelievably |
|---|
| 370 | n/a | # slow. So instead, we have to use wildcard remove entries |
|---|
| 371 | n/a | if file.endswith(".py"): |
|---|
| 372 | n/a | add_data(self.db, "RemoveFile", |
|---|
| 373 | n/a | [(logical+"c", self.component, "%sC|%sc" % (short, file), |
|---|
| 374 | n/a | self.logical, 2), |
|---|
| 375 | n/a | (logical+"o", self.component, "%sO|%so" % (short, file), |
|---|
| 376 | n/a | self.logical, 2)]) |
|---|
| 377 | n/a | return logical |
|---|
| 378 | n/a | |
|---|
| 379 | n/a | def glob(self, pattern, exclude = None): |
|---|
| 380 | n/a | """Add a list of files to the current component as specified in the |
|---|
| 381 | n/a | glob pattern. Individual files can be excluded in the exclude list.""" |
|---|
| 382 | n/a | try: |
|---|
| 383 | n/a | files = os.listdir(self.absolute) |
|---|
| 384 | n/a | except OSError: |
|---|
| 385 | n/a | return [] |
|---|
| 386 | n/a | if pattern[:1] != '.': |
|---|
| 387 | n/a | files = (f for f in files if f[0] != '.') |
|---|
| 388 | n/a | files = fnmatch.filter(files, pattern) |
|---|
| 389 | n/a | for f in files: |
|---|
| 390 | n/a | if exclude and f in exclude: continue |
|---|
| 391 | n/a | self.add_file(f) |
|---|
| 392 | n/a | return files |
|---|
| 393 | n/a | |
|---|
| 394 | n/a | def remove_pyc(self): |
|---|
| 395 | n/a | "Remove .pyc files on uninstall" |
|---|
| 396 | n/a | add_data(self.db, "RemoveFile", |
|---|
| 397 | n/a | [(self.component+"c", self.component, "*.pyc", self.logical, 2)]) |
|---|
| 398 | n/a | |
|---|
| 399 | n/a | class Binary: |
|---|
| 400 | n/a | def __init__(self, fname): |
|---|
| 401 | n/a | self.name = fname |
|---|
| 402 | n/a | def __repr__(self): |
|---|
| 403 | n/a | return 'msilib.Binary(os.path.join(dirname,"%s"))' % self.name |
|---|
| 404 | n/a | |
|---|
| 405 | n/a | class Feature: |
|---|
| 406 | n/a | def __init__(self, db, id, title, desc, display, level = 1, |
|---|
| 407 | n/a | parent=None, directory = None, attributes=0): |
|---|
| 408 | n/a | self.id = id |
|---|
| 409 | n/a | if parent: |
|---|
| 410 | n/a | parent = parent.id |
|---|
| 411 | n/a | add_data(db, "Feature", |
|---|
| 412 | n/a | [(id, parent, title, desc, display, |
|---|
| 413 | n/a | level, directory, attributes)]) |
|---|
| 414 | n/a | def set_current(self): |
|---|
| 415 | n/a | global current_feature |
|---|
| 416 | n/a | current_feature = self |
|---|
| 417 | n/a | |
|---|
| 418 | n/a | class Control: |
|---|
| 419 | n/a | def __init__(self, dlg, name): |
|---|
| 420 | n/a | self.dlg = dlg |
|---|
| 421 | n/a | self.name = name |
|---|
| 422 | n/a | |
|---|
| 423 | n/a | def event(self, event, argument, condition = "1", ordering = None): |
|---|
| 424 | n/a | add_data(self.dlg.db, "ControlEvent", |
|---|
| 425 | n/a | [(self.dlg.name, self.name, event, argument, |
|---|
| 426 | n/a | condition, ordering)]) |
|---|
| 427 | n/a | |
|---|
| 428 | n/a | def mapping(self, event, attribute): |
|---|
| 429 | n/a | add_data(self.dlg.db, "EventMapping", |
|---|
| 430 | n/a | [(self.dlg.name, self.name, event, attribute)]) |
|---|
| 431 | n/a | |
|---|
| 432 | n/a | def condition(self, action, condition): |
|---|
| 433 | n/a | add_data(self.dlg.db, "ControlCondition", |
|---|
| 434 | n/a | [(self.dlg.name, self.name, action, condition)]) |
|---|
| 435 | n/a | |
|---|
| 436 | n/a | class RadioButtonGroup(Control): |
|---|
| 437 | n/a | def __init__(self, dlg, name, property): |
|---|
| 438 | n/a | self.dlg = dlg |
|---|
| 439 | n/a | self.name = name |
|---|
| 440 | n/a | self.property = property |
|---|
| 441 | n/a | self.index = 1 |
|---|
| 442 | n/a | |
|---|
| 443 | n/a | def add(self, name, x, y, w, h, text, value = None): |
|---|
| 444 | n/a | if value is None: |
|---|
| 445 | n/a | value = name |
|---|
| 446 | n/a | add_data(self.dlg.db, "RadioButton", |
|---|
| 447 | n/a | [(self.property, self.index, value, |
|---|
| 448 | n/a | x, y, w, h, text, None)]) |
|---|
| 449 | n/a | self.index += 1 |
|---|
| 450 | n/a | |
|---|
| 451 | n/a | class Dialog: |
|---|
| 452 | n/a | def __init__(self, db, name, x, y, w, h, attr, title, first, default, cancel): |
|---|
| 453 | n/a | self.db = db |
|---|
| 454 | n/a | self.name = name |
|---|
| 455 | n/a | self.x, self.y, self.w, self.h = x,y,w,h |
|---|
| 456 | n/a | add_data(db, "Dialog", [(name, x,y,w,h,attr,title,first,default,cancel)]) |
|---|
| 457 | n/a | |
|---|
| 458 | n/a | def control(self, name, type, x, y, w, h, attr, prop, text, next, help): |
|---|
| 459 | n/a | add_data(self.db, "Control", |
|---|
| 460 | n/a | [(self.name, name, type, x, y, w, h, attr, prop, text, next, help)]) |
|---|
| 461 | n/a | return Control(self, name) |
|---|
| 462 | n/a | |
|---|
| 463 | n/a | def text(self, name, x, y, w, h, attr, text): |
|---|
| 464 | n/a | return self.control(name, "Text", x, y, w, h, attr, None, |
|---|
| 465 | n/a | text, None, None) |
|---|
| 466 | n/a | |
|---|
| 467 | n/a | def bitmap(self, name, x, y, w, h, text): |
|---|
| 468 | n/a | return self.control(name, "Bitmap", x, y, w, h, 1, None, text, None, None) |
|---|
| 469 | n/a | |
|---|
| 470 | n/a | def line(self, name, x, y, w, h): |
|---|
| 471 | n/a | return self.control(name, "Line", x, y, w, h, 1, None, None, None, None) |
|---|
| 472 | n/a | |
|---|
| 473 | n/a | def pushbutton(self, name, x, y, w, h, attr, text, next): |
|---|
| 474 | n/a | return self.control(name, "PushButton", x, y, w, h, attr, None, text, next, None) |
|---|
| 475 | n/a | |
|---|
| 476 | n/a | def radiogroup(self, name, x, y, w, h, attr, prop, text, next): |
|---|
| 477 | n/a | add_data(self.db, "Control", |
|---|
| 478 | n/a | [(self.name, name, "RadioButtonGroup", |
|---|
| 479 | n/a | x, y, w, h, attr, prop, text, next, None)]) |
|---|
| 480 | n/a | return RadioButtonGroup(self, name, prop) |
|---|
| 481 | n/a | |
|---|
| 482 | n/a | def checkbox(self, name, x, y, w, h, attr, prop, text, next): |
|---|
| 483 | n/a | return self.control(name, "CheckBox", x, y, w, h, attr, prop, text, next, None) |
|---|