Skip to content

Type 1: Ability to get items via the path #1317

Description

@VDFaller

Summary

Right now, to my knowledge, we have to get items via the filter. I'd like to just get_project("/path/to/project")

Description

I have my own created already but figured I'd make sure this is something that might be of value for others. It might need some clean up in order to fit y'alls standards but like I do something like this.

classmyTSC(TSC.Server):
"""A subclass of the tableau server client that adds some functionality"""def__init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
defget_project(self, path:Union[PurePath, str], parent_id=None, has_cxn:bool=False)->TSC.ProjectItem:
""" gets a project via a path ARGS: path - can either be a pathlib.PurePath or a string of the fully scoped path to the project '/A/B/C' (with or without the root is fine, it will assume root if parent_id is not given) parent_id - if you already know the parent id, you can pass it in has_cxn - if you already have a connection (used by the wrapper) RETURNS: TSC.ProjectItem - so to get the project id you'd do project.id EXAMPLE: > get_project('/path/to/my/project') > get_project(Path('/path/to/my/project')) """assertisinstance(path, (PurePath, str)), 'path must be Path or string'parts=Path(path).parts# we should warnifparent_idisNone:
ifnot (str(path).startswith('/') orstr(path).startswith('\\')):
warn(f"When 'parent_id' is None, 'path' should start with '/' for '{path}'")
elifstr(path).startswith('/') orstr(path).startswith('\\'):
raiseValueError('parent_id was given but path looks to be a root')
else:
assertisinstance(parent_id, str), "parent_id must be None or string"ifparts[0] in ('\\', '/'): # let people put in a root if they wantparts=parts[1:]
forppinparts: ## just for through the path parts and go deeper and deeper and check that it existsproject_found=FalseforpinTSC.Pager(self.projects):
ifp.name==ppandp.parent_id==parent_id:
project=pparent_id=project.id# setting the parent ID for the next project levelproject_found=Truelogger.debug(f"Found Project {pp}")
breakifnotproject_found: # fail if it doesn't find oneraiseEndpointUnavailableError('Project "'+'/'.join(parts[:parts.index(pp)+1])+'" Not Found')
returnprojectnew_server=myTSC(server.server_address, use_server_version=True)
withnew_server.auth.sign_in(tableau_auth):
project=new_server.get_project(Path('/path/to/my/project'))

Use case

I often have to pull very specific data sources and manipulate them in python. Then push them back up to tableau somewhere else.
This makes the configs for those projects much easier. If there's an easier way to do this I'd also be interested in that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions