|
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
|
|
|
# package to measure portions of code performance |
|
8
|
|
|
from codetiming import Timer |
|
9
|
|
|
# Custom classes specific to this package |
|
10
|
|
|
from tableau_hyper_management.BasicNeedsForPublisher import os, BasicNeeds, BasicNeedsForPublisher |
|
11
|
|
|
from tableau_hyper_management.LoggingNeeds import LoggingNeeds |
|
12
|
|
|
from tableau_hyper_management.CommandLineArgumentsManagement import CommandLineArgumentsManagement |
|
13
|
|
|
from tableau_hyper_management.TableauServerCommunicator import TableauServerCommunicator |
|
14
|
|
|
|
|
15
|
|
|
# get current script name |
|
16
|
|
|
current_script_name = os.path.basename(__file__).replace('.py', '') |
|
17
|
|
|
|
|
18
|
|
|
# main execution logic |
|
19
|
|
|
if __name__ == '__main__': |
|
20
|
|
|
# instantiate Basic Needs class |
|
21
|
|
|
c_bn = BasicNeeds() |
|
22
|
|
|
# load application configuration (inputs are defined into a json file) |
|
23
|
|
|
c_bn.fn_load_configuration() |
|
24
|
|
|
# instantiate CommandLine Arguments Management class |
|
25
|
|
|
c_clam = CommandLineArgumentsManagement() |
|
26
|
|
|
parameters_in = c_clam.parse_arguments(c_bn.cfg_dtls['input_options']['publisher']) |
|
27
|
|
|
# checking inputs, if anything is invalid an exit(1) will take place |
|
28
|
|
|
c_bn.fn_check_inputs(parameters_in) |
|
29
|
|
|
# instantiate Extractor Specific Needs class |
|
30
|
|
|
c_bnfp = BasicNeedsForPublisher() |
|
31
|
|
|
# checking inputs, if anything is invalid an exit(1) will take place |
|
32
|
|
|
c_bnfp.fn_check_inputs_specific(parameters_in) |
|
33
|
|
|
# get the secrets from provided file |
|
34
|
|
|
credentials = c_bn.fn_open_file_and_get_content(parameters_in.input_credentials_file, 'json') |
|
35
|
|
|
credentials_dict = credentials['Credentials']['LDAP']['Production']['Default'] |
|
36
|
|
|
# instantiate Logger class |
|
37
|
|
|
c_ln = LoggingNeeds() |
|
38
|
|
|
# initiate logger |
|
39
|
|
|
c_ln.initiate_logger(parameters_in.output_log_file, 'thm_publish_data_source') |
|
40
|
|
|
# define global timer to use |
|
41
|
|
|
t = Timer('thm_publish_data_source', text='Time spent is {seconds} ', logger=c_ln.logger.debug) |
|
42
|
|
|
# reflect input parameters given values |
|
43
|
|
|
c_clam.listing_parameter_values(c_ln.logger, t, 'Tableau Hyper Publisher', |
|
44
|
|
|
c_bn.cfg_dtls['input_options']['publisher'], parameters_in) |
|
45
|
|
|
# store statistics about input file |
|
46
|
|
|
c_bn.fn_store_file_statistics(c_ln.logger, t, parameters_in.input_file, 'Input') |
|
47
|
|
|
# instantiate main library that ensure Tableau Server communication |
|
48
|
|
|
c_tsc = TableauServerCommunicator() |
|
49
|
|
|
# initiate Tableau Server connection |
|
50
|
|
|
c_tsc.connect_to_tableau_server(c_ln.logger, t, { |
|
51
|
|
|
'Tableau Server': parameters_in.tableau_server, |
|
52
|
|
|
'Tableau Site': parameters_in.tableau_site, |
|
53
|
|
|
'Username': credentials_dict['Username'], |
|
54
|
|
|
'Password': credentials_dict['Password'], |
|
55
|
|
|
}) |
|
56
|
|
|
# identify relevant project(s) based on given name |
|
57
|
|
|
relevant_project_details = c_tsc.load_tableau_project_ids(c_ln.logger, t, |
|
58
|
|
|
[parameters_in.tableau_project], |
|
59
|
|
|
'JustOnesMentioned') |
|
60
|
|
|
# check if a single project has been identified and if so proceed with publishing |
|
61
|
|
|
if c_tsc.is_publishing_possible(c_ln.logger, parameters_in.tableau_project, |
|
62
|
|
|
relevant_project_details): |
|
63
|
|
|
# perform the publishing of data source |
|
64
|
|
|
c_tsc.publish_data_source_to_tableau_server(c_ln.logger, t, { |
|
65
|
|
|
'Project ID': relevant_project_details[0], |
|
66
|
|
|
'Tableau Extract File': parameters_in.input_file, |
|
67
|
|
|
'Publishing Mode': parameters_in.publishing_mode, |
|
68
|
|
|
}) |
|
69
|
|
|
# disconnect from Tableau Server |
|
70
|
|
|
c_tsc.disconnect_from_tableau_server(c_ln.logger, t) |
|
71
|
|
|
# just final message |
|
72
|
|
|
c_bn.fn_final_message(c_ln.logger, parameters_in.output_log_file, |
|
73
|
|
|
t.timers.total('thm_publish_data_source')) |
|
74
|
|
|
|