Passed
Push — master ( 0894ce...68cef4 )
by Daniel
01:20
created

sources.db_extractor.ExtractorSpecificNeeds   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ExtractorSpecificNeeds.fn_is_extraction_neccesary() 0 20 4
A ExtractorSpecificNeeds.__init__() 0 2 1
A ExtractorSpecificNeeds.fn_check_inputs_specific() 0 7 1
1
"""
2
Class Extractor Specific Needs
3
4
Handling specific needs for Extractor script
5
"""
6
# package to facilitate working with directories and files
7
from pathlib import Path
8
# package to facilitate common operations
9
from db_extractor.BasicNeeds import BasicNeeds
10
11
12
class ExtractorSpecificNeeds:
13
    lcl_bn = None
14
15
    def __init__(self):
16
        self.lcl_bn = BasicNeeds()
17
18
    def fn_check_inputs_specific(self, input_parameters):
19
        self.lcl_bn.fn_validate_single_value(input_parameters.input_source_system_file,
20
                                             'file', 'source system file')
21
        self.lcl_bn.fn_validate_single_value(input_parameters.input_credentials_file,
22
                                             'file', 'credentials file')
23
        self.lcl_bn.fn_validate_single_value(input_parameters.input_extracting_sequence_file,
24
                                             'file', 'extracting sequence file')
25
26
    @staticmethod
27
    def fn_is_extraction_neccesary(local_logger, relevant_details):
28
        extraction_is_necessary = False
29
        local_logger.debug('Extract behaviour is set to ' + relevant_details['extract-behaviour'])
30
        if relevant_details['extract-behaviour'] == \
31
                'skip-if-output-file-exists':
32
            if Path(relevant_details['output-csv-file']).is_file():
33
                local_logger.debug('File ' + relevant_details['output-csv-file']
34
                                   + ' already exists, '
35
                                   + 'so database extraction will not be performed')
36
            else:
37
                extraction_is_necessary = True
38
                local_logger.debug('File ' + relevant_details['output-csv-file']
39
                                   + ' does not exist, '
40
                                   + 'so database extraction has to be performed')
41
        elif relevant_details['extract-behaviour'] == \
42
                'overwrite-if-output-file-exists':
43
            extraction_is_necessary = True
44
            local_logger.debug('Database extraction has to be performed')
45
        return extraction_is_necessary