Skip to content

Commit

Permalink
Implemented a data_file_replacement_map method on TableauFile, for sw…
Browse files Browse the repository at this point in the history
…apping in new CSV, XLS, or Hyper files that are generated programmatically into an existing TWBX or TDSX.
  • Loading branch information
Bryant Howell committed Apr 15, 2019
1 parent de67c7a commit 7de408d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
22 changes: 17 additions & 5 deletions tableau_documents/tableau_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ def tableau_document(self):
return self._tableau_document

# Appropriate extension added if needed
def save_new_file(self, new_filename_no_extension):
def save_new_file(self, new_filename_no_extension, data_file_replacement_map=None):
"""
:type new_filename_no_extension: unicode
:type data_file_replacement_map: dict
:rtype: unicode
"""
self.start_log_block()
Expand Down Expand Up @@ -194,9 +195,16 @@ def save_new_file(self, new_filename_no_extension):
self.log(u'File {} is from an extract that has been replaced, skipping'.format(filename))
continue

o_zf.extract(filename)
new_zf.write(filename)
os.remove(filename)
# If file is listed in the data_file_replacement_map, write data from the mapped in file
if filename in data_file_replacement_map:
#data_file_obj = open(filename, mode='wb')
#data_file_obj.write(data_file_replacement_map[filename])
#data_file_obj.close()
new_zf.write(data_file_replacement_map[filename], u"/" + filename)
else:
o_zf.extract(filename)
new_zf.write(filename)
os.remove(filename)
self.log(u'Removed file {}'.format(filename))
lowest_level = filename.split('/')
temp_directories_to_remove[lowest_level[0]] = True
Expand All @@ -211,7 +219,11 @@ def save_new_file(self, new_filename_no_extension):
# Cleanup all the temporary directories
for directory in temp_directories_to_remove:
self.log(u'Removing directory {}'.format(directory))
shutil.rmtree(directory)
try:
shutil.rmtree(directory)
except OSError as e:
# Just means that directory didn't exist for some reason, probably a swap occurred
pass
new_zf.close()

return save_filename
Expand Down
12 changes: 9 additions & 3 deletions tableau_rest_api/tableau_rest_api_connection_33.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,24 @@ def publish_workbook(self, workbook_filename, workbook_name, project_obj, overwr

# Flow Methods Start

def query_flows_for_a_site(self, sorts=None):

def query_flow_luid(self, flow_name):
pass

def query_flows(self, sorts=None):
self.start_log_block()
flows = self.query_resource('flows', sorts=sorts)

self.end_log_block()
return flows

# Just an alias for the method
def query_flows(self):
return self.query_flows_for_a_site()
def query_flows_for_a_site(self):
return self.query_flows()

def query_flows_for_a_user(self, username_or_luid):
pass

def run_flow_now(self):
pass
# Flow Methods End

0 comments on commit 7de408d

Please sign in to comment.