-
Notifications
You must be signed in to change notification settings - Fork 182
Implemented ConnectionParser to handle Federated and Legacy connections #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
__version__ = '0.0.1' | ||
__VERSION__ = __version__ | ||
from .connection import Connection | ||
from .datasource import Datasource | ||
from .datasource import Datasource, ConnectionParser | ||
from .workbook import Workbook |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,25 @@ | |
import xml.etree.ElementTree as ET | ||
from tableaudocumentapi import Connection | ||
|
||
class ConnectionParser(object): | ||
|
||
def __init__(self, datasource_xml, version): | ||
self._dsxml = datasource_xml | ||
self._dsversion = version | ||
|
||
def _extract_federated_connections(self): | ||
return list(map(Connection,self._dsxml.findall('.//named-connections/named-connection/*'))) | ||
|
||
def _extract_legacy_connection(self): | ||
return Connection(self._dsxml.find('connection')) | ||
|
||
def get_connections(self): | ||
if float(self._dsversion) < 10: | ||
connections = self._extract_legacy_connection() | ||
else: | ||
connections = self._extract_federated_connections() | ||
return connections | ||
|
||
|
||
class Datasource(object): | ||
""" | ||
|
@@ -28,7 +47,8 @@ def __init__(self, dsxml, filename=None): | |
self._datasourceTree = ET.ElementTree(self._datasourceXML) | ||
self._name = self._datasourceXML.get('name') or self._datasourceXML.get('formatted-name') # TDS files don't have a name attribute | ||
self._version = self._datasourceXML.get('version') | ||
self._connection = Connection(self._datasourceXML.find('connection')) | ||
self._connection_parser = ConnectionParser(self._datasourceXML, version=self._version) | ||
self._connection = self._connection_parser.get_connections() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are returning a list, connection needs to be plural (same for the accessor) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That breaks the existing API, but that's probably ok because only the sample needs to be updated :) @benlower and I discussed always returning a list for connections, even in the legacy case, what do you think? I have that change shelved already and can add it to the PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "existing" api doesn't exist yet. :) I think we are okay for just a bit longer and then will have to worry about versioining and such but (a) we are still in BETA and (b) we haven't even released the BETA. :) And I am good with returning a list even for older datasources. Consistent API. I don't want users having to put if cases for version numbers. |
||
|
||
@classmethod | ||
def from_file(cls, filename): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm beginning to wonder if we shouldn't have a different class for the NamedConnection that just mimics the old interface, but can handle things like the caption and other attributes that legacy connections don't have.
But that might be more than we need right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spoke to Sundeep, and he confirmed I can ignore the named-connection elements for Server purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more. 8000
Fine for now. In the end, we should have separate classes for parsing 10.0+ vs prior connections. This current format, I think, will lead to potentially a good number of if else cases. I think there can be inheritance. Just a note for going forward. For now ... I wouldn't bother.