Test Failed
Push — master ( 083155...926069 )
by Daniel
03:49
created

tableau_hyper_management.publisher   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 53
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 0
1
"""
2
main - entry point of the package
3
4
This file is connecting to a Tableau Server and publishes a local HYPER file
5
measuring time elapsed (performance)
6
"""
7
8
# standard Python packages
9
import os
10
import os.path as os_path
11
from datetime import timedelta
12
# package to measure portions of code performance
13
from codetiming import Timer
14
15
16
# Custom classes specific to this package
17
from tableau_hyper_management.BasicNeeds import BasicNeeds as ClassBN
18
from tableau_hyper_management.LoggingNeeds import LoggingNeeds as ClassLN
19
from tableau_hyper_management.CommandLineArgumentsManagement import \
20
    CommandLineArgumentsManagement as ClassCLAM
21
from tableau_hyper_management.TableauServerCommunicator import TableauServerCommunicator as ClassTSC
22
23
# main execution logic
24
if __name__ == '__main__':
25
    ClassBN.fn_load_configuration(ClassBN)
26
    parameters_in = ClassCLAM.parse_arguments(ClassCLAM,
27
                                              ClassBN.cfg_dtls['input_options']['publisher'])
28
    credentials = ClassBN.fn_open_file_and_get_its_content(ClassBN,
29
                                                           parameters_in.input_credentials_file,
30
                                                           'json')
31
    credentials_to_use = credentials['Credentials']['LDAP']['LDAP']['LDAP']['Production']['Default']
32
    # initiate logger
33
    ClassLN.initiate_logger(ClassLN, parameters_in.output_log_file, 'thm_publisher')
34
    # define global timer to use
35
    t = Timer('thm',
36
              text      = 'Time spent is {seconds} ',
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
37
              logger    = ClassLN.logger.debug
0 ignored issues
show
Coding Style introduced by
No space allowed around keyword argument assignment
Loading history...
38
              )
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (remove 1 space).
Loading history...
39
    t.start()
40
    # marking start of the Log
41
    ClassLN.logger.info('='*50)
42
    ClassLN.logger.info('Tableau Hyper Publisher started')
43
    # reflect input parameters given values
44
    ClassCLAM.listing_parameter_values(ClassCLAM, ClassLN.logger,
45
                                       ClassBN.cfg_dtls['input_options']['publisher'],
46
                                       parameters_in,
47
                                       )
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (remove 1 space).
Loading history...
48
    t.stop()
49
    # check if provided Hyper file actually exists
50
    if os_path.isfile(parameters_in.input_file):
51
        tableau_connecting_details = {
52
            'Tableau Server'    : parameters_in.tableau_server,
53
            'Tableau Site'      : parameters_in.tableau_site,
54
            'Username'          : credentials_to_use['Username'],
55
            'Password'          : credentials_to_use['Password'],
56
        }
57
        ClassTSC.connect_to_tableau_server(ClassTSC, ClassLN.logger, t, tableau_connecting_details)
58
        relevant_project = [parameters_in.tableau_project]
59
        relevant_project_details = ClassTSC.load_tableau_project_ids(ClassTSC, ClassLN.logger, t,
60
                                                                     relevant_project,
61
                                                                     'JustOnesMentioned')
62
        if ClassTSC.is_publishing_possible(ClassTSC, ClassLN.logger,
63
                                           parameters_in.tableau_project,
64
                                           relevant_project_details):
65
            publishing_details = {
66
                'Project ID'            : relevant_project_details[0],
67
                'Tableau Extract File'  : parameters_in.input_file,
68
                'Publishing Mode'       : parameters_in.publishing_mode,
69
            }
70
            ClassTSC.publish_data_source_to_tableau_server(ClassTSC, ClassLN.logger, t,
71
                                                           publishing_details)
72
        ClassTSC.disconnect_from_tableau_server(ClassTSC, ClassLN.logger, t)
73
    else:
74
        # doesn't exist
75
        ClassLN.logger.error('Given file ' + parameters_in.input_file
76
                             + ' does not exist, please check your inputs!')
77
    ClassBN.fn_final_message(ClassBN, ClassLN.logger, t, parameters_in.output_log_file)
78