Add a licenses command by Gheorghe Scutaru
authorDaniel Bainton <daniel.bainton@movial.com>
Thu, 2 Jul 2009 07:13:04 +0000 (10:13 +0300)
committerDaniel Bainton <daniel.bainton@movial.com>
Thu, 2 Jul 2009 07:13:57 +0000 (10:13 +0300)
matrix/components.py
matrix/matrix.py

index 1ac060f..98d6bf9 100644 (file)
@@ -2,6 +2,7 @@
 # Authors: Timo Savola
 #          Daniel Bainton <daniel.bainton@movial.com>
 
+import sys
 import os
 import re
 from glob import glob
@@ -43,6 +44,8 @@ class Component(object):
 
                self.rank = rank
 
+               self.license = self.get_license()
+
        def __str__(self):
                return str(self.source)
 
@@ -73,6 +76,19 @@ class Component(object):
        def get_depends(self):
                return self.depends
 
+       def get_license(self):
+               path = os.path.join(self.meta.path, 'info')
+               if not os.path.exists(path):
+                       return 'None'
+
+               f = open(path, 'r')
+               for line in f:
+                       if (line.find('license') != -1) and (line.count('"') == 2):
+                               index_quote1 = line.find('"')
+                               index_quote2 = line.find('"', index_quote1 + 1)
+                               return line[index_quote1 + 1 : index_quote2].strip()
+               return 'None'
+
 class PlatformProvidedComponent(Component):
        """A Component that is provided by the platform.
           The sources will not be built during install."""
index 78e10e1..dc13243 100644 (file)
@@ -65,6 +65,7 @@ def main(version):
                'pull':         pull,
                'changes':      changes,
                'source-dist':  source_dist,
+               'licenses':     print_licenses,
        }
 
        func = command_funcs.get(command)
@@ -91,6 +92,7 @@ commands:
   pull          update remote repositories and merge with local repositories
   changes       show commits which are not on the server
   source-dist   download and package the component sources
+  licenses      print components licenses
 '''
 
 def parse_args(matrix_version):
@@ -359,3 +361,18 @@ def dist_sources(c, location):
                os.remove(path)
 
        c.source.archive(name, path)
+
+def print_licenses(targets):
+       file = sys.stdout
+       
+       meta(targets)
+       
+       for name in targets:
+               c = find_component(name)
+               print >> file, c.name + ' --> ' + c.license
+               
+               for dep in c.get_depends():
+                       print >> file, '\t' + dep.name + ' --> ' + dep.license
+
+               print >> file, '\n'
+