Passed
Push — master ( 84bec4...a08110 )
by Konstantin
04:15 queued 01:47
created

invalidate_AlternativeImage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 23
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B invalidate_AlternativeImage() 0 31 8
1
def invalidate_AlternativeImage(self, feature_selector=None):
2
    """
3
    Remove derived images from this segment (due to changed coordinates).
4
5
    If ``feature_selector`` is not none, remove only images with
6
    matching ``@comments``, e.g. ``feature_selector=cropped,deskewed``.
7
    """
8
    existing_images = self.AlternativeImage or []
9
    removed_images = []
10
    if feature_selector:
11
        new_images = []
12
        for image in existing_images:
13
            features = image.get_comments() or ''
14
            if any(feature in features.split(',')
15
                   for feature in feature_selector.split(',') if feature):
16
                removed_images.append(image)
17
            else:
18
                new_images.append(image)
19
        self.AlternativeImage = new_images
20
    else:
21
        removed_images = existing_images
22
        self.AlternativeImage = []
23
    if hasattr(self, 'id'):
24
        name = self.id
25
    elif hasattr(self, 'parent_object_') and hasattr(self.parent_object_, 'pcGtsId'):
26
        name = self.parent_object_.pcGtsId
27
    else:
28
        name = ''
29
    for image in removed_images:
30
        self.gds_collector_.add_message('Removing AlternativeImage %s from "%s"' % (
31
            image.get_comments() or '', name))
32