From 0c8583c05cedcbcf98cdda684b614a6a97055de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ylt=E5=A7=9A=E5=85=B0=E5=A4=A9?= Date: Tue, 23 Jun 2015 17:51:25 +0800 Subject: [PATCH] add file size diff --- .gitignore | 3 +++ file/__init__.py | 2 ++ file/size_diff.py | 15 +++++++++++++++ file/size_diff_test.py | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 file/__init__.py create mode 100644 file/size_diff.py create mode 100644 file/size_diff_test.py diff --git a/.gitignore b/.gitignore index ba74660..e798bb1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ __pycache__/ # C extensions *.so +# IDE config +.idea/ + # Distribution / packaging .Python env/ diff --git a/file/__init__.py b/file/__init__.py new file mode 100644 index 0000000..550c49c --- /dev/null +++ b/file/__init__.py @@ -0,0 +1,2 @@ +# -*- coding:utf8 -*- +__author__ = 'ltyao' diff --git a/file/size_diff.py b/file/size_diff.py new file mode 100644 index 0000000..f9b9391 --- /dev/null +++ b/file/size_diff.py @@ -0,0 +1,15 @@ +# -*- coding:utf8 -*- +__author__ = 'ltyao' +import os +from os.path import join, getsize + + +def cmp_size(left_dir, right_dir): + for root, dirs, files in os.walk(left_dir): + for file_name in files: + left = getsize(join(root, file_name)) + right = getsize(join(root.replace(left_dir, right_dir), file_name)) + if cmp(left, right) != 0: + print root, file_name, left - right + + diff --git a/file/size_diff_test.py b/file/size_diff_test.py new file mode 100644 index 0000000..177b16c --- /dev/null +++ b/file/size_diff_test.py @@ -0,0 +1,19 @@ +__author__ = 'ltyao' + +import unittest +from size_diff import cmp_size + + +class SizeTestCase(unittest.TestCase): + def setUp(self): + self.left_dir = "D:\Users\ltyao\PycharmProjects\untitled5\NET_1367635\ws.mobilesecure.payment.soa2\payment" + self.right_dir = "D:\Users\ltyao\PycharmProjects\untitled5\NET_1368884\ws.mobilesecure.payment.soa2\payment" + + def test_echo(self): + cmp_size(self.left_dir, self.right_dir) + print("--------------------") + cmp_size(self.right_dir, self.left_dir) + + +if __name__ == '__main__': + unittest.main()