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)
Beispiel #2
0
    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):
     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))