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 |