Sample group filtering#199
Sample group filtering#199acpana merged 6 commits intotableau:developmenttableau/server-client-python:developmentfrom acpana:sample_group_filteringacpana/server-client-python:sample_group_filteringCopy head branch name to clipboard
Conversation
samples/group_filtering.py
Outdated
| group1 = TSC.GroupItem(group_name) | ||
| group1 = server.groups.create(group1) | ||
| print(group1) | ||
| except: |
There was a problem hiding this comment.
You should catch a specific set of exceptions rather than all of them
|
|
||
| group_name = 'SALES+ROMANIA' | ||
| options = TSC.RequestOptions() | ||
| options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, |
There was a problem hiding this comment.
Maybe add a comment to explain what you are going here
|
Just pushed a commit addressing past feedback. |
t8y8
left a comment
There was a problem hiding this comment.
Nits but I think they're worth it
samples/filter_sort_groups.py
Outdated
| parser.add_argument('-p', default=None) | ||
| args = parser.parse_args() | ||
|
|
||
| password = '' |
There was a problem hiding this comment.
This isn't necessary, the if/then should catch all cases
There was a problem hiding this comment.
Just to clarify, you mean it is not necessary to set passsword = '' ?
There was a problem hiding this comment.
correct, password gets set in all cases because args.p is either None, or it isn't.
So the initial password = '' is redundant. It doesn't hurt anything either :P
samples/filter_sort_groups.py
Outdated
| try: | ||
| group1 = TSC.GroupItem(group_name) | ||
| group1 = server.groups.create(group1) | ||
| print(group1) |
There was a problem hiding this comment.
Do we want to print something more meaningful than the repr of a group?
eg "Group created: "
samples/filter_sort_groups.py
Outdated
| try: | ||
| group2 = TSC.GroupItem(group_name) | ||
| group2 = server.groups.create(group2) | ||
| print(group2) |
samples/filter_sort_groups.py
Outdated
| TSC.RequestOptions.Operator.Equals, | ||
| filter_group_name)) | ||
|
|
||
| filtered_group_paged = server.groups.get(req_options=options) |
There was a problem hiding this comment.
Pager again (Samples aren't always just run against new servers, often it's existing servers)
samples/filter_sort_groups.py
Outdated
| filtered_group_paged = server.groups.get(req_options=options) | ||
|
|
||
| # Return type is a tuple with the first entry as a list of matching groups | ||
| print(filtered_group_paged[0][0].name) |
There was a problem hiding this comment.
tuple unpacking or comment please
samples/filter_sort_groups.py
Outdated
|
|
||
| filtered_groups, _ = server.groups.get(req_options=options) | ||
| # Result can either be a matching group or none | ||
| group_name = filtered_groups.pop().name if len(filtered_groups) != 0 else 'No project named \'' + str(filter_group_name) + '\' found ' |
There was a problem hiding this comment.
if filtered_groups:
group_name = filtered_groups.pop()
else:
error = "No project named '{}' found".format(filter_group_name)
print(error)
Reads cleaner to me, then we aren't overloading the group_name as either a name OR an error string.
Empty lists in python are false-y, so you can just truth test it (if filtered_groups). Or there's a bug, because len(None) will through an error.
I may run over to clarify some things
| import tableauserverclient as TSC | ||
|
|
||
|
|
||
| def create_example_group(group_name='Example Group', server=None): |
There was a problem hiding this comment.
None isn't actually a safe default, this should just be a standard required parameter.
* Sample group filtering script * Added comments and specific error catching * Renamed the file to follow the naming convention * commented on return type, example group creation, cleaned up code * Better way to call and catch return from rest api * Proper printing instructions
* Sample group filtering script * Added comments and specific error catching * Renamed the file to follow the naming convention * commented on return type, example group creation, cleaned up code * Better way to call and catch return from rest api * Proper printing instructions
Create python-package.yml
Added a script for group filtering.