msilib.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码
def commit(self, db):
        self.file.close()
        try:
            os.unlink(self.name+".cab")
        except OSError:
            pass
        for k, v in [(r"Software\Microsoft\VisualStudio\7.1\Setup\VS", "VS7CommonBinDir"),
                     (r"Software\Microsoft\VisualStudio\8.0\Setup\VS", "VS7CommonBinDir"),
                     (r"Software\Microsoft\VisualStudio\9.0\Setup\VS", "VS7CommonBinDir"),
                     (r"Software\Microsoft\Win32SDK\Directories", "Install Dir"),
                    ]:
            try:
                key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, k)
                dir = _winreg.QueryValueEx(key, v)[0]
                _winreg.CloseKey(key)
            except (WindowsError, IndexError):
                continue
            cabarc = os.path.join(dir, r"Bin", "cabarc.exe")
            if not os.path.exists(cabarc):
                continue
            break
        else:
            print "WARNING: cabarc.exe not found in registry"
            cabarc = "cabarc.exe"
        cmd = r'"%s" -m lzx:21 n %s.cab @%s.txt' % (cabarc, self.name, self.name)
        p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        for line in p.stdout:
            if line.startswith("  -- adding "):
                sys.stdout.write(".")
            else:
                sys.stdout.write(line)
            sys.stdout.flush()
        if not os.path.exists(self.name+".cab"):
            raise IOError, "cabarc failed"
        add_data(db, "Media",
                [(1, self.index, None, "#"+self.name, None, None)])
        add_stream(db, self.name, self.name+".cab")
        os.unlink(self.name+".txt")
        os.unlink(self.name+".cab")
        db.Commit()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号