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 facilitate operating system locale detection |
8
|
|
|
import locale |
9
|
|
|
import os |
10
|
|
|
# Custom classes specific to this package |
11
|
|
|
from tableau_hyper_management.ProjectNeeds import ProjectNeeds |
12
|
|
|
from tableau_hyper_management.TableauServerCommunicator import TableauServerCommunicator |
13
|
|
|
# get current script name |
14
|
|
|
#SCRIPT_NAME = os.path.basename(__file__).replace('.py', '') |
15
|
|
|
SCRIPT_NAME = 'publisher' |
16
|
|
|
SCRIPT_LANGUAGE = locale.getdefaultlocale('LC_ALL')[0] |
17
|
|
|
|
18
|
|
|
# main execution logic |
19
|
|
|
if __name__ == '__main__': |
20
|
|
|
# instantiate Extractor Specific Needs class |
21
|
|
|
class_pn = ProjectNeeds(SCRIPT_NAME, SCRIPT_LANGUAGE) |
22
|
|
|
# load application configuration (inputs are defined into a json file) |
23
|
|
|
class_pn.load_configuration() |
24
|
|
|
# initiate Logging sequence |
25
|
|
|
class_pn.initiate_logger_and_timer() |
26
|
|
|
# reflect title and input parameters given values in the log |
27
|
|
|
class_pn.class_clam.listing_parameter_values( |
28
|
|
|
class_pn.class_ln.logger, class_pn.timer, 'Tableau Data Source Publisher', |
29
|
|
|
class_pn.config['input_options'][SCRIPT_NAME], class_pn.parameters) |
30
|
|
|
relevant_files_list = class_pn.class_fo.fn_build_file_list( |
31
|
|
|
class_pn.class_ln.logger, class_pn.timer, class_pn.parameters.input_file) |
|
|
|
|
32
|
|
|
# log file statistic details |
33
|
|
|
class_pn.class_fo.fn_store_file_statistics( |
34
|
|
|
class_pn.class_ln.logger, class_pn.timer, relevant_files_list, 'Input') |
|
|
|
|
35
|
|
|
# get the secrets from provided file |
36
|
|
|
credentials = class_pn.class_fo.fn_open_file_and_get_content( |
37
|
|
|
class_pn.parameters.input_credentials_file, 'json') |
|
|
|
|
38
|
|
|
credentials_dict = credentials['Credentials']['LDAP']['Production']['Default'] |
39
|
|
|
# instantiate main library that ensure Tableau Server communication |
40
|
|
|
c_tsc = TableauServerCommunicator() |
41
|
|
|
# initiate Tableau Server connection |
42
|
|
|
c_tsc.connect_to_tableau_server(class_pn.class_ln.logger, class_pn.timer, { |
43
|
|
|
'Tableau Server': class_pn.parameters.tableau_server, |
44
|
|
|
'Tableau Site': class_pn.parameters.tableau_site, |
45
|
|
|
'Username': credentials_dict['Username'], |
46
|
|
|
'Password': credentials_dict['Password'], |
47
|
|
|
}) |
48
|
|
|
# identify relevant project(s) based on given name |
49
|
|
|
list_project_details = c_tsc.load_tableau_project_ids( |
50
|
|
|
class_pn.class_ln.logger, class_pn.timer, |
|
|
|
|
51
|
|
|
[class_pn.parameters.tableau_project], 'JustOnesMentioned') |
|
|
|
|
52
|
|
|
# check if a single project has been identified and if so proceed with publishing |
53
|
|
|
if c_tsc.is_publishing_possible( |
54
|
|
|
class_pn.class_ln.logger, class_pn.parameters.tableau_project, list_project_details): |
55
|
|
|
# perform the publishing of data source |
56
|
|
|
c_tsc.publish_data_source_to_tableau_server(class_pn.class_ln.logger, class_pn.timer, { |
57
|
|
|
'Project ID': list_project_details[0], |
58
|
|
|
'Tableau Extract File': class_pn.parameters.input_file, |
59
|
|
|
'Publishing Mode': class_pn.parameters.publishing_mode, |
60
|
|
|
}) |
61
|
|
|
# disconnect from Tableau Server |
62
|
|
|
c_tsc.disconnect_from_tableau_server(class_pn.class_ln.logger, class_pn.timer) |
63
|
|
|
# just final message |
64
|
|
|
class_pn.class_bn.fn_final_message( |
65
|
|
|
class_pn.class_ln.logger, class_pn.parameters.output_log_file, |
|
|
|
|
66
|
|
|
class_pn.timer.timers.total(SCRIPT_NAME)) |
|
|
|
|
67
|
|
|
|