Browse Source

More progress on lines.

avkonst 11 years ago
parent
commit
57d95d4477
2 changed files with 14 additions and 11 deletions
  1. 0 1
      mainline/core/log.py
  2. 14 10
      mainline/ext/std/code/lines.py

+ 0 - 1
mainline/core/log.py

@@ -51,6 +51,5 @@ class Plugin(core.api.Plugin, core.api.IConfigurable):
         logging.warn("Logging enabled with " + options.__dict__['log_level'] + " level")
 
 
-
 def set_default_format():
     logging.basicConfig(format="[LOG]: %(levelname)s:\t%(message)s", level=logging.WARN)

+ 14 - 10
mainline/ext/std/code/lines.py

@@ -18,6 +18,7 @@
 #
 
 import core.api
+import re
 
 class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
     
@@ -67,16 +68,19 @@ class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
         if len(fields) != 0:
             core.api.subscribe_by_parents_interface(core.api.ICode, self, 'callback')
 
+    pattern_line = re.compile(r'''[^\s].*''')
+
     def callback(self, parent, data, is_updated):
         is_updated = is_updated or self.is_updated
         if is_updated == True:
-            for region in data.iterate_regions():
-                size = 0
-                start_pos = region.get_offset_begin()
-                for sub_id in region.iterate_subregion_ids():
-                    # exclude sub regions, like enclosed classes
-                    size += data.get_region(sub_id).get_offset_begin() - start_pos
-                    start_pos = data.get_region(sub_id).get_offset_end()
-                size += region.get_offset_end() - start_pos
-                region.set_data(self.get_name(), 'size', size)
-
+            if self.is_active_code == True:
+                text = data.get_content(exclude = data.get_marker_types().ALL_EXCEPT_CODE)
+                for region in data.iterate_regions():
+                    count = 0
+                    start_pos = region.get_offset_begin()
+                    for sub_id in region.iterate_subregion_ids():
+                        count += len(self.pattern_line.findall(text, start_pos, data.get_region(sub_id).get_offset_begin()))
+                        start_pos = data.get_region(sub_id).get_offset_end()
+                    count += len(self.pattern_line.findall(text, start_pos, region.get_offset_end()))
+                    region.set_data(self.get_name(), 'code', count)
+