diff --git a/examples/replicate_site_structure_sample.py b/examples/replicate_site_structure_sample.py index 1cbd35a..cabeb2c 100644 --- a/examples/replicate_site_structure_sample.py +++ b/examples/replicate_site_structure_sample.py @@ -2,39 +2,55 @@ from tableau_tools.tableau_rest_api import * from tableau_tools import * -import urllib2 import time -server = u'http://127.0.0.1' -username = u'' -password = u'' - +o_server = u'http://127.0.0.1' +o_username = u'' +o_password = u'' original_content_url = u'test_site' + +n_server = u'http://127.0.0.1' +n_username = u'' +n_password = u'' new_site_name = u'Test Site Replica' new_site_content_url = u'test_site_replica' -o = TableauRestApiConnection25(server, username, password, original_content_url) +# Sign in to the original site with an administrator level user +o = TableauRestApiConnection28(server=o_server, username=o_username, + password=o_password, site_content_url=original_content_url) o.signin() logger = Logger(u'replicate_site_sample.log') # Enable logging after sign-in to hide credentials o.enable_logging(logger) +# Sign in to the new Server on default as a Server Admin +n_default = TableauRestApiConnection28(server=n_server, username=n_username, + password=n_password, site_content_url=u"default") +n_default.signin() +n_default.enable_logging(logger) + +# Die if the new site already exists try: - o.create_site(new_site_name, new_site_content_url) -except AlreadyExistsException: - print e.msg - print u"Cannot create new site, it already exists" + n_default.create_site(new_site_name, new_site_content_url) +except AlreadyExistsException as e: + print(e.msg) + print(u"Cannot create new site, it already exists. Exiting") exit() +n_default.signout() -n = TableauRestApiConnection25(server, username, password, new_site_content_url) +# Connect to the newly created site +n = TableauRestApiConnection28(server=n_server, username=n_username, + password=n_password, site_content_url=new_site_content_url) n.signin() n.enable_logging(logger) -# Replicate Groups +# Now we start replicating from one site to the other + +# Replicate Groups first, so you can put users in them groups = o.query_groups() groups_dict = o.convert_xml_list_to_name_id_dict(groups) for group in groups_dict: - # Can't add All Users because it is generated + # Can't add All Users because it is generated automatically if group == u'All Users': continue n.create_group(group) @@ -62,17 +78,25 @@ group_users_dict = o.convert_xml_list_to_name_id_dict(group_users) n.add_users_to_group(group_users_dict, group) -# Replicate Projects +# Create all of the projects projects = o.query_projects() proj_dict = o.convert_xml_list_to_name_id_dict(projects) -for proj in proj_dict: - if proj == u'Default': +for proj in projects: + if proj.get(u'name') == u'Default': continue # This assumes locked permissions and no description. Can iterate over objects if you need some of that - n.create_project(proj, no_return=True) + n.create_project(proj.get(u'name'), proj.get(u'description'), proj.get(u'contentPermissions'), + publish_samples=False, no_return=True) +# Assign projects to their parents if they have one +for proj in projects: + if proj.get(u'parentProjectId') is not None: + # Get the Name of the Project that is the Parent + o_parent_project = o.query_project(proj.get(u'parentProjectId')) + new_parent_project_name = o_parent_project.get_xml_obj().get(u'name') + n.update_project(proj.get(u'name'), + parent_project_name_or_luid=new_parent_project_name) - n.create_project() # Let the projects get all settled in time.sleep(4) @@ -83,5 +107,23 @@ new_proj = n.query_project(proj_name) new_proj.replicate_permissions(orig_proj) -# Bring down all datasources +# Datasources # Note -- data sources with embedded data credentials must have them supplied again at this publish time +# Must publish Data Sources + +# Workbooks + +# Schedules +# Schedules are Server wide, so you must be a Server admin to sync them +# You probably don't want to override existing schedules on the new Server + +# If migrating to Tableau Online, comment out this section +#schedules = o.query_schedules() +#for sched in schedules: + + +# Subscriptions +# If migrating to Tableau Online, build a translation dictionary for the + +# Alerts + diff --git a/requirements.txt b/requirements.txt index 6b08d69..663bd1f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -tableau_tools requests \ No newline at end of file diff --git a/setup.py b/setup.py index 99db97a..e5a5801 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='tableau_tools', - version='4.6.4', + version='4.6.5', packages=['tableau_tools', 'tableau_tools.tableau_rest_api', 'tableau_tools.tableau_documents', 'tableau_tools.examples'], url='https://github.com/bryantbhowell/tableau_tools', license='', diff --git a/tableau_documents/tableau_datasource.py b/tableau_documents/tableau_datasource.py index a3855c8..b87ee9e 100644 --- a/tableau_documents/tableau_datasource.py +++ b/tableau_documents/tableau_datasource.py @@ -82,7 +82,9 @@ def __init__(self, datasource_xml=None, logger_obj=None, ds_version=None): self.ds_version_type = u'9' else: version_split = xml_version.split(u'.') - if int(version_split[1]) < 5: + if int(version_split[0]) >= 18: + self.ds_version_type = u'10.5' + elif int(version_split[1]) < 5: self.ds_version_type = u'10' else: self.ds_version_type = u'10.5' @@ -456,7 +458,8 @@ def generate_extract_section(self): else: from tde_file_generator import TDEFileGenerator except Exception as ex: - print u"Must install the Tableau Extract SDK to add extracts" + print(u"Must have correct install of Tableau Extract SDK to add extracts") + print(u'Exception arising from the Tableau Extract SDK itself') raise e = etree.Element(u'extract') e.set(u'count', u'-1') diff --git a/tableau_rest_api/__init__.py b/tableau_rest_api/__init__.py index d4c0798..ad82815 100644 --- a/tableau_rest_api/__init__.py +++ b/tableau_rest_api/__init__.py @@ -9,6 +9,7 @@ from tableau_rest_api_connection_28 import TableauRestApiConnection28 from tableau_rest_api_connection_30 import TableauRestApiConnection30 from tableau_rest_api_connection_31 import TableauRestApiConnection31 +from tableau_rest_api_connection_32 import TableauRestApiConnection32 from sort import Sort from url_filter import UrlFilter, UrlFilter23, UrlFilter24, UrlFilter25, UrlFilter26, UrlFilter27, UrlFilter28 from content_deployer import ContentDeployer