-
Notifications
You must be signed in to change notification settings - Fork 178
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
Create New Connections per #68 #69
Changes from 3 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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
############################################################################### | ||
import collections | ||
import itertools | ||
import random | ||
import string | ||
import xml.etree.ElementTree as ET | ||
import xml.sax.saxutils as sax | ||
|
||
|
@@ -38,6 +40,7 @@ def _is_used_by_worksheet(names, field): | |
|
||
|
||
class FieldDictionary(MultiLookupDict): | ||
|
||
def used_by_sheet(self, name): | ||
# If we pass in a string, no need to get complicated, just check to see if name is in | ||
# the field's list of worksheets | ||
|
@@ -63,7 +66,15 @@ def _column_object_from_metadata_xml(metadata_xml): | |
return _ColumnObjectReturnTuple(field_object.id, field_object) | ||
|
||
|
||
def make_unique_name(dbclass): | ||
rand_part = ''.join(random.choice( | ||
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. Our unique names are a hash based on the current time, so we should probably do that rather than random data. I can find the relevant code if you need it. 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. Please! |
||
string.ascii_lowercase + string.digits) for _ in range(28)) | ||
name = dbclass + '.' + rand_part | ||
return name | ||
|
||
|
||
class ConnectionParser(object): | ||
|
||
def __init__(self, datasource_xml, version): | ||
self._dsxml = datasource_xml | ||
self._dsversion = version | ||
|
@@ -116,6 +127,20 @@ def from_file(cls, filename): | |
dsxml = xml_open(filename, cls.__name__.lower()).getroot() | ||
return cls(dsxml, filename) | ||
|
||
@classmethod | ||
def from_scratch(cls, caption, 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. Is this ever called by the end user? I'm not sold on this name. 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. Yeah, it'd be what you call, I just changed it to from_connections when I fixed a bug in my next commit, though that name isn't sexy either |
||
root = ET.Element('datasource', caption=caption, version='10.0') | ||
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. I feel like we are going to do this pattern a bunch. Would it make more sense to build up a logical model that we can then automatically serialize into the xml in some way rather than hard coding specific xml manipulations? 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. Yes, I was thinking about some sort of DSBuilder or something, the direct XML feels gross. It would also allow us to specify different versions (at least 9.3 vs 10) |
||
outer_connection = ET.SubElement(root, 'connection') | ||
outer_connection.set('class', 'federated') | ||
named_conns = ET.SubElement(outer_connection, 'named-connections') | ||
for conn in connections: | ||
nc = ET.SubElement(named_conns, | ||
'named-connection', | ||
name=make_unique_name(conn.dbclass), | ||
caption=conn.server) | ||
nc.append(conn._connectionXML) | ||
return cls(root) | ||
|
||
def save(self): | ||
""" | ||
Call finalization code and save file. | ||
|
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.
Totally a bug in my dbclass code.