Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(14)

Delta Between Two Patch Sets: Lib/msilib/__init__.py

Issue 7639: bdist_msi fails on files with long names
Left Patch Set: Created 10 years, 1 month ago
Right Patch Set: Created 8 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Lib/test/test_msilib.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2005 Martin v. Löwis 1 # Copyright (C) 2005 Martin v. Löwis
3 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
4 from _msi import * 3 from _msi import *
5 import os, string, re, sys 4 import os, string, re, sys
6 5
7 AMD64 = "AMD64" in sys.version 6 AMD64 = "AMD64" in sys.version
8 Itanium = "Itanium" in sys.version 7 Itanium = "Itanium" in sys.version
9 Win64 = AMD64 or Itanium 8 Win64 = AMD64 or Itanium
10 9
11 # Partially taken from Wine 10 # Partially taken from Wine
(...skipping 23 matching lines...) Expand all
35 34
36 def sql(self): 35 def sql(self):
37 fields = [] 36 fields = []
38 keys = [] 37 keys = []
39 self.fields.sort() 38 self.fields.sort()
40 fields = [None]*len(self.fields) 39 fields = [None]*len(self.fields)
41 for index, name, type in self.fields: 40 for index, name, type in self.fields:
42 index -= 1 41 index -= 1
43 unk = type & ~knownbits 42 unk = type & ~knownbits
44 if unk: 43 if unk:
45 print "%s.%s unknown bits %x" % (self.name, name, unk) 44 print("%s.%s unknown bits %x" % (self.name, name, unk))
46 size = type & datasizemask 45 size = type & datasizemask
47 dtype = type & typemask 46 dtype = type & typemask
48 if dtype == type_string: 47 if dtype == type_string:
49 if size: 48 if size:
50 tname="CHAR(%d)" % size 49 tname="CHAR(%d)" % size
51 else: 50 else:
52 tname="CHAR" 51 tname="CHAR"
53 elif dtype == type_short: 52 elif dtype == type_short:
54 assert size==2 53 assert size==2
55 tname = "SHORT" 54 tname = "SHORT"
56 elif dtype == type_long: 55 elif dtype == type_long:
57 assert size==4 56 assert size==4
58 tname="LONG" 57 tname="LONG"
59 elif dtype == type_binary: 58 elif dtype == type_binary:
60 assert size==0 59 assert size==0
61 tname="OBJECT" 60 tname="OBJECT"
62 else: 61 else:
63 tname="unknown" 62 tname="unknown"
64 print "%s.%sunknown integer type %d" % (self.name, name, size) 63 print("%s.%sunknown integer type %d" % (self.name, name, size))
65 if type & type_nullable: 64 if type & type_nullable:
66 flags = "" 65 flags = ""
67 else: 66 else:
68 flags = " NOT NULL" 67 flags = " NOT NULL"
69 if type & type_localizable: 68 if type & type_localizable:
70 flags += " LOCALIZABLE" 69 flags += " LOCALIZABLE"
71 fields[index] = "`%s` %s%s" % (name, tname, flags) 70 fields[index] = "`%s` %s%s" % (name, tname, flags)
72 if type & type_key: 71 if type & type_key:
73 keys.append("`%s`" % name) 72 keys.append("`%s`" % name)
74 fields = ", ".join(fields) 73 fields = ", ".join(fields)
75 keys = ", ".join(keys) 74 keys = ", ".join(keys)
76 return "CREATE TABLE %s (%s PRIMARY KEY %s)" % (self.name, fields, keys) 75 return "CREATE TABLE %s (%s PRIMARY KEY %s)" % (self.name, fields, keys)
77 76
78 def create(self, db): 77 def create(self, db):
79 v = db.OpenView(self.sql()) 78 v = db.OpenView(self.sql())
80 v.Execute(None) 79 v.Execute(None)
81 v.Close() 80 v.Close()
82 81
83 class _Unspecified:pass 82 class _Unspecified:pass
84 def change_sequence(seq, action, seqno=_Unspecified, cond = _Unspecified): 83 def change_sequence(seq, action, seqno=_Unspecified, cond = _Unspecified):
85 "Change the sequence number of an action in a sequence list" 84 "Change the sequence number of an action in a sequence list"
86 for i in range(len(seq)): 85 for i in range(len(seq)):
87 if seq[i][0] == action: 86 if seq[i][0] == action:
88 if cond is _Unspecified: 87 if cond is _Unspecified:
89 cond = seq[i][1] 88 cond = seq[i][1]
90 if seqno is _Unspecified: 89 if seqno is _Unspecified:
91 seqno = seq[i][2] 90 seqno = seq[i][2]
92 seq[i] = (action, cond, seqno) 91 seq[i] = (action, cond, seqno)
93 return 92 return
94 raise ValueError, "Action not found in sequence" 93 raise ValueError("Action not found in sequence")
95 94
96 def add_data(db, table, values): 95 def add_data(db, table, values):
97 v = db.OpenView("SELECT * FROM `%s`" % table) 96 v = db.OpenView("SELECT * FROM `%s`" % table)
98 count = v.GetColumnInfo(MSICOLINFO_NAMES).GetFieldCount() 97 count = v.GetColumnInfo(MSICOLINFO_NAMES).GetFieldCount()
99 r = CreateRecord(count) 98 r = CreateRecord(count)
100 for value in values: 99 for value in values:
101 assert len(value) == count, value 100 assert len(value) == count, value
102 for i in range(count): 101 for i in range(count):
103 field = value[i] 102 field = value[i]
104 if isinstance(field, (int, long)): 103 if isinstance(field, int):
105 r.SetInteger(i+1,field) 104 r.SetInteger(i+1,field)
106 elif isinstance(field, basestring): 105 elif isinstance(field, str):
107 r.SetString(i+1,field) 106 r.SetString(i+1,field)
108 elif field is None: 107 elif field is None:
109 pass 108 pass
110 elif isinstance(field, Binary): 109 elif isinstance(field, Binary):
111 r.SetStream(i+1, field.name) 110 r.SetStream(i+1, field.name)
112 else: 111 else:
113 raise TypeError, "Unsupported type %s" % field.__class__.__name_ _ 112 raise TypeError("Unsupported type %s" % field.__class__.__name__ )
114 try: 113 try:
115 v.Modify(MSIMODIFY_INSERT, r) 114 v.Modify(MSIMODIFY_INSERT, r)
116 except Exception, e: 115 except Exception as e:
117 raise MSIError("Could not insert "+repr(values)+" into "+table) 116 raise MSIError("Could not insert "+repr(values)+" into "+table)
118 117
119 r.ClearData() 118 r.ClearData()
120 v.Close() 119 v.Close()
121 120
122 121
123 def add_stream(db, name, path): 122 def add_stream(db, name, path):
124 v = db.OpenView("INSERT INTO _Streams (Name, Data) VALUES ('%s', ?)" % name) 123 v = db.OpenView("INSERT INTO _Streams (Name, Data) VALUES ('%s', ?)" % name)
125 r = CreateRecord(1) 124 r = CreateRecord(1)
126 r.SetStream(1, path) 125 r.SetStream(1, path)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ("Manufacturer", Manufacturer), 165 ("Manufacturer", Manufacturer),
167 ("ProductLanguage", "1033")]) 166 ("ProductLanguage", "1033")])
168 db.Commit() 167 db.Commit()
169 return db 168 return db
170 169
171 def add_tables(db, module): 170 def add_tables(db, module):
172 for table in module.tables: 171 for table in module.tables:
173 add_data(db, table, getattr(module, table)) 172 add_data(db, table, getattr(module, table))
174 173
175 def make_id(str): 174 def make_id(str):
176 #str = str.replace(".", "_") # colons are allowed 175 identifier_chars = string.ascii_letters + string.digits + "._"
177 str = str.replace(" ", "_") 176 str = "".join([c if c in identifier_chars else "_" for c in str])
178 str = str.replace("-", "_") 177 if str[0] in (string.digits + "."):
179 if str[0] in string.digits: 178 str = "_" + str
180 str = "_"+str
181 assert re.match("^[A-Za-z_][A-Za-z0-9_.]*$", str), "FILE"+str 179 assert re.match("^[A-Za-z_][A-Za-z0-9_.]*$", str), "FILE"+str
182 return str 180 return str
183 181
184 def gen_uuid(): 182 def gen_uuid():
185 return "{"+UuidCreate().upper()+"}" 183 return "{"+UuidCreate().upper()+"}"
186 184
187 class CAB: 185 class CAB:
188 def __init__(self, name): 186 def __init__(self, name):
189 self.name = name 187 self.name = name
190 self.files = [] 188 self.files = []
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 else: 276 else:
279 keyid = None 277 keyid = None
280 add_data(self.db, "Component", 278 add_data(self.db, "Component",
281 [(component, uuid, self.logical, flags, None, keyid)]) 279 [(component, uuid, self.logical, flags, None, keyid)])
282 if feature is None: 280 if feature is None:
283 feature = current_feature 281 feature = current_feature
284 add_data(self.db, "FeatureComponents", 282 add_data(self.db, "FeatureComponents",
285 [(feature.id, component)]) 283 [(feature.id, component)])
286 284
287 def make_short(self, file): 285 def make_short(self, file):
286 oldfile = file
287 file = file.replace('+', '_')
288 file = ''.join(c for c in file if not c in ' "/\[]:;=,')
288 parts = file.split(".") 289 parts = file.split(".")
289 if len(parts)>1: 290 if len(parts) > 1:
291 prefix = "".join(parts[:-1]).upper()
290 suffix = parts[-1].upper() 292 suffix = parts[-1].upper()
291 prefix = "".join(parts[:-1]).upper() 293 if not prefix:
292 else: 294 prefix = suffix
295 suffix = None
296 else:
297 prefix = file.upper()
293 suffix = None 298 suffix = None
294 prefix = file.upper() 299 if len(parts) < 3 and len(prefix) <= 8 and file == oldfile and (
295 file = None 300 not suffix or len(suffix) <= 3):
296 if len(parts)<3 and len(prefix)<=8 and (not suffix or len(suffix)<=3):
297 if suffix: 301 if suffix:
298 file = prefix+"."+suffix 302 file = prefix+"."+suffix
299 else: 303 else:
300 file = prefix 304 file = prefix
305 else:
306 file = None
301 if file is None or file in self.short_names: 307 if file is None or file in self.short_names:
302 prefix = prefix[:6] 308 prefix = prefix[:6]
303 if suffix: 309 if suffix:
304 suffix = suffix[:3] 310 suffix = suffix[:3]
305 pos = 1 311 pos = 1
306 while 1: 312 while 1:
307 if suffix: 313 if suffix:
308 file = "%s~%d.%s" % (prefix, pos, suffix) 314 file = "%s~%d.%s" % (prefix, pos, suffix)
309 else: 315 else:
310 file = "%s~%d" % (prefix, pos) 316 file = "%s~%d" % (prefix, pos)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return self.control(name, "PushButton", x, y, w, h, attr, None, text, ne xt, None) 465 return self.control(name, "PushButton", x, y, w, h, attr, None, text, ne xt, None)
460 466
461 def radiogroup(self, name, x, y, w, h, attr, prop, text, next): 467 def radiogroup(self, name, x, y, w, h, attr, prop, text, next):
462 add_data(self.db, "Control", 468 add_data(self.db, "Control",
463 [(self.name, name, "RadioButtonGroup", 469 [(self.name, name, "RadioButtonGroup",
464 x, y, w, h, attr, prop, text, next, None)]) 470 x, y, w, h, attr, prop, text, next, None)])
465 return RadioButtonGroup(self, name, prop) 471 return RadioButtonGroup(self, name, prop)
466 472
467 def checkbox(self, name, x, y, w, h, attr, prop, text, next): 473 def checkbox(self, name, x, y, w, h, attr, prop, text, next):
468 return self.control(name, "CheckBox", x, y, w, h, attr, prop, text, next , None) 474 return self.control(name, "CheckBox", x, y, w, h, attr, prop, text, next , None)
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+