From d4701d33c2a0ad9f2651d290c21c8fcec216a7f3 Mon Sep 17 00:00:00 2001 From: Justin Grilli Date: Fri, 1 Mar 2024 12:41:22 -0800 Subject: [PATCH] Updated logging and docstrings --- setup.py | 2 +- tableau_utilities/tableau_file/tableau_file.py | 14 ++++++++------ tableau_utilities/tableau_server/base.py | 1 + tableau_utilities/tableau_server/create.py | 1 + tableau_utilities/tableau_server/download.py | 1 + tableau_utilities/tableau_server/get.py | 1 + tableau_utilities/tableau_server/publish.py | 6 +++++- tableau_utilities/tableau_server/refresh.py | 1 + tableau_utilities/tableau_server/static.py | 1 + tableau_utilities/tableau_server/update.py | 1 + 10 files changed, 21 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 59609bb4..39f9d005 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ long_description=readme, long_description_content_type='text/markdown', name="tableau_utilities", - version="2.1.12", + version="2.1.13", packages=[ 'tableau_utilities', 'tableau_utilities.general', diff --git a/tableau_utilities/tableau_file/tableau_file.py b/tableau_utilities/tableau_file/tableau_file.py index 22356db3..567806ad 100644 --- a/tableau_utilities/tableau_file/tableau_file.py +++ b/tableau_utilities/tableau_file/tableau_file.py @@ -99,22 +99,24 @@ def save(self): dupe_temp_path = os.path.join(temp_folder, f'__tmp_{self.file_basename}') shutil.move(self.file_path, temp_path) # Unzip the zipped files + logging.info('Unzipping files from {}'.format(temp_path)) extracted_files = list() with ZipFile(temp_path) as z: for f in z.filelist: ext = f.filename.split('.')[-1] + if ext in ['tds', 'twb']: + xml_path = path logging.info('Extracting file {}'.format(f.filename)) path = z.extract(member=f, path=temp_folder) extracted_files.append(path) - if ext in ['tds', 'twb']: - xml_path = path - # Update XML file - logging.info('Extracting updating XML {}'.format(xml_path)) + # Overwrite XML file with new XML + logging.info('Overwriting XML file {}'.format(os.path.basename(xml_path))) self._tree.write(xml_path, encoding="utf-8", xml_declaration=True) - # Repack the unzipped file + logging.info('Zipping files into {}'.format(temp_path)) + # Repack the unzipped files with ZipFile(temp_path, 'w') as z: for file in extracted_files: - logging.info('Archiving {}'.format(file)) + logging.info('Archiving {}'.format(os.path.basename(file))) arcname = file.split(temp_folder)[-1] z.write(file, arcname=arcname) # Move file back to the original folder and remove any unpacked contents diff --git a/tableau_utilities/tableau_server/base.py b/tableau_utilities/tableau_server/base.py index 43395b10..7051df30 100644 --- a/tableau_utilities/tableau_server/base.py +++ b/tableau_utilities/tableau_server/base.py @@ -3,6 +3,7 @@ class Base: + """ Base functionality inherited by TableauServer class, and Core TableauServer classes """ def __init__(self, parent): self.session: Session = parent.session self.user: str = parent.user diff --git a/tableau_utilities/tableau_server/create.py b/tableau_utilities/tableau_server/create.py index d18a8adb..dd28434c 100644 --- a/tableau_utilities/tableau_server/create.py +++ b/tableau_utilities/tableau_server/create.py @@ -3,6 +3,7 @@ class Create(Base): + """ Core Create functionality of the TableauServer class """ def __init__(self, parent): super().__init__(parent) diff --git a/tableau_utilities/tableau_server/download.py b/tableau_utilities/tableau_server/download.py index 7aff26b2..1dcdd909 100644 --- a/tableau_utilities/tableau_server/download.py +++ b/tableau_utilities/tableau_server/download.py @@ -7,6 +7,7 @@ class Download(Base): + """ Core Download functionality of the TableauServer class """ def __init__(self, parent): super().__init__(parent) diff --git a/tableau_utilities/tableau_server/get.py b/tableau_utilities/tableau_server/get.py index 4e0a1820..ee7c9548 100644 --- a/tableau_utilities/tableau_server/get.py +++ b/tableau_utilities/tableau_server/get.py @@ -5,6 +5,7 @@ class Get(Base): + """ Core Get functionality of the TableauServer class """ def __init__(self, parent): super().__init__(parent) diff --git a/tableau_utilities/tableau_server/publish.py b/tableau_utilities/tableau_server/publish.py index 7304dfd4..a3df6933 100644 --- a/tableau_utilities/tableau_server/publish.py +++ b/tableau_utilities/tableau_server/publish.py @@ -11,6 +11,7 @@ class Publish(Base): + """ Core Publish functionality of the TableauServer class """ def __init__(self, parent): super().__init__(parent) @@ -100,8 +101,11 @@ def __upload_in_chunks(self, file_path, chunk_size_mb=5): ('request_payload', '', None, 'text/xml'), ('tableau_file', chunk, file_name, 'application/octet-stream') ]) + # Log progress every so often current += chunk_size_mb - logging.info('({} of {} mb) Uploading {}'.format(current if current < total else total, total, file_path)) + if current == chunk_size_mb or current % 500 == 0 or current >= total: + logging.info('({} of {} mb) Uploading {}'.format( + current if current < total else total, total, file_path)) self._put( f'{self.url}/fileUploads/{upload_session_id}', data=post_body, headers={'Content-Type': content_type} diff --git a/tableau_utilities/tableau_server/refresh.py b/tableau_utilities/tableau_server/refresh.py index 525948d0..f0993818 100644 --- a/tableau_utilities/tableau_server/refresh.py +++ b/tableau_utilities/tableau_server/refresh.py @@ -5,6 +5,7 @@ class Refresh(Base): + """ Core Refresh functionality of the TableauServer class """ def __init__(self, parent): super().__init__(parent) diff --git a/tableau_utilities/tableau_server/static.py b/tableau_utilities/tableau_server/static.py index 2352c114..7492e715 100644 --- a/tableau_utilities/tableau_server/static.py +++ b/tableau_utilities/tableau_server/static.py @@ -1,3 +1,4 @@ +""" Static functionality of the TableauServer and Core classes """ import requests from tableau_utilities.general.funcs import flatten_dict diff --git a/tableau_utilities/tableau_server/update.py b/tableau_utilities/tableau_server/update.py index 406ae845..10411a68 100644 --- a/tableau_utilities/tableau_server/update.py +++ b/tableau_utilities/tableau_server/update.py @@ -5,6 +5,7 @@ class Update(Base): + """ Core Update functionality of the TableauServer class """ def __init__(self, parent): super().__init__(parent)