def __init__(self, datasource_xml, logger_obj=None): """ :type datasource_xml: etree.Element :type logger_obj: Logger """ TableauDocument.__init__(self) self.logger = logger_obj
def __init__(self, twb_filename, logger_obj=None): TableauDocument.__init__(self) self._document_type = u'workbook' self.logger = logger_obj self.log(u'Initializing a TableauWorkbook object') self.twb_filename = twb_filename # Check the filename if self.twb_filename.find('.twb') == -1: raise InvalidOptionException( u'Must input a .twb filename that exists') self.build_document_objects(self.twb_filename)
def __init__(self, datasource_xml=None, logger_obj=None): """ :type datasource_xml: etree.Element :type logger_obj: Logger """ TableauDocument.__init__(self) self.logger = logger_obj self._parameters = [] # type: list[TableauParameter] self._highest_param_num = 1 self.log(u'Initializing TableauParameters object') self._document_type = u'parameters' # Initialize new Parameters datasource if existing xml is not passed in if datasource_xml is None: self.log(u'No Parameter XML passed in, building from scratch') self.ds_xml = etree.Element(u"datasource") self.ds_xml.set(u'name', u'Parameters') # Initialization of the datasource self.ds_xml.set(u'hasconnection', u'false') self.ds_xml.set(u'inline', u'true') a = etree.Element(u'aliases') a.set(u'enabled', u'yes') self.ds_xml.append(a) else: self.log( u'Parameter XML passed in, finding essential characteristics') self.ds_xml = datasource_xml params_xml = self.ds_xml.findall(u'./column') numbered_parameter_regex = re.compile(u"\[Parameter (\d+)\]") for column in params_xml: alias = column.get(u'caption') internal_name = column.get(u'name') # type: unicode # Parameters are all given internal name [Parameter #], unless they are copies where they # end with (copy) h/t Jeff James for discovering regex_match = numbered_parameter_regex.match(internal_name) if regex_match and regex_match.group(1): param_num = int(regex_match.group(1)) # Move up the highest_param_num counter for when you add new ones if param_num > self._highest_param_num: self._highest_param_num = param_num p = TableauParameter(parameter_xml=column, logger_obj=self.logger) self._parameters.append(p)
def __init__(self, datasource_xml=None, logger_obj=None, ds_version=None): """ :type datasource_xml: etree.Element :type logger_obj: Logger """ TableauDocument.__init__(self) self._document_type = u'datasource' etree.register_namespace(u't', self.ns_map['t']) self.logger = logger_obj self._connections = [] self.ds_name = None self.ds_version = None self._published = False self.relation_xml_obj = None self.existing_tde_filename = None self.nsmap = {u"user": u'http://www.tableausoftware.com/xml/user'} # All used for creating from scratch self._tde_filename = None self.incremental_refresh_field = None self.join_relations = [] self.column_mapping = {} self.column_aliases = {} self.datasource_filters = [] self.extract_filters = [] self.initial_sql = None self.column_instances = [] self.main_table_relation = None self.main_table_name = None self._connection_root = None # Create from new or from existing object if datasource_xml is None: self.xml = self.create_new_datasource_xml() if ds_version is None: self.ds_version = u'10' else: self.ds_version = ds_version else: self.xml = datasource_xml if self.xml.get(u"caption"): self.ds_name = self.xml.attrib[u"caption"] elif self.xml.get(u"name"): self.ds_name = self.xml.attrib[u'name'] xml_version = self.xml.attrib[u'version'] # Determine whether it is a 9 style or 10 style federated datasource if xml_version in [u'9.0', u'9.1', u'9.2', u'9.3']: self.ds_version = u'9' else: self.ds_version = u'10' self.log(u'Data source is Tableau {} style'.format( self.ds_version)) # Create Connections # 9.0 style if self.ds_version == u'9': connection_xml_obj = self.xml.find(u'.//connection', self.ns_map) # Skip the relation if it is a Parameters datasource. Eventually, build out separate object if connection_xml_obj is None: self.log(u'Found a Parameters datasource') else: self.log( u'connection tags found, building a TableauConnection object' ) new_conn = TableauConnection(connection_xml_obj) self.connections.append(new_conn) # Grab the relation elif self.ds_version == u'10': named_connections = self.xml.findall(u'.//named-connection', self.ns_map) for named_connection in named_connections: self.log( u'connection tags found, building a TableauConnection object' ) self.connections.append( TableauConnection(named_connection)) # Check for published datasources, which look like 9.0 style still published_datasources = self.xml.findall( u'.//connection[@class="sqlproxy"]', self.ns_map) for published_datasource in published_datasources: self.log( u'Published Datasource connection tags found, building a TableauConnection object' ) self.connections.append( TableauConnection(published_datasource)) # Skip the relation if it is a Parameters datasource. Eventually, build out separate object if self.xml.get(u'name') != u'Parameters': self.relation_xml_obj = self.xml.find(u'.//relation', self.ns_map) self.read_existing_relations() else: self.log(u'Found a Parameters datasource') self.repository_location = None if self.xml.find(u'repository-location') is not None: if len(self.xml.find(u'repository-location')) == 0: self._published = True repository_location_xml = self.xml.find(u'repository-location') self.repository_location = repository_location_xml # Grab the extract filename if there is an extract section if self.xml.find(u'extract') is not None: e = self.xml.find(u'extract') c = e.find(u'connection') self.existing_tde_filename = c.get(u'dbname') # To make work as tableau_document from TableauFile self._datasources.append(self) self._columns = None # Possible, though unlikely, that there would be no columns if self.xml.find(u'column') is not None: columns_list = self.xml.findall(u'column') self._columns = TableauColumns(columns_list, self.logger) self._tde_filename = None self.ds_generator = None