def add_files(self): db = self.db cab = msilib.CAB("distfiles") f = Feature(db, "default", "Default Feature", "Everything", 1, directory="TARGETDIR") f.set_current() rootdir = os.path.abspath(self.bdist_dir) root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir") db.Commit() todo = [root] while todo: dir = todo.pop() for file in os.listdir(dir.absolute): afile = os.path.join(dir.absolute, file) if os.path.isdir(afile): newdir = Directory(db, cab, dir, file, file, "%s|%s" % (dir.make_short(file), file)) todo.append(newdir) else: key = dir.add_file(file) if file == self.install_script: if self.install_script_key: raise DistutilsOptionError, "Multiple files with name %s" % file self.install_script_key = '[#%s]' % key cab.commit(db)
def add_files(self): db = self.db cab = msilib.CAB('distfiles') rootdir = os.path.abspath(self.bdist_dir) root = Directory(db, cab, None, rootdir, 'TARGETDIR', 'SourceDir') f = Feature(db, 'Python', 'Python', 'Everything', 0, 1, directory='TARGETDIR') items = [(f, root, '')] for version in self.versions + [self.other_version]: target = 'TARGETDIR' + version name = default = 'Python' + version desc = 'Everything' if version is self.other_version: title = 'Python from another location' level = 2 else: title = 'Python %s from registry' % version level = 1 f = Feature(db, name, title, desc, 1, level, directory=target) dir = Directory(db, cab, root, rootdir, target, default) items.append((f, dir, version)) db.Commit() seen = {} for feature, dir, version in items: todo = [dir] while todo: dir = todo.pop() for file in os.listdir(dir.absolute): afile = os.path.join(dir.absolute, file) if os.path.isdir(afile): short = '%s|%s' % (dir.make_short(file), file) default = file + version newdir = Directory(db, cab, dir, file, default, short) todo.append(newdir) else: if not dir.component: dir.start_component(dir.logical, feature, 0) if afile not in seen: key = seen[afile] = dir.add_file(file) if file == self.install_script: if self.install_script_key: raise DistutilsOptionError( 'Multiple files with name %s' % file) self.install_script_key = '[#%s]' % key else: key = seen[afile] add_data(self.db, 'DuplicateFile', [(key + version, dir.component, key, None, dir.logical)]) db.Commit() cab.commit(db) return
def add_files(self): db = self.db cab = msilib.CAB("distfiles") f = Feature(db, "default", "Default Feature", "Everything", 1, directory="TARGETDIR") f.set_current() rootdir = os.path.abspath(self.bdist_dir) root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir") db.Commit() todo = [root] while todo: dir = todo.pop() for file in os.listdir(dir.absolute): afile = os.path.join(dir.absolute, file) if os.path.isdir(afile): newdir = Directory(db, cab, dir, file, file, "%s|%s" % (dir.make_short(file), file)) todo.append(newdir) else: key = dir.add_file(file) if file==self.install_script: if self.install_script_key: raise DistutilsOptionError( "Multiple files with name %s" % file) self.install_script_key = '[#%s]' % key cab.commit(db)
def add_features(self): global default_feature if (self.isDebug): print '(add_features).1 :: db=(%s)' % (str(self.db)) default_feature = Feature(self.db, "DefaultFeature", "DSS", "DSS Installation", 1, directory="TARGETDIR")
def add_files(self): db = self.db cab = msilib.CAB("distfiles") rootdir = os.path.abspath(self.bdist_dir) root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir") f = Feature(db, "Python", "Python", "Everything", 0, 1, directory="TARGETDIR") items = [(f, root, "")] for version in self.versions + [self.other_version]: target = "TARGETDIR" + version name = default = "Python" + version desc = "Everything" if version is self.other_version: title = "Python from another location" level = 2 else: title = "Python %s from registry" % version level = 1 f = Feature(db, name, title, desc, 1, level, directory=target) dir = Directory(db, cab, root, rootdir, target, default) items.append((f, dir, version)) db.Commit() seen = {} for feature, dir, version in items: todo = [dir] while todo: dir = todo.pop() for file in os.listdir(dir.absolute): afile = os.path.join(dir.absolute, file) if os.path.isdir(afile): short = "%s|%s" % (dir.make_short(file), file) default = file + version newdir = Directory(db, cab, dir, file, default, short) todo.append(newdir) else: if not dir.component: dir.start_component(dir.logical, feature, 0) if afile not in seen: key = seen[afile] = dir.add_file(file) if file == self.install_script: if self.install_script_key: raise DistutilsOptionError( "Multiple files with name %s" % file) self.install_script_key = "[#%s]" % key else: key = seen[afile] add_data( self.db, "DuplicateFile", [( key + version, dir.component, key, None, dir.logical, )], ) db.Commit() cab.commit(db)
def add_files(self): f = Feature(self.db, "default", "Default Feature", "Everything", 1, directory="TARGETDIR") f.set_current() # each tree is represented by a CAB for tree in self.trees: if isinstance(tree, PublicTree): cab = _CAB(tree.name) rootdir = os.path.abspath(tree.root) root = _Directory(self.db, cab, None, rootdir, "TARGETDIR", "SourceDir") self.db.Commit() todo = [root] while todo: dir = todo.pop() #sys.stderr.write("processing %s\n" % dir.physical) for file in os.listdir(dir.absolute): if tree.excludes and tree.excludes.match(file): continue afile = os.path.join(dir.absolute, file) if os.path.isdir(afile): newdir = _Directory(self.db, cab, dir, file, file, "%s|%s" % (dir.make_short(file), file)) todo.append(newdir) else: try: key = dir.add_file(file) #sys.stderr.write('added %s\n' % file) except AssertionError: print "Exception adding", file print ''.join(traceback.format_exception(*sys.exc_info())) print "dir.short_names is", dir.short_names #_showmedia(self.db) cab.commit(self.db) elif isinstance(tree, PrivateTree): # private trees are represented as a zip file contained as a binary blob files = [] todo = [(os.path.abspath(tree.root), "")] while todo: dir, rdir = todo.pop() for file in os.listdir(dir): if tree.excludes and tree.excludes.match(file): print 'excluding', (rdir and os.path.join(rdir, file)) or file continue afile = os.path.join(dir, file) rfile = (rdir and os.path.join(rdir, file)) or file if os.path.isdir(afile): todo.append((afile, rfile)) else: files.append((afile, rfile)) tfile = tempfile.mktemp() zfile = None try: # we base64 the zip file for better use with Scripting.FileSystemObject buffer = StringIO.StringIO() zfile = zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED) for afile, rfile in files: zfile.write(afile, rfile) zfile.close() zfile = None data = buffer.getvalue() print tree.name + ' zipfile', len(data) data = base64.encodestring(data) tfileobj = open(tfile, "w") tfileobj.write(data + '\n') tfileobj.close() # tfileobj = open(tfile, "r") # for line in tfileobj: # print line.strip() # tfileobj.close() print tfile, os.path.getsize(tfile) add_data(self.db, "Binary", [ ("tree-" + tree.name, msilib.Binary(tfile)), ]) finally: if zfile and isinstance(zfile, zipfile.ZipFile): zfile.close() if os.path.exists(tfile): try: os.unlink(tfile) except: pass # handle unpack script if tree.unpack_script: script_key = "tree-%s-unpack" % tree.name action_script = tree.unpack_script if tree.unpack_script.lower().endswith(".exe"): action_type = 2 if tree.unpack_script.lower().endswith(".js"): action_type = 5 elif tree.unpack_script.lower().endswith(".vbs"): action_type = 6 elif tree.unpack_script.lower().endswith(".py"): action_script, action_type = self._wrap_unpack_script(tree) else: raise ValueError("Can't handle unpack script of unknown type: %s" % tree.unpack_script) add_data(self.db, "Binary", [(script_key, msilib.Binary(action_script)), ]) # fp = open(action_script, "rb") # data = fp.read() # fp.close() # print '------------------- unpack script for tree "%s" ----------------------' % tree.name # print data # print '----------------------------------------------------------------------' if action_script != tree.unpack_script: atexit.register(lambda x=action_script: os.path.exists(x) and os.unlink(x)) add_data(self.db, "CustomAction", [(script_key, action_type, script_key, None)]) add_data(self.db, "InstallExecuteSequence", [(script_key, "NOT Installed", 6799)]) else: raise ValueError("Can't process tree <%s: %s> -- unknown subtype of Tree" % (tree.__class__.__name__, tree.name))