1
私の割り当ての一環として、私はPythonスクリプトを通してテーブルワークシートを移行するように求められています。移行は成功しましたが、移行後に出力ワークシートのソースファイルからタブを取得しません。Pythonで移動したときにTableauワークブックにソースファイルのタブが表示されないScipt
スクリーンショット2:以下は私の立場を説明、画像....
スクリーンショット1は
'''
Created on Sep 12, 2016
@author: johnsoja
'''
import argparse
import Utils
import os
dev_server="http://ftc-wberfapp202"
dev_user="sys_dev_erfadmin"
dev_pwd="xyz"
stg_server="https://ftc-wberfapp501"
stg_user="sys_dev_erfadmin"
stg_pwd="xyz"
prod_server="https://PTC-WBERFAPP101"
prod_user="sys_pr_erf_admin"
prod_pwd="xyz"
scriptdir = "E:\\Program Files\\Tableau\\Tableau Server\\10.1\\bin\\";
tabcmdlogincmd = "tabcmd login -s {0} -t {1} -u {2} -p {3} --cookie";
downloadfilecmd = "tabcmd get \"{0}\" -f \"{1}\" ";
publishfilecmd ="tabcmd publish \"{0}\" -r \"{1}\" --overwrite ";
tabcmdlogoutcmd = "tabcmd logout";
tmpFileLocation = "E:\\Tableau_Deployment_Application_SVN\\approved\\";
tmpDatasourceLocation = "E:\\Tableau_Deployment_Application_SVN\\datasources\\";
'''
Read from config file the data sources that are to be migrated.
'''
def readDataSourceConfig(configfilename):
print('reading config file name ({0})'.format(configfilename))
utils = Utils.ConfigUtil()
datasources = utils.ConfigSections(configfilename)
dataSourcesDict = dict()
dataSourceNames = []
for datasource in datasources:
print("Datasources to migrate ({0})".format(datasource))
dictionary = utils.ConfigSectionMap(configfilename, datasource)
dataSourcesDict[datasource] = dictionary
datasourcenm, connectionnm = datasource.split(":")
dataSourceNames.append(datasourcenm)
return dataSourcesDict, dataSourceNames
'''
Read from config file the data sources that are to be migrated.
'''
def readWorkbookConfig(configfilename):
print('reading config file name ({0})'.format(configfilename))
workbookprops = []
with open(configfilename) as file:
for line in file:
line = line.strip()
workbookprops.append(line)
print(workbookprops)
return workbookprops
def getWorkbooksFromSourceSite(source_server,source_username,source_password,source_site,source_project,dataSourceNames,workbookprops):
token, site_id, user_id = Utils.RestApiUtils.sign_in(source_site,source_server,source_username,source_password)
workbooks = Utils.RestApiUtils.query_workbooks(token, site_id, source_project);
datasources = Utils.RestApiUtils.query_datasources(token, site_id)
return workbooks, datasources
def uploadWorkbooksToDestinationSite(dest_server,dest_username,dest_password,dest_site,dest_project,workbooks,datasources,dataSourceNames,workbookprops,update_ds):
os.chdir(scriptdir)
print("********************")
print("Logging into the Tableau Server")
tabcmdlogincmdfrmt = tabcmdlogincmd.format(dest_server,dest_site,dest_username,dest_password)
tabcmdlogincmdfrmt = tabcmdlogincmdfrmt+" --no-certcheck "
print(tabcmdlogincmdfrmt)
Utils.Commons.runCommand(tabcmdlogincmdfrmt)
for workbook in workbooks:
workbook_name=workbook.get("contentUrl")
workbook_full_name=workbook.get("name")
if workbook_name in workbookprops:
workbookfile = "/workbooks/"+workbook_name+".twbx"
outputworkbookfile = tmpFileLocation+workbook_name+".twbx"
publishfilecmdfrmt=publishfilecmd.format(outputworkbookfile, dest_project,dest_username,dest_password)
print(publishfilecmdfrmt)
Utils.Commons.runCommand(publishfilecmdfrmt+" --no-certcheck ")
print("********************")
print("completed publishing workbooks")
Utils.Commons.runCommand(tabcmdlogoutcmd)
return workbooks, datasources
def stringComp(str_1, str_0):
if(str_1 is None):
str_1 = ""
if(str_0 is None):
str_0 = ""
return str_1.lower() == str_0.lower()
def usage():
print('\n This is the usage function: \n')
print('NonProd-Staging-Prod-Loader -a -f <location of erf<stg/prod>migration.properties> -s <sitename> -p <projectname>')
if __name__ == '__main__':
pass
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--all')
parser.add_argument('-f', '--filepath')
parser.add_argument('-s', '--sitename', required=True)
parser.add_argument('-d', '--destsitename', required=True)
parser.add_argument('-p', '--projectname', required=True)
parser.add_argument('-t', '--target', required=True)
parser.add_argument('-u', '--updatedatasource')
args = parser.parse_known_args()[0]
if(args.target=="PROD"):
source_server = dev_server
source_username = dev_user
source_password = dev_pwd
source_site = args.sitename
source_project = args.projectname
dest_server = prod_server
dest_username = prod_user
dest_password = prod_pwd
dest_site = args.destsitename
dest_project = args.projectname
update_ds=args.updatedatasource
print("moving site {0} from server {1} to server {2}".format(source_site, stg_server, prod_server))
dest_ds_properties = "E:\\Tableau_Deployment_Application_SVN\\migrationconfigs\\ds.prod.properties";
dest_wkbk_properties = "E:\\Tableau_Deployment_Application_SVN\\migrationconfigs\\wkbk.properties";
if(args.target=="STG"):
source_server = dev_server
source_username = dev_user
source_password = dev_pwd
source_site = args.sitename
source_project = args.projectname
dest_server = stg_server
dest_username = stg_user
dest_password = stg_pwd
dest_site = args.destsitename
dest_project = args.projectname
update_ds=args.updatedatasource
print("moving site {0} from server {1} to server {2}".format(dest_site, dev_server, stg_server))
dest_ds_properties = "E:\\Tableau_Deployment_Application_SVN\\migrationconfigs\\ds.prod.properties";
dest_wkbk_properties = "E:\\Tableau_Deployment_Application_SVN\\migrationconfigs\\wkbk.properties";
datasourceprops, dataSourceNames = readDataSourceConfig(dest_ds_properties);
##print("Data source names from properties")
##print(dataSourceNames)
workbookprops = readWorkbookConfig(dest_wkbk_properties);
workbooks, datasources = getWorkbooksFromSourceSite(source_server,source_username,source_password,source_site,source_project,dataSourceNames,workbookprops)
workbooks, datasources = uploadWorkbooksToDestinationSite(dest_server,dest_username,dest_password,dest_site,dest_project,workbooks,datasources,dataSourceNames,workbookprops,update_ds)
print("Completed Migration!!!!")