Completed
Push — master ( 394f60...2c657b )
by Daniel
01:31
created

FileValidatorsPlugin   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 14 4
A __init__() 0 3 1
1
from subprocess import check_output, CalledProcessError
2
3
from groundwork_validation.patterns import GwValidatorsPattern
4
5
6
class GwFileValidatorsPattern(GwValidatorsPattern):
7
8
    def __init__(self, app, **kwargs):
9
        super(GwFileValidatorsPattern, self).__init__(app, **kwargs)
10
        self.app = app
11
        self.validators.db = FileValidatorsPlugin(self)
12
13
14
class FileValidatorsPlugin:
15
16
    def __init__(self, plugin):
17
        self.plugin = plugin
18
        self._validator = None
19
20
    def validate(self, file,  validator=None):
21
22
        if validator is None:
23
            if self._validator is None:
24
                self._validator = self.plugin.validators.register("cmd_validator_%s" % self.plugin.name,
25
                                                                  "CMD validator for plugin %s" % self.plugin.name)
26
            validator = self._validator
27
28
        try:
29
            output = check_output()
30
            return_code = 0
31
        except CalledProcessError as e:
32
            output = e.output
33
            return_code = e.returncode
34
35