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