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/02 23:35:40 UTC
svn commit: r981691 - in /labs/mouse: match.py mouse.py
Author: hwright
Date: Mon Aug 2 21:35:39 2010
New Revision: 981691
URL: http://svn.apache.org/viewvc?rev=981691&view=rev
Log:
Factor out the match-determining code for mouse into a separate file, with the
nebulous UnknownResult being the only contents for now.
Added:
labs/mouse/match.py
Modified:
labs/mouse/mouse.py
Added: labs/mouse/match.py
URL: http://svn.apache.org/viewvc/labs/mouse/match.py?rev=981691&view=auto
==============================================================================
--- labs/mouse/match.py (added)
+++ labs/mouse/match.py Mon Aug 2 21:35:39 2010
@@ -0,0 +1,52 @@
+#!/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.
+#
+'''The match module for Mouse.'''
+
+
+
+class UnknownResult(object):
+
+ def __init__(self):
+ self.header_name = '?????'
+ self.license_family = '?????'
+ self.license_approved = False
+ self.type_name = 'standard'
+
+ @staticmethod
+ def match(content):
+ return True
+
+
+_match_order = [
+ # we don't need UnknownResult in this list, since it will be returned
+ # from do_match() by default.
+ # UnknownResult,
+ ]
+
+
+def do_match(item):
+ '''Check each of the classes in _match_order, using it's match() method, and
+ if the content of item matches that class, instantiate and return the
+ result.'''
+ for m in _match_order:
+ if m.match(item.get_content()):
+ return m()
+
+ return UnknownResult()
Modified: labs/mouse/mouse.py
URL: http://svn.apache.org/viewvc/labs/mouse/mouse.py?rev=981691&r1=981690&r2=981691&view=diff
==============================================================================
--- labs/mouse/mouse.py (original)
+++ labs/mouse/mouse.py Mon Aug 2 21:35:39 2010
@@ -39,6 +39,7 @@ import optparse
import xml.etree.cElementTree as ElementTree
import sources
+import match
# Some constants
@@ -47,15 +48,6 @@ VERSION = '0.1'
resources_path = os.path.join(sys.path[0], 'resources')
-class Result(object):
-
- def __init__(self):
- self.header_name = '?????'
- self.license_family = '?????'
- self.license_approved = False
- self.type_name = 'standard'
-
-
class Resource(object):
def __init__(self, item, result):
@@ -97,7 +89,7 @@ def generate_report(items):
def report_generator():
for item in items():
- yield Resource(item, Result())
+ yield Resource(item, match.do_match(item))
return report_generator
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org