Skip to content

Commit

Permalink
Bugfixes on logger and replaced the isinstance() type checking with t…
Browse files Browse the repository at this point in the history
…ype( ).__name__ so no need to import classes to check
  • Loading branch information
Bryant Howell committed Jan 3, 2020
1 parent 169f423 commit 82917e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def start_log_block(self):
short_class = short_class[:-2]
cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).encode('utf-8')

log_line = '{}vv-- {} : {} {} started --------vv\n'.format(" "*self.log_depth, cur_time, short_class, caller_function_name)
log_line = '{}vv-- {} : {} {} started --------vv\n'.format(" "*self.log_depth, str(cur_time), short_class, caller_function_name)
# Only move the log depth in debug mode
if self._log_modes['debug'] is True:
self.log_depth += 2
Expand All @@ -68,7 +68,7 @@ def end_log_block(self):
cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()).encode('utf-8')
if self._log_modes['debug'] is True:
self.log_depth -= 2
log_line = '{}^^-- {} : {} {} ended --------^^\n'.format(" "*self.log_depth, cur_time, short_class, caller_function_name)
log_line = '{}^^-- {} : {} {} ended --------^^\n'.format(" "*self.log_depth, str(cur_time), short_class, caller_function_name)

self.__log_handle.write(log_line.encode('utf-8'))

Expand All @@ -78,9 +78,9 @@ def log_uri(self, uri: str, verb: str):
def log_xml_request(self, xml: Union[ET.Element, str], verb: str, uri: str):
if self._log_modes['request'] is True:
if isinstance(xml, str):
self.log('[{}}] \n{}'.format(verb.upper(), xml))
self.log('[{}] \n{}'.format(verb.upper(), xml))
else:
self.log('[{}}] \n{}'.format(verb.upper(), ET.tostring(xml)))
self.log('[{}] \n{}'.format(verb.upper(), ET.tostring(xml)))
else:
self.log('[{}] {}'.format(verb.upper(), uri))

Expand Down
12 changes: 6 additions & 6 deletions tableau_rest_api/published_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,18 +950,18 @@ def are_permissions_locked(self) -> bool:
def lock_permissions(self):
self.start_log_block()
if self.permissions_locked is False:
if(type(self.t_rest_api).__name__.contains('TableauRestApiConnection')):
if(type(self.t_rest_api).__name__.find('TableauRestApiConnection') != -1):
self.t_rest_api.update_project(self.luid, locked_permissions=True)
if(type(self.t_rest_api).__name__.contains('TableauServerRest')):
if(type(self.t_rest_api).__name__.find('TableauServerRest') != -1):
self.t_rest_api.projects.update_project(self.luid, locked_permissions=True)
self.end_log_block()

def unlock_permissions(self):
self.start_log_block()
if self.permissions_locked is True:
if(isinstance(self.t_rest_api, TableauRestApiConnection)):
if(type(self.t_rest_api).__name__.find('TableauRestApiConnection') != -1):
self.t_rest_api.update_project(self.luid, locked_permissions=False)
if(isinstance(self.t_rest_api, TableauServerRest)):
if(type(self.t_rest_api).__name__.find('TableauServerRest') != -1):
self.t_rest_api.projects.update_project(self.luid, locked_permissions=False)

self.end_log_block()
Expand Down Expand Up @@ -1047,9 +1047,9 @@ def parent_project_luid(self) -> str:

def query_child_projects(self) -> ET.Element:
self.start_log_block()
if (isinstance(self.t_rest_api, TableauRestApiConnection)):
if (type(self.t_rest_api).__name__.find('TableauRestApiConnection') != -1):
projects = self.t_rest_api.query_projects()
elif (isinstance(self.t_rest_api, TableauServerRest)):
elif(type(self.t_rest_api).__name__.find('TableauServerRest') != -1):
projects = self.t_rest_api.projects.query_projects()
else:
raise InvalidOptionException('t_rest_api needs to be either TableauRestApiConnection or TableauServerRest descended')
Expand Down

0 comments on commit 82917e4

Please sign in to comment.