utils.py 文件源码

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

项目:sketch-components 作者: ibhubs 项目源码 文件源码
def print_file_diffs(self):
        for name in self.diff_files:
            if name.split('.') and name.split('.')[-1] in ['js', 'txt', 'html',
                                                           'json', 'css']:
                d = difflib.Differ()
                left_lines = open(os.path.join(self.left, name)).readlines()
                right_lines = open(os.path.join(self.right, name)).readlines()
                result = d.compare(left_lines, right_lines)
                print("Diff between files {} and {}".format(
                    os.path.join(self.left, name),
                    os.path.join(self.right, name)))
                print("")
                sys.stdout.writelines(result)
            else:
                left_sha1 = hashlib.sha1(
                    open(os.path.join(self.left, name)).read()).hexdigest()
                right_sha1 = hashlib.sha1(
                    open(os.path.join(self.right, name)).read()).hexdigest()
                if left_sha1 != right_sha1:
                    print("Shasum mismatch between files {} and {}".format(
                        os.path.join(self.left, name),
                        os.path.join(self.right, name)))
        for name in self.left_only:
            print("Expected file {} not generated.".format(
                os.path.join(self.left, name)))
        for name in self.right_only:
            print("Unexpected file {} generated.".format(
                os.path.join(self.right, name)))
        for name in self.funny_files:
            print("Could not read the file {}".format(name))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号