From 7f80c5fdc389b3ac244497613f62dbfa46cb2a17 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Sun, 9 Oct 2022 00:10:02 -0700 Subject: [PATCH 1/4] fix order of initializing variables --- tabcmd/commands/auth/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabcmd/commands/auth/session.py b/tabcmd/commands/auth/session.py index a380ab73..188c0581 100644 --- a/tabcmd/commands/auth/session.py +++ b/tabcmd/commands/auth/session.py @@ -44,8 +44,8 @@ def __init__(self): self.timeout = None self.logging_level = "info" - self._read_from_json() self.logger = log(__class__.__name__, self.logging_level) # instantiate here mostly for tests + self._read_from_json() self.tableau_server = None # this one is an object that doesn't get persisted in the file # called before we connect to the server From 1bf2e4255f74b58643edc80ad8fa8e1bf383d5a5 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Sun, 9 Oct 2022 00:51:08 -0700 Subject: [PATCH 2/4] Fix image export https://github.com/tableau/tabcmd/issues/184 --- .../datasources_and_workbooks_command.py | 4 ++-- tabcmd/commands/datasources_and_workbooks/export_command.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py b/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py index 86536550..9887ab63 100644 --- a/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py +++ b/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py @@ -99,8 +99,8 @@ def apply_png_options(request_options: TSC.ImageRequestOptions, args, logger): if args.height or args.width: # only applicable for png logger.warn("Height/width arguments not yet implemented in export") - if args.image_resolution: - request_options.image_resolution = args.image_resolution + # Always request high-res images + request_options.image_resolution = "high" @staticmethod def save_to_data_file(logger, output, filename): diff --git a/tabcmd/commands/datasources_and_workbooks/export_command.py b/tabcmd/commands/datasources_and_workbooks/export_command.py index 2e714543..2e9c4340 100644 --- a/tabcmd/commands/datasources_and_workbooks/export_command.py +++ b/tabcmd/commands/datasources_and_workbooks/export_command.py @@ -148,7 +148,7 @@ def download_png(server, view_item, args, logger): DatasourcesAndWorkbooks.apply_png_options(image_options, args, logger) logger.trace(image_options) server.views.populate_image(view_item, image_options) - return view_item.png + return view_item.image @staticmethod def parse_export_url_to_workbook_and_view(logger, url): From 2bff5c782d0a6495638f7f092f035257ae95a542 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Sun, 9 Oct 2022 00:52:19 -0700 Subject: [PATCH 3/4] implement pdf layout/page type --- .../datasources_and_workbooks_command.py | 7 +++++ .../export_command.py | 30 +++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py b/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py index 9887ab63..1eadb3a5 100644 --- a/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py +++ b/tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py @@ -102,6 +102,13 @@ def apply_png_options(request_options: TSC.ImageRequestOptions, args, logger): # Always request high-res images request_options.image_resolution = "high" + @staticmethod + def apply_pdf_options(request_options: TSC.PDFRequestOptions, args, logger): + request_options.page_type = args.pagesize + if args.pagelayout: + logger.debug("Setting page layout to: {}".format(args.pagelayout)) + request_options.orientation = args.pagelayout + @staticmethod def save_to_data_file(logger, output, filename): logger.info(_("httputils.found_attachment").format(filename)) diff --git a/tabcmd/commands/datasources_and_workbooks/export_command.py b/tabcmd/commands/datasources_and_workbooks/export_command.py index 2e9c4340..f326943c 100644 --- a/tabcmd/commands/datasources_and_workbooks/export_command.py +++ b/tabcmd/commands/datasources_and_workbooks/export_command.py @@ -6,6 +6,8 @@ from tabcmd.execution.logger_config import log from .datasources_and_workbooks_command import DatasourcesAndWorkbooks +pagesize = TSC.PDFRequestOptions.PageType # type alias for brevity + class ExportCommand(DatasourcesAndWorkbooks): @@ -24,13 +26,17 @@ def define_args(export_parser): export_parser.add_argument( "--pagelayout", choices=["landscape", "portrait"], - default="landscape", + default=None, help="page orientation (landscape or portrait) of the exported PDF", ) - export_parser.add_argument("--pagesize", default="letter", help="Set the page size of the exported PDF") export_parser.add_argument( - "--image-resolution", default="High", help="Set the image resolution of the exported image" - ) + "--pagesize", + choices=[pagesize.A3, pagesize.A4, pagesize.A5, pagesize.B4, pagesize.B5, pagesize.Executive, pagesize.Folio, + pagesize.Ledger, pagesize.Legal, pagesize.Letter, pagesize.Note, pagesize.Quarto, pagesize.Tabloid, + pagesize.Unspecified + ], + default="letter", + help="Set the page size of the exported PDF") export_parser.add_argument( "--width", default=800, help="Set the width of the image in pixels. Default is 800 px" @@ -111,42 +117,42 @@ def apply_values_from_args(request_options: TSC.PDFRequestOptions, args, logger= @staticmethod def download_wb_pdf(server, workbook_item, args, logger): - logger.trace(args.url) + logger.debug(args.url) pdf_options = TSC.PDFRequestOptions(maxage=1) ExportCommand.apply_values_from_url_params(pdf_options, args.url, logger) ExportCommand.apply_values_from_args(pdf_options, args, logger) - logger.trace(pdf_options) + logger.debug(pdf_options.get_query_params()) server.workbooks.populate_pdf(workbook_item, pdf_options) return workbook_item.pdf @staticmethod def download_view_pdf(server, view_item, args, logger): - logger.trace(args.url) + logger.debug(args.url) pdf_options = TSC.PDFRequestOptions(maxage=1) ExportCommand.apply_values_from_url_params(pdf_options, args.url, logger) ExportCommand.apply_values_from_args(pdf_options, args, logger) - logger.trace(pdf_options) + logger.debug(pdf_options.get_query_params()) server.views.populate_pdf(view_item, pdf_options) return view_item.pdf @staticmethod def download_csv(server, view_item, args, logger): - logger.trace(args.url) + logger.debug(args.url) csv_options = TSC.CSVRequestOptions(maxage=1) ExportCommand.apply_values_from_url_params(csv_options, args.url, logger) ExportCommand.apply_values_from_args(csv_options, args, logger) - logger.trace(csv_options) + logger.debug(csv_options.get_query_params()) server.views.populate_csv(view_item, csv_options) return view_item.csv @staticmethod def download_png(server, view_item, args, logger): - logger.trace(args.url) + logger.debug(args.url) image_options = TSC.ImageRequestOptions(maxage=1) ExportCommand.apply_values_from_url_params(image_options, args.url, logger) ExportCommand.apply_values_from_args(image_options, args, logger) DatasourcesAndWorkbooks.apply_png_options(image_options, args, logger) - logger.trace(image_options) + logger.debug(image_options.get_query_params()) server.views.populate_image(view_item, image_options) return view_item.image From 610df676171a1dc1d5749eb1bf3f3bf55d5f8941 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Sun, 9 Oct 2022 01:19:03 -0700 Subject: [PATCH 4/4] format w black --- .../export_command.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tabcmd/commands/datasources_and_workbooks/export_command.py b/tabcmd/commands/datasources_and_workbooks/export_command.py index f326943c..79ddedb6 100644 --- a/tabcmd/commands/datasources_and_workbooks/export_command.py +++ b/tabcmd/commands/datasources_and_workbooks/export_command.py @@ -31,12 +31,25 @@ def define_args(export_parser): ) export_parser.add_argument( "--pagesize", - choices=[pagesize.A3, pagesize.A4, pagesize.A5, pagesize.B4, pagesize.B5, pagesize.Executive, pagesize.Folio, - pagesize.Ledger, pagesize.Legal, pagesize.Letter, pagesize.Note, pagesize.Quarto, pagesize.Tabloid, - pagesize.Unspecified + choices=[ + pagesize.A3, + pagesize.A4, + pagesize.A5, + pagesize.B4, + pagesize.B5, + pagesize.Executive, + pagesize.Folio, + pagesize.Ledger, + pagesize.Legal, + pagesize.Letter, + pagesize.Note, + pagesize.Quarto, + pagesize.Tabloid, + pagesize.Unspecified, ], default="letter", - help="Set the page size of the exported PDF") + help="Set the page size of the exported PDF", + ) export_parser.add_argument( "--width", default=800, help="Set the width of the image in pixels. Default is 800 px"