-
Notifications
You must be signed in to change notification settings - Fork 16
Implement command line and url parameters for get/export #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
491120c
432c289
e393bdc
79b6630
68de73e
3f2540f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ def get_view_by_content_url(logger, server, view_content_url) -> TSC.ViewItem: | |
| req_option.filter.add(TSC.Filter("contentUrl", TSC.RequestOptions.Operator.Equals, view_content_url)) | ||
| matching_views, paging = server.views.get(req_option) | ||
| except TSC.ServerResponseError as e: | ||
| Errors.exit_with_error(logger, _("publish.errors.unexpected_server_response").format("")) | ||
| Errors.exit_with_error(logger, _("publish.errors.unexpected_server_response").format(e)) | ||
| if len(matching_views) < 1: | ||
| Errors.exit_with_error(logger, message=_("errors.xmlapi.not_found")) | ||
| return matching_views[0] | ||
|
|
@@ -42,3 +42,76 @@ def get_wb_by_content_url(logger, server, workbook_content_url) -> TSC.WorkbookI | |
| if len(matching_workbooks) < 1: | ||
| Errors.exit_with_error(logger, message=_("dataalerts.failure.error.workbookNotFound")) | ||
| return matching_workbooks[0] | ||
|
|
||
| @staticmethod | ||
| def apply_values_from_url_params(request_options: TSC.PDFRequestOptions, url, logger) -> None: | ||
| # should be able to replace this with request_options._append_view_filters(params) | ||
| logger.debug(url) | ||
| try: | ||
| if "?" in url: | ||
| query = url.split("?")[1] | ||
| logger.trace("Query parameters: {}".format(query)) | ||
| else: | ||
| logger.debug("No query parameters present in url") | ||
| return | ||
|
|
||
| params = query.split("&") | ||
| logger.trace(params) | ||
| for value in params: | ||
| if value.startswith(":"): | ||
| DatasourcesAndWorkbooks.apply_option_value(request_options, value, logger) | ||
| else: # it must be a filter | ||
| DatasourcesAndWorkbooks.apply_filter_value(request_options, value, logger) | ||
|
|
||
| except BaseException as e: | ||
| logger.warn("Error building filter params", e) | ||
| # ExportCommand.log_stack(logger) # type: ignore | ||
|
|
||
| @staticmethod | ||
| def apply_filter_value(request_options: TSC.PDFRequestOptions, value: str, logger) -> None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the apply_filter_value and apply_option_value methods be moved to a class that is more relevant ? |
||
| # todo: do we need to strip Parameters.x -> x? | ||
| logger.trace("handling filter param {}".format(value)) | ||
| data_filter = value.split("=") | ||
| request_options.vf(data_filter[0], data_filter[1]) | ||
|
|
||
| @staticmethod | ||
| def apply_option_value(request_options: TSC.PDFRequestOptions, value: str, logger) -> None: | ||
| logger.trace("handling url option {}".format(value)) | ||
| setting = value.split("=") | ||
| if ":iid" == setting[0]: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: this block might read better inside a switch case |
||
| logger.debug(":iid value ignored in url") | ||
| elif ":refresh" == setting[0] and DatasourcesAndWorkbooks.is_truthy(setting[1]): | ||
| # mypy is worried that this is readonly | ||
| request_options.max_age = 0 # type:ignore | ||
| logger.debug("Set max age to {} from {}".format(request_options.max_age, value)) | ||
| elif ":size" == setting[0]: | ||
| height, width = setting[1].split(",") | ||
| logger.warn("Height/weight parameters not yet implemented ({})".format(value)) | ||
| else: | ||
| logger.debug("Parameter[s] not recognized: {}".format(value)) | ||
|
|
||
| @staticmethod | ||
| def is_truthy(value: str): | ||
| return value.lower() in ["yes", "y", "1", "true"] | ||
|
|
||
| @staticmethod | ||
| 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 | ||
|
|
||
| @staticmethod | ||
| def save_to_data_file(logger, output, filename): | ||
| logger.info(_("httputils.found_attachment").format(filename)) | ||
| with open(filename, "wb") as f: | ||
| f.writelines(output) | ||
| logger.info(_("export.success").format("", filename)) | ||
|
|
||
| @staticmethod | ||
| def save_to_file(logger, output, filename): | ||
| logger.info(_("httputils.found_attachment").format(filename)) | ||
| with open(filename, "wb") as f: | ||
| f.write(output) | ||
| logger.info(_("export.success").format("", filename)) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming that the url type is a string. If yes, can we be sure that the url will always be decoded at this point in the code. Also, is there a url library in python that can abstract getting params from urls that we could use instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a string, yes. It's not a full url, it's the representation of the workbook/view as it would be in a url (tabcmd get "/views/Sales_Analysis/Sales_Report.png") - I'm actually not quite sure how we handle encoding yet and have to do some comparison with behaviors in the original tabcmd, but it's possible a proper library will be better.