Skip to content

Commit 8c78b10

Browse files
authored
Fix for #346 & #347 (#348)
* Fix for few issues * Fix mypy issue * Fix code format issues * Fix for issue #349 * Fixing mypy issue * Changing image resolution default value to high * code formatting changes
1 parent ee047d7 commit 8c78b10

19 files changed

Lines changed: 211 additions & 18 deletions

tabcmd/commands/auth/session.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tableauserverclient as TSC
77
import urllib3
88
from urllib3.exceptions import InsecureRequestWarning
9+
from urllib.parse import urlparse, urlunparse
910

1011
from tabcmd.version import version
1112
from tabcmd.commands.constants import Errors
@@ -61,7 +62,8 @@ def _update_session_data(self, args):
6162
# self.command = args.???
6263
self.username = args.username or self.username or ""
6364
self.username = self.username.lower()
64-
self.server_url = args.server or self.server_url or "http://localhost"
65+
server_base_url = self._get_server_base_url(args.server) if args.server else None
66+
self.server_url = server_base_url or self.server_url or "http://localhost"
6567
self.server_url = self.server_url.lower()
6668
if args.server is not None:
6769
self.site_name = None
@@ -481,3 +483,14 @@ def _remove_json(self):
481483
message = "Error clearing session data from {}: check and remove manually".format(file_path)
482484
self.logger.error(message)
483485
self.logger.error(e)
486+
487+
def _get_server_base_url(self, url: str):
488+
try:
489+
parsed = urlparse(url)
490+
scheme = parsed.scheme or "http"
491+
492+
# If netloc is empty, treat path as netloc and discard any extra path
493+
netloc = parsed.netloc or parsed.path.split("/")[0] # Keep only the domain
494+
return urlunparse((scheme, netloc, "", "", "", ""))
495+
except Exception as e:
496+
Errors.exit_with_error(self.logger, exception=e)

tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,18 @@ def apply_options_in_url(logger, request_options: TSC.RequestOptions, value: str
125125
request_options.max_age = 0 # type: ignore
126126
logger.debug("Set max age to {} from {}".format((TSC.ImageRequestOptions(request_options)).max_age, value))
127127
elif ":size" == setting_name:
128-
# this is only used by get as png
129-
try:
130-
height, width = setting_val.split(",")
131-
(TSC.ImageRequestOptions(request_options)).viz_height = int(height)
132-
(TSC.ImageRequestOptions(request_options)).viz_width = int(width)
133-
except Exception as oops:
134-
logger.warn("Unable to read image size options '{}', skipping".format(setting_val))
135-
logger.warn(oops)
128+
if isinstance(request_options, (TSC.ImageRequestOptions, TSC.PDFRequestOptions)):
129+
try:
130+
height, width = setting_val.split(",")
131+
request_options.viz_height = int(height)
132+
request_options.viz_width = int(width)
133+
except Exception as oops:
134+
logger.warn("Unable to read image size options '{}', skipping".format(setting_val))
135+
logger.warn(oops)
136+
else:
137+
logger.debug(
138+
"Request options are not of type ImageRequestOptions or PDFRequestOptions, skipping size setting"
139+
)
136140
else:
137141
logger.debug("Parameter[s] not recognized: {}".format(value))
138142

@@ -147,8 +151,10 @@ def apply_png_options(logger, request_options: TSC.ImageRequestOptions, args):
147151
request_options.viz_height = int(args.height)
148152
if args.width:
149153
request_options.viz_width = int(args.width)
150-
# Always request high-res images
151-
request_options.image_resolution = "high"
154+
if args.resolution and args.resolution != TSC.ImageRequestOptions.Resolution.High.lower():
155+
request_options.image_resolution = None
156+
else:
157+
request_options.image_resolution = TSC.ImageRequestOptions.Resolution.High.lower()
152158

153159
@staticmethod
154160
def apply_pdf_options(logger, request_options: TSC.PDFRequestOptions, args):

tabcmd/commands/datasources_and_workbooks/export_command.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from .datasources_workbooks_views_url_parser import DatasourcesWorkbooksAndViewsUrlParser
1111

1212
pagesize = TSC.PDFRequestOptions.PageType # type alias for brevity
13+
pageorientation = TSC.PDFRequestOptions.Orientation
14+
imageresolution = TSC.ImageRequestOptions.Resolution
15+
ImageResolutionStandard = "standard"
1316

1417

1518
class ExportCommand(DatasourcesAndWorkbooks):
@@ -29,7 +32,7 @@ def define_args(export_parser):
2932

3033
group.add_argument(
3134
"--pagelayout",
32-
choices=["landscape", "portrait"],
35+
choices=[pageorientation.Landscape, pageorientation.Portrait],
3336
type=str.lower,
3437
default=None,
3538
help="page orientation (landscape or portrait) of the exported PDF",
@@ -57,16 +60,20 @@ def define_args(export_parser):
5760
help="Set the page size of the exported PDF",
5861
)
5962

60-
group.add_argument(
61-
"--width", default=800, help="[Not Yet Implemented] Set the width of the image in pixels. Default is 800 px"
62-
)
63+
group.add_argument("--width", default=800, help=_("export.options.width"))
6364
group.add_argument("--filename", "-f", help="filename to store the exported data")
6465
group.add_argument("--height", default=600, help=_("export.options.height"))
6566
group.add_argument(
6667
"--filter",
6768
metavar="COLUMN=VALUE",
6869
help="Data filter to apply to the view",
6970
)
71+
group.add_argument(
72+
"--resolution",
73+
choices=[imageresolution.High, ImageResolutionStandard],
74+
type=str.lower,
75+
help=_("export.options.resolution"),
76+
)
7077

7178
"""
7279
Command to Export a view_name or workbook from Tableau Server and save

tabcmd/locales/de/tabcmd_messages_de.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export.options.pagelayout=Legt die Seitenausrichtung der exportierten PDF-Datei
175175
export.options.pagesize=Legt die Seitengröße der exportierten PDF-Datei fest. Zulässige Werte: {0} (Standard: „{1}“)
176176
export.options.pdf=Daten im PDF-Format exportieren
177177
export.options.png=Daten im PNG-Format exportieren
178+
export.options.resolution=Set the value to high to ensure maximum pixel density
178179
export.options.width=Legt die Breite fest. Muss ein Ganzzahlwert (Standard: 800 Pixel) sein
179180
export.short_description=Daten oder Bild einer Ansicht vom Server exportieren
180181
export.status=„{0}“ wird vom Server abgerufen...

tabcmd/locales/en/tabcmd_messages_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export.options.pagelayout=Sets the page orientation of the exported PDF. Legal v
175175
export.options.pagesize=Sets the page size of the exported PDF. Legal values: {0} (default: ''{1}'')
176176
export.options.pdf=Export data in PDF format
177177
export.options.png=Export data in PNG format
178+
export.options.resolution=Set the value to high to ensure maximum pixel density
178179
export.options.width=Sets the width. Must be an integer value (default: 800 pixels)
179180
export.short_description=Export the data or image of a view from the server
180181
export.status=Requesting ''{0}'' from the server...

tabcmd/locales/es/tabcmd_messages_es.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export.options.pagelayout=Configura la orientación de páginas del PDF exportad
175175
export.options.pagesize=Configura el tamaño de página del PDF exportado. Valores legales: {0} (valor predeterminado: “{1}”)
176176
export.options.pdf=Exportar datos en formato PDF
177177
export.options.png=Exportar datos en formato PNG
178+
export.options.resolution=Set the value to high to ensure maximum pixel density
178179
export.options.width=Configura el ancho. Debe ser un valor entero (valor predeterminado: 800 píxeles)
179180
export.short_description=Exportar los datos o la imagen de una vista del servidor
180181
export.status=Solicitando “{0}” al servidor...

tabcmd/locales/fr/tabcmd_messages_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export.options.pagelayout=Définit l’orientation de la page du PDF exporté. V
175175
export.options.pagesize=Définit la taille de page du PDF exporté. Valeurs admises : {0} (“{1}” par défaut).
176176
export.options.pdf=Exporter les données au format PDF
177177
export.options.png=Exporter les données au format PNG
178+
export.options.resolution=Set the value to high to ensure maximum pixel density
178179
export.options.width=Définit la largeur. Doit être un nombre entier (800 pixels par défaut)
179180
export.short_description=Exporter les données ou une image d’une vue depuis le serveur
180181
export.status=Requête de “{0}” en provenance du serveur...

tabcmd/locales/ga/tabcmd_messages_ga.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export.options.pagelayout=f683-表:Sets the page orientation of the exported PDF
175175
export.options.pagesize=70c0-表:Sets the page size of the exported PDF. Legal values: {0} (default: ‘{1}’)|桜
176176
export.options.pdf=3ecf-表:Export data in PDF format|桜
177177
export.options.png=9e8c-表:Export data in PNG format|桜
178+
export.options.resolution=Set the value to high to ensure maximum pixel density
178179
export.options.width=687b-表:Sets the width. Must be an integer value (default: 800 pixels)|桜
179180
export.short_description=3b4e-表:Export the data or image of a view from the server|桜
180181
export.status=e524-表:Requesting ‘{0}’ from the server...|桜

tabcmd/locales/it/tabcmd_messages_it.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export.options.pagelayout=Imposta l’orientamento della pagina del PDF esportat
175175
export.options.pagesize=Imposta le dimensioni della pagina del PDF esportato. Valori consentiti: {0} (predefiniti: “{1}”)
176176
export.options.pdf=Esporta i dati in formato PDF
177177
export.options.png=Esporta i dati in formato PNG
178+
export.options.resolution=Set the value to high to ensure maximum pixel density
178179
export.options.width=Imposta la profondità. Deve essere un valore intero (predefinito: 800 pixel)
179180
export.short_description=Esportare i dati o l’immagine di una vista dal server
180181
export.status=Richiesta di “{0}” dal server in corso...

tabcmd/locales/ja/tabcmd_messages_ja.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export.options.pagelayout=エクスポートされた PDF のページの方向
175175
export.options.pagesize=エクスポートされた PDF のページ サイズを設定します。有効な値: {0} (既定: 「{1}」)
176176
export.options.pdf=PDF 形式でデータをエクスポート
177177
export.options.png=PNG 形式でデータをエクスポート
178+
export.options.resolution=Set the value to high to ensure maximum pixel density
178179
export.options.width=幅を設定します。整数値であることが必要です (既定: 800 ピクセル)
179180
export.short_description=サーバーから、ビューのデータまたはイメージをエクスポート
180181
export.status=サーバーから 「{0}」 を要求しています...

0 commit comments

Comments
 (0)