From 1bb8abef14af4690385aeb1185a52d5456ec11d8 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 11 Dec 2011 17:12:23 +0100 Subject: Handle files with stupid rights Now, files that are not readable, or writatble, or non-existent are correctly handled. --- mat-cli | 4 +++- mat/mat.py | 16 +++++++++++++--- test/clitest.py | 21 +++++++++++++++++++++ test/libtest.py | 13 +++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/mat-cli b/mat-cli index 00c5c11..253ea96 100755 --- a/mat-cli +++ b/mat-cli @@ -152,8 +152,10 @@ def main(): for filename in filenames: class_file = mat.create_class_file(filename, args.backup, args.add2archive) - if class_file is not None: + if class_file is not False: func(class_file, filename, args.force) + else: + print('Unable to process %s' % filename) if __name__ == '__main__': main() diff --git a/mat/mat.py b/mat/mat.py index dfd4c12..0c3f050 100644 --- a/mat/mat.py +++ b/mat/mat.py @@ -108,7 +108,17 @@ def create_class_file(name, backup, add2archive): if not os.path.isfile(name): # check if the file exists logging.error('%s is not a valid file' % name) - return + return False + + if not os.access(name, os.R_OK): + #check read permissions + logging.error('%s is is not readable' % name) + return False + + if not os.access(name, os.W_OK): + #check write permission + logging.error('%s is not writtable' % name) + return False filename = '' try: @@ -119,7 +129,7 @@ def create_class_file(name, backup, add2archive): parser = hachoir_parser.createParser(filename) if not parser: logging.info('Unable to parse %s' % filename) - return + return False mime = parser.mime_type @@ -135,6 +145,6 @@ def create_class_file(name, backup, add2archive): stripper_class = strippers.STRIPPERS[mime] except KeyError: logging.info('Don\'t have stripper for %s format' % mime) - return + return False return stripper_class(filename, parser, mime, backup, add2archive) diff --git a/test/clitest.py b/test/clitest.py index cb615ce..db54843 100644 --- a/test/clitest.py +++ b/test/clitest.py @@ -72,6 +72,27 @@ class TestisCleancli(test.MATTest): stdout, _ = proc.communicate() self.assertEqual(stdout.strip('\n'), '[+] %s is not clean' % dirty) +class TestFileAttributes(unittest.TestCase): + ''' + test various stuffs about files (readable, writable, exist, ...) + ''' + def test_not_readable(self): + proc = subprocess.Popen(['../mat-cli', 'not_readable'], + stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + self.assertEqual(stdout.strip('\n'), 'Unable to pocess %s' % 'not_readable') + + def test_not_writtable(self): + proc = subprocess.Popen(['../mat-cli', 'not_writtable'], + stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + self.assertEqual(stdout.strip('\n'), 'Unable to pocess %s' % 'not_writtable') + + def test_not_exist(self): + proc = subprocess.Popen(['../mat-cli', 'ilikecookies'], + stdout=subprocess.PIPE) + stdout, _ = proc.communicate() + self.assertEqual(stdout.strip('\n'), 'Unable to pocess %s' % 'ilikecookies') if __name__ == '__main__': suite = unittest.TestSuite() diff --git a/test/libtest.py b/test/libtest.py index ecbc03e..0df584f 100644 --- a/test/libtest.py +++ b/test/libtest.py @@ -64,11 +64,24 @@ class TestisCleanlib(test.MATTest): current_file = mat.create_class_file(clean, False, True) self.assertTrue(current_file.is_clean()) +class TestFileAttributes(unittest.TestCase): + ''' + test various stuffs about files (readable, writable, exist, ...) + ''' + def test_not_readable(self): + self.assertFalse(mat.create_class_file('not_readable', False, True)) + + def test_not_writtable(self): + self.assertFalse(mat.create_class_file('not_writtable', False, True)) + + def test_not_exist(self): + self.assertFalse(mat.create_class_file('ilikecookies', False, True)) if __name__ == '__main__': Suite = unittest.TestSuite() Suite.addTest(unittest.makeSuite(TestRemovelib)) Suite.addTest(unittest.makeSuite(TestListlib)) Suite.addTest(unittest.makeSuite(TestisCleanlib)) + Suite.addTest(unittest.makeSuite(TestFileAttributes)) unittest.TextTestRunner(verbosity=test.VERBOSITY).run(Suite) -- cgit v1.3 From d7cf13ec8bc08825b17192568500162715077ecc Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 11 Dec 2011 18:34:58 +0100 Subject: Now testsuites have a return code --- test/clitest.py | 4 +++- test/libtest.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/clitest.py b/test/clitest.py index db54843..4155d45 100644 --- a/test/clitest.py +++ b/test/clitest.py @@ -99,4 +99,6 @@ if __name__ == '__main__': suite.addTest(unittest.makeSuite(TestRemovecli)) suite.addTest(unittest.makeSuite(TestListcli)) suite.addTest(unittest.makeSuite(TestisCleancli)) - unittest.TextTestRunner(verbosity=test.VERBOSITY).run(suite) + test_result = unittest.TextTestRunner(verbosity=test.VERBOSITY).run(suite) + sys.exit(len(test_result.failures)) + diff --git a/test/libtest.py b/test/libtest.py index 0df584f..1afabd9 100644 --- a/test/libtest.py +++ b/test/libtest.py @@ -75,7 +75,8 @@ class TestFileAttributes(unittest.TestCase): self.assertFalse(mat.create_class_file('not_writtable', False, True)) def test_not_exist(self): - self.assertFalse(mat.create_class_file('ilikecookies', False, True)) + #self.assertFalse(mat.create_class_file('ilikecookies', False, True)) + self.assertTrue(mat.create_class_file('ilikecookies', False, True)) if __name__ == '__main__': Suite = unittest.TestSuite() @@ -83,5 +84,6 @@ if __name__ == '__main__': Suite.addTest(unittest.makeSuite(TestListlib)) Suite.addTest(unittest.makeSuite(TestisCleanlib)) Suite.addTest(unittest.makeSuite(TestFileAttributes)) - unittest.TextTestRunner(verbosity=test.VERBOSITY).run(Suite) + test_result = unittest.TextTestRunner(verbosity=test.VERBOSITY).run(Suite) + sys.exit(len(test_result.failures)) -- cgit v1.3 From 6b2de70ebc205a1b17c7c7a2db5401b0be87d778 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 11 Dec 2011 18:35:25 +0100 Subject: Update TODO --- TODO | 7 ------- 1 file changed, 7 deletions(-) diff --git a/TODO b/TODO index 05749dd..b509f83 100644 --- a/TODO +++ b/TODO @@ -5,16 +5,9 @@ GENERAL: - Fix the ugly function get_sharedir - Modify creation/modification date (except for stupid formats like zip) - - better log management - - cleaning a file (mat-gui) in a directory where you have no write - permission : pretend a cleaned file was created which is wrong ! - -TESTSUITE: - - return code ? GUI: - display harmrful meta per file - - drag'n'drop does not work with filenames containing spaces FORMATS - microsoft office < 2007 (ugly and insane) -- cgit v1.3 From 0e3b12c856d4ab026fd7741626be79da0dbfff65 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 12 Dec 2011 20:22:20 +0100 Subject: Update changelog --- CHANGELOG | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index af0f58e..53309fb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,9 @@ +0.2 - 21dec2011 + * Improvements for testsuites + * Improve log system + * Handle file with weird rights + * Drag'n'drop support + * Various bugfixes + 0.1 - 30oct2011 * initial version -- cgit v1.3 From 47fcf3a0715143358b453f92807a519162a97f58 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 12 Dec 2011 20:22:35 +0100 Subject: Update release's process --- RELEASE | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RELEASE b/RELEASE index f5b97ed..376900b 100644 --- a/RELEASE +++ b/RELEASE @@ -1,3 +1,9 @@ +update changelog: + git log + +create a tag + git tag -s $VERSION + archive's creation : git archive --format=tar.gz --prefix=mat-$VERSION/ $VERSION > mat-$VERSION.tar.gz -- cgit v1.3 From bb41ac16339e9138587921629b8b9e4336ea10a6 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 13 Dec 2011 13:59:13 +0100 Subject: Oops, forgot a debug instruction A debug instruction was making a test fail : it's now fixed --- test/libtest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/libtest.py b/test/libtest.py index 1afabd9..bfeb548 100644 --- a/test/libtest.py +++ b/test/libtest.py @@ -75,8 +75,7 @@ class TestFileAttributes(unittest.TestCase): self.assertFalse(mat.create_class_file('not_writtable', False, True)) def test_not_exist(self): - #self.assertFalse(mat.create_class_file('ilikecookies', False, True)) - self.assertTrue(mat.create_class_file('ilikecookies', False, True)) + self.assertFalse(mat.create_class_file('ilikecookies', False, True)) if __name__ == '__main__': Suite = unittest.TestSuite() -- cgit v1.3 From 13f102b65c8cf9981b2925495b95d20047b3932f Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 13 Dec 2011 16:14:03 +0100 Subject: Update todo --- TODO | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index b509f83..5ccf195 100644 --- a/TODO +++ b/TODO @@ -9,7 +9,10 @@ GENERAL: GUI: - display harmrful meta per file -FORMATS +FORMATS: - microsoft office < 2007 (ugly and insane) - fix zip (fix python's ziplib) - videos format ? + +MISC: + - a nautilus extension (right-clic -> clean with MAT) -- cgit v1.3