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 17:00:56 UTC
svn commit: r982284 - in /labs/mouse: guesser/__init__.py guesser/notice.py
match.py tests/test_mouse.py
Author: hwright
Date: Wed Aug 4 15:00:56 2010
New Revision: 982284
URL: http://svn.apache.org/viewvc?rev=982284&view=rev
Log:
Implement notice file detection (with an accompanying test).
Added:
labs/mouse/guesser/notice.py
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=982284&r1=982283&r2=982284&view=diff
==============================================================================
--- labs/mouse/guesser/__init__.py (original)
+++ labs/mouse/guesser/__init__.py Wed Aug 4 15:00:56 2010
@@ -23,6 +23,10 @@ Helper methods are defined here so that
module, rather than all the child modules.'''
import binary
+import notice
def is_binary(item):
return binary.is_binary(item)
+
+def is_notice(item):
+ return notice.is_binary(item)
Added: labs/mouse/guesser/notice.py
URL: http://svn.apache.org/viewvc/labs/mouse/guesser/notice.py?rev=982284&view=auto
==============================================================================
--- labs/mouse/guesser/notice.py (added)
+++ labs/mouse/guesser/notice.py Wed Aug 4 15:00:56 2010
@@ -0,0 +1,53 @@
+#!/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 a notice.'''
+
+import os
+
+_notice_names = [ 'NOTICE', 'LICENSE', 'LICENSE.TXT', 'NOTICE.TXT', 'INSTALL',
+ 'INSTALL.TXT', 'README', 'README.TXT', 'NEWS', 'NEWS.TXT', 'AUTHOR',
+ 'AUTHOR.TXT', 'AUTHORS', 'AUTHORS.txt', 'CHANGELOG', 'CHANGELOG.TXT',
+ 'DISCLAIMER', 'DISCLAIMER.TXT', 'KEYS', 'KEYS.TXT', 'RELEASE-NOTES',
+ 'RELEASE-NOTES.TXT', 'RELEASE_NOTES', 'RELEASE_NOTES.TXT', 'UPGRADE',
+ 'UPGRADE.TXT', 'STATUS', 'STATUS.TXT', 'THIRD_PARTY_NOTICES',
+ 'THIRD_PARTY_NOTICES.TXT', 'COPYRIGHT', 'COPYRIGHT.TXT', 'BUILDING',
+ 'BUILDING.TXT', 'BUILD', 'BUILT.TXT',
+ ]
+
+_notice_exts = [ 'LICENSE', 'LICENSE.TXT', 'NOTICE', 'NOTICE.TXT',
+ ]
+
+
+def is_binary(item):
+ '''Entry method, will return True if ITEM is thought to be a notice,
+ False otherwise.'''
+
+ # Just look a the filename
+ (dirname, basename) = os.path.split(item.name)
+ if basename.upper() in _notice_names:
+ return True
+
+ # now look at the extensions
+ for ext in _notice_exts:
+ if basename.endswith('.' + ext):
+ return True
+
+ # we've exhausted our options, so this file must not be a notice
+ return False
Modified: labs/mouse/match.py
URL: http://svn.apache.org/viewvc/labs/mouse/match.py?rev=982284&r1=982283&r2=982284&view=diff
==============================================================================
--- labs/mouse/match.py (original)
+++ labs/mouse/match.py Wed Aug 4 15:00:56 2010
@@ -51,7 +51,7 @@ class BinaryResult(object):
_match_order = [
- ( lambda x: False, NoticeResult ),
+ ( guesser.is_notice, NoticeResult ),
( lambda x: False, ArchiveResult ),
( guesser.is_binary, BinaryResult ),
Modified: labs/mouse/tests/test_mouse.py
URL: http://svn.apache.org/viewvc/labs/mouse/tests/test_mouse.py?rev=982284&r1=982283&r2=982284&view=diff
==============================================================================
--- labs/mouse/tests/test_mouse.py (original)
+++ labs/mouse/tests/test_mouse.py Wed Aug 4 15:00:56 2010
@@ -162,6 +162,19 @@ class TestBinaryGuessing(unittest.TestCa
'elements', 'NOTICE')))))
+class TestNoticeGuessing(unittest.TestCase):
+ '''Test to see if we recognize various notice files.'''
+
+ _names = [ 'LICENSE', 'LICENSE.TXT', 'NOTICE', 'NOTICE.TXT', 'README',
+ 'README.TXT' ]
+
+ def test_is_notice(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_notice(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