incubator-rat-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r1190530 - in /incubator/rat/eye/trunk: apache-rat-eye-license-and-notice.py apache-rat-eye-manifest.py apache-rat-eye-meta-inf.py org/apache/rat/eye/engine.py org/apache/rat/eye/eye.py
Date Fri, 28 Oct 2011 20:06:25 GMT
Author: rdonkin
Date: Fri Oct 28 20:06:24 2011
New Revision: 1190530

URL: http://svn.apache.org/viewvc?rev=1190530&view=rev
Log:
Factor out high level module

Added:
    incubator/rat/eye/trunk/org/apache/rat/eye/eye.py
      - copied, changed from r1147459, incubator/rat/eye/trunk/org/apache/rat/eye/engine.py
Modified:
    incubator/rat/eye/trunk/apache-rat-eye-license-and-notice.py
    incubator/rat/eye/trunk/apache-rat-eye-manifest.py
    incubator/rat/eye/trunk/apache-rat-eye-meta-inf.py
    incubator/rat/eye/trunk/org/apache/rat/eye/engine.py

Modified: incubator/rat/eye/trunk/apache-rat-eye-license-and-notice.py
URL: http://svn.apache.org/viewvc/incubator/rat/eye/trunk/apache-rat-eye-license-and-notice.py?rev=1190530&r1=1190529&r2=1190530&view=diff
==============================================================================
--- incubator/rat/eye/trunk/apache-rat-eye-license-and-notice.py (original)
+++ incubator/rat/eye/trunk/apache-rat-eye-license-and-notice.py Fri Oct 28 20:06:24 2011
@@ -24,13 +24,13 @@ Scripts a basic report on META-INF.
 import os.path
 import sys
 
-from org.apache.rat.eye import engine
+from org.apache.rat.eye import eye
 from org.apache.rat.eye import review
 from org.apache.rat.eye import style
 
 def runBasicReport(base):
     if os.path.exists(base):
-        engine.report(base, review.checkLicenseAndNotice(), style.simplePrint())
+        eye.report(base, review.checkLicenseAndNotice(), style.simplePrint())
         sys.exit(0)
     else:
         sys.stderr.write("Base directory '{0}' not found\n".format(base))

Modified: incubator/rat/eye/trunk/apache-rat-eye-manifest.py
URL: http://svn.apache.org/viewvc/incubator/rat/eye/trunk/apache-rat-eye-manifest.py?rev=1190530&r1=1190529&r2=1190530&view=diff
==============================================================================
--- incubator/rat/eye/trunk/apache-rat-eye-manifest.py (original)
+++ incubator/rat/eye/trunk/apache-rat-eye-manifest.py Fri Oct 28 20:06:24 2011
@@ -24,13 +24,13 @@ Scripts a basic report on jar manifests.
 import os.path
 import sys
 
-from org.apache.rat.eye import engine
+from org.apache.rat.eye import eye
 from org.apache.rat.eye import review
 from org.apache.rat.eye import style
 
 def runBasicReport(base):
     if os.path.exists(base):
-        engine.report(base, review.ManifestReportBuilder().build(), style.simplePrint())
+        eye.report(base, review.ManifestReportBuilder().build(), style.simplePrint())
         sys.exit(0)
     else:
         sys.stderr.write("Base directory '{0}' not found\n".format(base))

Modified: incubator/rat/eye/trunk/apache-rat-eye-meta-inf.py
URL: http://svn.apache.org/viewvc/incubator/rat/eye/trunk/apache-rat-eye-meta-inf.py?rev=1190530&r1=1190529&r2=1190530&view=diff
==============================================================================
--- incubator/rat/eye/trunk/apache-rat-eye-meta-inf.py (original)
+++ incubator/rat/eye/trunk/apache-rat-eye-meta-inf.py Fri Oct 28 20:06:24 2011
@@ -24,13 +24,13 @@ Scripts a basic report on META-INF.
 import os.path
 import sys
 
-from org.apache.rat.eye import engine
+from org.apache.rat.eye import eye
 from org.apache.rat.eye import style
 from org.apache.rat.eye import review
 
 def runBasicReport(base):
     if os.path.exists(base):
-        engine.report(base, review.presentMetaInf(), style.simplePrint())
+        eye.report(base, review.presentMetaInf(), style.simplePrint())
         sys.exit(0)
     else:
         sys.stderr.write("Base directory '{0}' not found\n".format(base))

Modified: incubator/rat/eye/trunk/org/apache/rat/eye/engine.py
URL: http://svn.apache.org/viewvc/incubator/rat/eye/trunk/org/apache/rat/eye/engine.py?rev=1190530&r1=1190529&r2=1190530&view=diff
==============================================================================
--- incubator/rat/eye/trunk/org/apache/rat/eye/engine.py (original)
+++ incubator/rat/eye/trunk/org/apache/rat/eye/engine.py Fri Oct 28 20:06:24 2011
@@ -27,15 +27,6 @@ import os.path
 import zipfile
 
 #
-# High Level
-#
-
-def report(directory, checks, styles):
-    Reporter(styles).report(
-        Reviewer(checks).review(
-            AccumulativeScanner(directory).scan().findings))
-
-#
 # Utilities
 #
 

Copied: incubator/rat/eye/trunk/org/apache/rat/eye/eye.py (from r1147459, incubator/rat/eye/trunk/org/apache/rat/eye/engine.py)
URL: http://svn.apache.org/viewvc/incubator/rat/eye/trunk/org/apache/rat/eye/eye.py?p2=incubator/rat/eye/trunk/org/apache/rat/eye/eye.py&p1=incubator/rat/eye/trunk/org/apache/rat/eye/engine.py&r1=1147459&r2=1190530&rev=1190530&view=diff
==============================================================================
--- incubator/rat/eye/trunk/org/apache/rat/eye/engine.py (original)
+++ incubator/rat/eye/trunk/org/apache/rat/eye/eye.py Fri Oct 28 20:06:24 2011
@@ -18,350 +18,19 @@
 #
 
 """
-Drives model creation.
+High level API.
 """
 
-import os
-import logging
-import os.path
-import zipfile
+from org.apache.rat.eye import engine
+from org.apache.rat.eye import review
+from org.apache.rat.eye import style
 
 #
 # High Level
 #
 
 def report(directory, checks, styles):
-    Reporter(styles).report(
-        Reviewer(checks).review(
-            AccumulativeScanner(directory).scan().findings))
-
-#
-# Utilities
-#
-
-def isHidden(dir):
-    """
-    Is this directory path hidden by it's name
-    or the name of a parent directory?
-    """
-    if dir == "" or dir ==".":
-        return False
-    else:
-        head, tail = os.path.split(dir)
-        if tail.startswith('.') and not(tail.startswith('..')):
-            return True
-        elif head == "":
-            return False
-        else:
-            return isHidden(head)    
-
-
-def root(filename):
-    """
-    Extracts the root of the name:
-    the part before the first dot.
-    """
-    root = filename
-    extension = filename
-    while not (extension == None or extension == ""):
-        (root, extension) = os.path.splitext(root)
-    return root
-
-def extension(filename):
-    """
-    Extracts the extension:
-    the part after the first dot.
-    
-    Result does not contain a leading dot, for example
-    
-    >>> org.apache.rat.eye.engine.extension("archive.tar.gz")
-    'tar.gz'
-
-    and not '.tar.gz'.
-    
-    """
-    root = filename
-    extension = filename
-    # First time case assumes result starts None
-    result = None
-    while not (extension == None or extension == ""):
-        (root, extension) = os.path.splitext(root)
-        if (result == None):
-            # First time 
-            result = extension
-        else:
-            result = extension + result
-        
-    if (result == None):
-        result = ""
-    # Prune any trailing or leading dots
-    return result.strip('.')
-    
-def contentFromZip(resource, names):
-    """
-    Reads contents indexed by name from a zip archive.
-    
-    return: dictionary indexing lines read from a document by its name
-    rtype: dict
-    """
-    if (hasattr(resource, "open")):
-        # Assume it's a ZipFile
-        return dict((name, resource.open(name).readlines()) for name in names)
-    else:
-        zip = zipfile.ZipFile(resource, "r")
-        try:
-            return readContentFromZip(zip)
-        finally:
-            zip.close()
-
-def filterContentFromZip(resource, selectionFunction=None):
-    """
-    Reads names from zip archive, with optional filtering.
-    
-    return: dictionary indexing lines read from a document by its name
-    rtype: dict
-    """
-    if (hasattr(resource, "open")):
-        # Assume it's a ZipFile
-        return contentFromZip(resource, filter(selectionFunction, resource.namelist()))
-    else:
-        zip = zipfile.ZipFile(resource, "r")
-        try:
-            return filterContentFromZip(zip, selectionFunction)
-        finally:
-            zip.close()    
-    
-def readContentsFromDirectoryInZip(resource, directory):
-    """
-    Reads names from zip archive, with optional filtering.
-    
-    return: dictionary indexing lines read from a document by its name
-    rtype: dict
-    """
-    return filterContentFromZip(resource,
-                                lambda name:
-                                    os.path.dirname(name) == directory and not
-                                    name == directory and not
-                                    name == directory + "/")
-    
-#
-# Builders
-#
-
-def buildJar(name, path='.', filenames=[]):
-    """
-    return: A Jar archive when appropriate, None otherwise
-    rtype: Jar, or None
-    """
-    suffix = extension(name).lower()
-    if suffix == "jar" or (not(suffix is None) and suffix.endswith(".jar")):
-        return Jar(path, name)
-    else:
-        return None
-    
-    
-def buildArtifact(name, path='.', filenames=[]):
-    """
-    return: A Jar when appropriate, None otherwise
-    rtype: Jar, or None    
-    """
-    return buildJar(name, path, filenames)
-    
-def listArtifacts(path, filenames):
-    """
-    Builds a list of primary relese artifacts from the given files.
-    
-    return: list of artifacts
-    rtype: appropriate Artifact type
-    """
-    # Filter out None from list of artifacts built
-    return filter(None, [buildArtifact(name, path, filenames) for name in filenames])
-    
-def reportOn(list, reviewer):
-    for item in list:
-        if (hasattr(item, "reportTo")):
-            item.reportTo(reviewer)
-
-#
-# Classes
-#
-
-class Scanner():
-    """
-    Scans a directory structure.
-    With support for directory hiding.
-    Reports results by calling found.
-    Base class simply logs at debug.
-    """
-    def __init__(self, baseDirectory='.', logger = logging.getLogger()):
-        self.baseDirectory = baseDirectory
-        self.logger = logger
-        
-    def scan(self):
-        self.logger.debug("Starting to scan %s", self.baseDirectory)
-        for directory, subdirectories, files in os.walk(self.baseDirectory):
-            self.logger.debug("Scanning %s", directory)
-            model = Directory(directory, files)
-            if self.ignoreDirectory(model):
-                self.logger.debug("Ignoring %s", directory)
-            else:
-                self.logger.debug("Found directory %s", directory)
-                self.found(model, files)
-                
-        return self
-    
-    def found(self, directory, files):
-        self.logger.debug("In %s are $s", directory.path, files)
-        
-    def ignoreDirectory(self, directory):
-        """
-        Is this directory to be ignored?
-        """
-        return directory.isHidden()    
-
-class AccumulativeScanner(Scanner):
-    """
-    Accumulates list of findings.
-    """
-    def __init__(self, baseDirectory='.', logger = logging.getLogger()):
-        Scanner.__init__(self,baseDirectory, logger)
-        self.findings = []
-        
-    def found(self, directory, files):
-        Scanner.found(self, directory, files)
-        if not (Directory is None or self.findings is None):
-            self.findings.append(directory)            
-    
-class Reporter():
-    """
-    Aggregates and renders reports.
-    """
-    def __init__(self, styles = []):
-        self.styles = styles
-        
-    def report(self, list):   
-        return [style.present(resource) for style in self.styles for resource in list]
-    
-class Reviewer():
-    """
-    Reviews artifacts.
-    """
-    def __init__(self, reviews = []):
-        self.reviews = reviews
-        
-    def review(self, list):
-        for item in list:
-            if (hasattr(item, "reportTo")):
-                for review in self.reviews:
-                    item.reportTo(review)
-        return list
-    
-class Reports():
-    """
-    Collects reports.
-    """
-    def __init__(self, moniker):
-        self.reports = []
-        self.moniker = moniker
-        
-    def addReports(self, reports):
-        if reports:
-            try:
-                self.reports.extend(filter(None, reports))
-            except TypeError:
-                # Most likely not a sequence
-                self.reports.append(reports)
-        return self
-    
-    def subreports(self):
-        return []
-    
-class Directory(Reports):
-    """
-    Models a directory within some structure.
-    """
-    
-    def __init__(self, path, files=[]):
-        Reports.__init__(self, path)
-        self.path = path
-        self.files = files
-        self.artifacts = listArtifacts(self.path, self.files)
-        
-    def isHidden(self):
-        return isHidden(self.path)
-        
-    def reportTo(self, reviewer):
-        if (hasattr(reviewer, "reviewDirectory")):
-            reviewer.reviewDirectory(self)
-        for artifact in self.artifacts:
-            artifact.reportTo(reviewer)
-            
-    def subreports(self):
-        return self.artifacts
-    
-    def __repr__(self):
-        return "directory:path='" + self.path + "'"
-
-class Artifact(Reports):
-    """
-    A primary release artifact.
-    The architype is a compressed archive.
-    A checksum is an architypal secondary release artifact.
-    """
-
-    def __init__(self, path, name):
-        Reports.__init__(self, name)
-        self.path = path
-        self.name = name
-        self.root = root(name)
-    
-    def __repr__(self):
-        return "artifact:name=" + self.name
-    
-    def __eq__(self, other):
-        try:
-            return (self.name == getattr(other, "name") and
-                self.path == getattr(other, "path"))
-        except AttributeError:
-            return False
-        
-    def reportTo(self, reviewer):
-        if (hasattr(reviewer, "reviewArtifact")):
-            reviewer.reviewArtifact(self)
-
-class ZipContainer():
-    """
-    A container compressed using the zip algorithm.
-    """
-    
-    def __init__(self, path, name):
-        self.filepath = os.path.join(path, name)
-    
-    def contentsOfDirectory(self, directory):
-        return readContentsFromDirectoryInZip(self.filepath, directory)
-    
-class Jar(Artifact, ZipContainer):
-    """
-    An artifact compressed using the zip algorithm
-    and laid out according to the Jar format.
-    """
-    
-    def __init__(self, path, name):
-        Artifact.__init__(self, path, name)
-        ZipContainer.__init__(self, path, name)
-    
-    def __repr__(self):
-        return "jar:name=" + self.name 
-
-    def metainf(self):
-        """
-        Reads the contents of the META-INF directory.
-        """
-        return self.contentsOfDirectory("META-INF")
-        
-    def reportTo(self, reviewer):
-        Artifact.reportTo(self, reviewer)
-        if (hasattr(reviewer, "reviewJar")):
-            reviewer.reviewJar(self)
-        return self
+    engine.Reporter(styles).report(
+        engine.Reviewer(checks).review(
+            engine.AccumulativeScanner(directory).scan().findings))
 



Mime
View raw message