Browse Source

New option --include-files for the collect tool.

avkonst 10 năm trước cách đây
mục cha
commit
86fba228f8
2 tập tin đã thay đổi với 14 bổ sung1 xóa
  1. 3 1
      mainline/CHANGELOG.md
  2. 11 0
      mainline/ext/std/tools/collect.py

+ 3 - 1
mainline/CHANGELOG.md

@@ -1,5 +1,7 @@
-## 1.4 (September, 2013)
+## 1.4 (May, 2014)
 - New metric: std.code.mi:simple - simple implemetation of maintainability index.
+- New configuration option for collect tool: --include-files (symetrical to --exclude-files)
+
 
 ## 1.3 (August, 2013)
 - Deprecated and dropped support for callback based implementation of advanced counters

+ 11 - 0
mainline/ext/std/tools/collect.py

@@ -30,6 +30,7 @@ class Plugin(mpp.api.Plugin, mpp.api.Parent, mpp.api.IConfigurable, mpp.api.IRun
     
     def __init__(self):
         self.reader = DirectoryReader()
+        self.include_rules = []
         self.exclude_rules = []
         self.exclude_files = []
         self.parsers       = []
@@ -54,6 +55,10 @@ class Plugin(mpp.api.Plugin, mpp.api.Parent, mpp.api.IConfigurable, mpp.api.IRun
         self.is_proctime_enabled = options.__dict__['std.general.proctime']
         self.is_procerrors_enabled = options.__dict__['std.general.procerrors']
         self.is_size_enabled = options.__dict__['std.general.size']
+        try:
+            self.add_include_rule(re.compile(options.__dict__['include_files']))
+        except Exception as e:
+            self.optparser.error("option --include-files: " + str(e))
         try:
             self.add_exclude_rule(re.compile(options.__dict__['exclude_files']))
         except Exception as e:
@@ -88,6 +93,9 @@ class Plugin(mpp.api.Plugin, mpp.api.Parent, mpp.api.IConfigurable, mpp.api.IRun
                     return parser[1]
         return None
 
+    def add_include_rule(self, re_compiled_pattern):
+        self.include_rules.append(re_compiled_pattern)
+
     def add_exclude_rule(self, re_compiled_pattern):
         self.exclude_rules.append(re_compiled_pattern)
 
@@ -97,6 +105,9 @@ class Plugin(mpp.api.Plugin, mpp.api.Parent, mpp.api.IConfigurable, mpp.api.IRun
         self.exclude_files.append(file_path)
 
     def is_file_excluded(self, file_name):
+        for each in self.include_rules:
+            if re.match(each, os.path.basename(file_name)) == None:
+                return True
         for each in self.exclude_rules:
             if re.match(each, os.path.basename(file_name)) != None:
                 return True