You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by hw...@apache.org on 2010/08/04 22:26:28 UTC
svn commit: r982392 - in /labs/mouse: guesser/__init__.py guesser/archive.py
match.py tests/data/expected_output/archive
tests/data/expected_output/archive.xml tests/test_mouse.py
Author: hwright
Date: Wed Aug 4 20:26:28 2010
New Revision: 982392
URL: http://svn.apache.org/viewvc?rev=982392&view=rev
Log:
Add archive recognition capabilities to Mouse, along with some tests of same.
Added:
labs/mouse/guesser/archive.py
labs/mouse/tests/data/expected_output/archive
labs/mouse/tests/data/expected_output/archive.xml
Modified:
labs/mouse/guesser/__init__.py
labs/mouse/match.py
labs/mouse/tests/test_mouse.py
Modified: labs/mouse/guesser/__init__.py
URL: http://svn.apache.org/viewvc/labs/mouse/guesser/__init__.py?rev=982392&r1=982391&r2=982392&view=diff
==============================================================================
--- labs/mouse/guesser/__init__.py (original)
+++ labs/mouse/guesser/__init__.py Wed Aug 4 20:26:28 2010
@@ -24,9 +24,13 @@ module, rather than all the child module
import binary
import notice
+import archive
def is_binary(item):
return binary.is_binary(item)
def is_notice(item):
return notice.is_notice(item)
+
+def is_archive(item):
+ return archive.is_archive(item)
Added: labs/mouse/guesser/archive.py
URL: http://svn.apache.org/viewvc/labs/mouse/guesser/archive.py?rev=982392&view=auto
==============================================================================
--- labs/mouse/guesser/archive.py (added)
+++ labs/mouse/guesser/archive.py Wed Aug 4 20:26:28 2010
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+'''Module to determine if a file with given content is an archive.'''
+
+import os
+
+_archive_exts = [ 'jar', 'gz', 'zip', 'tar', 'bz', 'bz2', 'rar', 'war',
+ ]
+
+
+def is_archive(item):
+ '''Entry method, will return True if ITEM is thought to be a notice,
+ False otherwise.'''
+
+ (dirname, basename) = os.path.split(item.name)
+
+ # Look at the extensions
+ for ext in _archive_exts:
+ if basename.endswith('.' + ext):
+ return True
+
+ ### TODO: We could actually look at the file contents, see
+ ### zipfile.is_zipfile() and tarfile.is_tarfile().
+
+ # we've exhausted our options, so this file must not be an archive
+ return False
Modified: labs/mouse/match.py
URL: http://svn.apache.org/viewvc/labs/mouse/match.py?rev=982392&r1=982391&r2=982392&view=diff
==============================================================================
--- labs/mouse/match.py (original)
+++ labs/mouse/match.py Wed Aug 4 20:26:28 2010
@@ -52,7 +52,7 @@ class BinaryResult(object):
_match_order = [
( guesser.is_notice, NoticeResult ),
- ( lambda x: False, ArchiveResult ),
+ ( guesser.is_archive, ArchiveResult ),
( guesser.is_binary, BinaryResult ),
# we don't need UnknownResult in this list, since it will be returned
Added: labs/mouse/tests/data/expected_output/archive
URL: http://svn.apache.org/viewvc/labs/mouse/tests/data/expected_output/archive?rev=982392&view=auto
==============================================================================
--- labs/mouse/tests/data/expected_output/archive (added)
+++ labs/mouse/tests/data/expected_output/archive Wed Aug 4 20:26:28 2010
@@ -0,0 +1,39 @@
+
+*****************************************************
+Summary
+-------
+Notes: 0
+Binaries: 0
+Archives: 1
+Standards: 0
+
+Apache Licensed: 0
+Generated Documents: 0
+
+JavaDocs are generated and so license header is optional
+Generated files do not required license headers
+
+0 Unknown Licenses
+
+*******************************
+
+Unapproved licenses:
+
+
+*******************************
+
+Archives:
+
+ + data/rat-tests/artifacts/dummy.tar.gz
+
+*****************************************************
+ Files with Apache License headers will be marked AL
+ Binary files (which do not require AL headers) will be marked B
+ Compressed archives will be marked A
+ Notices, licenses etc will be marked N
+ A data/rat-tests/artifacts/dummy.tar.gz
+
+ *****************************************************
+ Printing headers for files without AL header...
+
+
\ No newline at end of file
Added: labs/mouse/tests/data/expected_output/archive.xml
URL: http://svn.apache.org/viewvc/labs/mouse/tests/data/expected_output/archive.xml?rev=982392&view=auto
==============================================================================
--- labs/mouse/tests/data/expected_output/archive.xml (added)
+++ labs/mouse/tests/data/expected_output/archive.xml Wed Aug 4 20:26:28 2010
@@ -0,0 +1 @@
+<rat-report><resource name='data/rat-tests/artifacts/dummy.tar.gz'><type name='archive'/></resource></rat-report>
\ No newline at end of file
Modified: labs/mouse/tests/test_mouse.py
URL: http://svn.apache.org/viewvc/labs/mouse/tests/test_mouse.py?rev=982392&r1=982391&r2=982392&view=diff
==============================================================================
--- labs/mouse/tests/test_mouse.py (original)
+++ labs/mouse/tests/test_mouse.py Wed Aug 4 20:26:28 2010
@@ -129,6 +129,13 @@ class TestReport(unittest.TestCase):
def test_binary(self):
self._check_plain_output(os.path.join('rat-tests', 'binaries'), 'binaries')
+ def test_archive_xml(self):
+ self._check_xml_output(os.path.join('rat-tests', 'artifacts'),
+ 'archive.xml')
+
+ def test_archive(self):
+ self._check_plain_output(os.path.join('rat-tests', 'artifacts'), 'archive')
+
# def test_rat_xml(self):
# self._check_xml_output('rat-tests', 'rat-tests.xml')
#
@@ -175,6 +182,17 @@ class TestNoticeGuessing(unittest.TestCa
self.assertTrue(guesser.is_notice(sources.Item(name, None)))
+class TestArchiveGuessing(unittest.TestCase):
+
+ _names = [ '42.jar', '42.tar.gz', '42.zip', '42.tar', '42.bz', '42.bz2' ]
+
+ def test_is_archive(self):
+ for name in self._names:
+ # Don't bother giving the item contents, since we shouldn't ever
+ # have to check the content, anyway
+ self.assertTrue(guesser.is_archive(sources.Item(name, None)))
+
+
class TestFilters(unittest.TestCase):
'Test filtering various files and patterns'
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org