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.path as os_path |
10
|
|
|
# package to measure portions of code performance |
11
|
|
|
from codetiming import Timer |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
# Custom classes specific to this package |
15
|
|
|
from tableau_hyper_management import BasicNeeds |
16
|
|
|
from tableau_hyper_management import LoggingNeeds |
17
|
|
|
from tableau_hyper_management import CommandLineArgumentsManagement |
18
|
|
|
from tableau_hyper_management import TableauServerCommunicator |
19
|
|
|
|
20
|
|
|
# main execution logic |
21
|
|
|
if __name__ == '__main__': |
22
|
|
|
c_bn = BasicNeeds() |
23
|
|
|
c_bn.fn_load_configuration() |
24
|
|
|
c_clam = CommandLineArgumentsManagement() |
25
|
|
|
parameters_in = c_clam.parse_arguments(c_bn.cfg_dtls['input_options']['publisher']) |
26
|
|
|
credentials = c_bn.fn_open_file_and_get_its_content(parameters_in.input_credentials_file, |
27
|
|
|
'json') |
28
|
|
|
credentials_to_use = credentials['Credentials']['LDAP']['LDAP']['LDAP']['Production']['Default'] |
29
|
|
|
# initiate logger |
30
|
|
|
c_ln = LoggingNeeds() |
31
|
|
|
c_ln.initiate_logger(parameters_in.output_log_file, 'thm_publisher') |
32
|
|
|
# define global timer to use |
33
|
|
|
t = Timer('thm', |
34
|
|
|
text = 'Time spent is {seconds} ', |
35
|
|
|
logger = c_ln.logger.debug |
36
|
|
|
) |
37
|
|
|
t.start() |
38
|
|
|
# marking start of the Log |
39
|
|
|
c_ln.logger.info('='*50) |
40
|
|
|
c_ln.logger.info('Tableau Hyper Publisher started') |
41
|
|
|
# reflect input parameters given values |
42
|
|
|
c_clam.listing_parameter_values(c_ln.logger, |
43
|
|
|
c_bn.cfg_dtls['input_options']['publisher'], |
44
|
|
|
parameters_in) |
45
|
|
|
t.stop() |
46
|
|
|
# check if provided Hyper file actually exists |
47
|
|
|
if os_path.isfile(parameters_in.input_file): |
48
|
|
|
tableau_connecting_details = { |
49
|
|
|
'Tableau Server' : parameters_in.tableau_server, |
50
|
|
|
'Tableau Site' : parameters_in.tableau_site, |
51
|
|
|
'Username' : credentials_to_use['Username'], |
52
|
|
|
'Password' : credentials_to_use['Password'], |
53
|
|
|
} |
54
|
|
|
c_tsc = TableauServerCommunicator() |
55
|
|
|
c_tsc.connect_to_tableau_server(c_ln.logger, t, tableau_connecting_details) |
56
|
|
|
relevant_project = [parameters_in.tableau_project] |
57
|
|
|
relevant_project_details = c_tsc.load_tableau_project_ids(c_ln.logger, t, |
58
|
|
|
relevant_project, |
59
|
|
|
'JustOnesMentioned') |
60
|
|
|
if c_tsc.is_publishing_possible(c_ln.logger, |
61
|
|
|
parameters_in.tableau_project, |
62
|
|
|
relevant_project_details): |
63
|
|
|
publishing_details = { |
64
|
|
|
'Project ID' : relevant_project_details[0], |
65
|
|
|
'Tableau Extract File' : parameters_in.input_file, |
66
|
|
|
'Publishing Mode' : parameters_in.publishing_mode, |
67
|
|
|
} |
68
|
|
|
c_tsc.publish_data_source_to_tableau_server(c_ln.logger, t, publishing_details) |
69
|
|
|
c_tsc.disconnect_from_tableau_server(c_ln.logger, t) |
70
|
|
|
else: |
71
|
|
|
# doesn't exist |
72
|
|
|
c_ln.logger.error('Given file ' + parameters_in.input_file |
73
|
|
|
+ ' does not exist, please check your inputs!') |
74
|
|
|
c_bn.fn_final_message(c_ln.logger, t, parameters_in.output_log_file) |
75
|
|
|
|