8000 Enable Black for CI and add as dependency by bcantoni · Pull Request #935 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Enable Black for CI and add as dependency #935

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

Merged
merged 5 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
python -m pip install --upgrade pip
pip install -e .[test]

- name: Format with black
run: |
black --check --line-length 120 tableauserverclient samples test

- name: Test with pytest
run: |
pytest test
Expand Down
32 changes: 18 additions & 14 deletions samples/add_default_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@


def main():
parser = argparse.ArgumentParser(description='Add workbook default permissions for a given project.')
parser = argparse.ArgumentParser(description="Add workbook default permissions for a given project.")
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument(
"--logging-level",
"-l",
choices=["debug", "info", "error"],
default="error",
help="desired logging level (set to error by default)",
)
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

Expand Down Expand Up @@ -53,10 +60,7 @@ def main():
new_capabilities = {TSC.Permission.Capability.ExportXml: TSC.Permission.Mode.Allow}

# Each PermissionRule in the list contains a grantee and a dict of capabilities
new_rules = [TSC.PermissionsRule(
grantee=default_permissions.grantee,
capabilities=new_capabilities
)]
new_rules = [TSC.PermissionsRule(grantee=default_permissions.grantee, capabilities=new_capabilities)]

new_default_permissions = server.projects.update_workbook_default_permissions(project, new_rules)

Expand All @@ -78,5 +82,5 @@ def main():
# server.projects.delete(project.id)


if __name__ == '__main__':
if __name__ == "__main__":
main()
29 changes: 18 additions & 11 deletions samples/create_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@

def main():

parser = argparse.ArgumentParser(description='Creates a sample user group.')
parser = argparse.ArgumentParser(description="Creates a sample user group.")
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument(
"--logging-level",
"-l",
choices=["debug", "info", "error"],
default="error",
help="desired logging level (set to error by default)",
)
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

Expand All @@ -38,10 +45,10 @@ def main():
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):
group = TSC.GroupItem('test')
group = TSC.GroupItem("test")
group = server.groups.create(group)
print(group)


if __name__ == '__main__':
if __name__ == "__main__":
main()
37 changes: 22 additions & 15 deletions samples/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17 FFA4 ,31 @@
def create_project(server, project_item, samples=False):
try:
project_item = server.projects.create(project_item, samples)
print('Created a new project called: %s' % project_item.name)
print("Created a new project called: %s" % project_item.name)
return project_item
except TSC.ServerResponseError:
print('We have already created this project: %s' % project_item.name)
print("We have already created this project: %s" % project_item.name)
sys.exit(1)


def main():
parser = argparse.ArgumentParser(description='Create new projects.')
parser = argparse.ArgumentParser(description="Create new projects.")
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument(
"--logging-level",
"-l",
choices=["debug", "info", "error"],
default="error",
help="desired logging level (set to error by default)",
)
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

Expand All @@ -52,20 +59,20 @@ def main():
server.use_server_version()

# Without parent_id specified, projects are created at the top level.
top_level_project = TSC.ProjectItem(name='Top Level Project')
top_level_project = TSC.ProjectItem(name="Top Level Project")
top_level_project = create_project(server, top_level_project)

# Specifying parent_id creates a nested projects.
child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id)
child_project = TSC.ProjectItem(name="Child Project", parent_id=top_level_project.id)
child_project = create_project(server, child_project, samples=True)

# Projects can be nested at any level.
grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id)
grand_child_project = TSC.ProjectItem(name="Grand Child Project", parent_id=child_project.id)
grand_child_project = create_project(server, grand_child_project)

# Projects can be updated
changed_project = server.projects.update(grand_child_project, samples=True)


if __name__ == '__main__':
if __name__ == "__main__":
main()
79 changes: 51 additions & 28 deletions samples/create_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@

def main():

parser = argparse.ArgumentParser(description='Creates sample schedules for each type of frequency.')
parser = argparse.ArgumentParser(description="Creates sample schedules for each type of frequency.")
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument(
"--logging-level",
"-l",
choices=["debug", "info", "error"],
default="error",
help="desired logging level (set to error by default)",
)
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

Expand All @@ -40,43 +47,59 @@ def main():
with server.auth.sign_in(tableau_auth):
# Hourly Schedule
# This schedule will run every 2 hours between 2:30AM and 11:00PM
hourly_interval = TSC.HourlyInterval(start_time=time(2, 30),
end_time=time(23, 0),
interval_value=2)

hourly_schedule = TSC.ScheduleItem("Hourly-Schedule", 50, TSC.ScheduleItem.Type.Extract,
TSC.ScheduleItem.ExecutionOrder.Parallel, hourly_interval)
hourly_interval = TSC.HourlyInterval(start_time=time(2, 30), end_time=time(23, 0), interval_value=2)

hourly_schedule = TSC.ScheduleItem(
"Hourly-Schedule",
50,
TSC.ScheduleItem.Type.Extract,
TSC.ScheduleItem.ExecutionOrder.Parallel,
hourly_interval,
)
hourly_schedule = server.schedules.create(hourly_schedule)
print("Hourly schedule created (ID: {}).".format(hourly_schedule.id))

# Daily Schedule
# This schedule will run every day at 5AM
daily_interval = TSC.DailyInterval(start_time=time(5))
daily_schedule = TSC.ScheduleItem("Daily-Schedule", 60, TSC.ScheduleItem.Type.Subscription,
TSC.ScheduleItem.ExecutionOrder.Serial, daily_interval)
daily_schedule = TSC.ScheduleItem(
"Daily-Schedule",
60,
TSC.ScheduleItem.Type.Subscription,
TSC.ScheduleItem.ExecutionOrder.Serial,
daily_interval,
)
daily_schedule = server.schedules.create(daily_schedule)
print("Daily schedule created (ID: {}).".format(daily_schedule.id))

# Weekly Schedule
# This schedule will wun every Monday, Wednesday, and Friday at 7:15PM
weekly_interval = TSC.WeeklyInterval(time(19, 15),
TSC.IntervalItem.Day.Monday,
TSC.IntervalItem.Day.Wednesday,
TSC.IntervalItem.Day.Friday)
weekly_schedule = TSC.ScheduleItem("Weekly-Schedule", 70, TSC.ScheduleItem.Type.Extract,
TSC.ScheduleItem.ExecutionOrder.Serial, weekly_interval)
weekly_interval = TSC.WeeklyInterval(
time(19, 15), TSC.IntervalItem.Day.Monday, TSC.IntervalItem.Day.Wednesday, TSC.IntervalItem.Day.Friday
)
weekly_schedule = TSC.ScheduleItem(
"Weekly-Schedule",
70,
TSC.ScheduleItem.Type.Extract,
TSC.ScheduleItem.ExecutionOrder.Serial,
weekly_interval,
)
weekly_schedule = server.schedules.create(weekly_schedule)
print("Weekly schedule created (ID: {}).".format(weekly_schedule.id))

# Monthly Schedule
# This schedule will run on the 15th of every month at 11:30PM
monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30),
interval_value=15)
monthly_schedule = TSC.ScheduleItem("Monthly-Schedule", 80, TSC.ScheduleItem.Type.Subscription,
TSC.ScheduleItem.ExecutionOrder.Parallel, monthly_interval)
monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30), interval_value=15)
monthly_schedule = TSC.ScheduleItem(
"Monthly-Schedule",
80,
TSC.ScheduleItem.Type.Subscription,
TSC.ScheduleItem.ExecutionOrder.Parallel,
monthly_interval,
)
monthly_schedule = server.schedules.create(monthly_schedule)
print("Monthly schedule created (ID: {}).".format(monthly_schedule.id))


if __name__ == '__main__':
if __name__ == "__main__":
main()
44 changes: 26 additions & 18 deletions samples/download_view_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,27 @@

def main():

parser = argparse.ArgumentParser(description='Download image of a specified view.')
parser = argparse.ArgumentParser(description="Download image of a specified view.")
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument(
"--logging-level",
"-l",
choices=["debug", "info", "error"],
default="error",
help="desired logging level (set to error by default)",
)
# Options specific to this sample
parser.add_argument('--view-name', '-vn', required=True,
help='name of view to download an image of')
parser.add_argument('--filepath', '-f', required=True, help='filepath to save the image returned')
parser.add_argument('--maxage', '-m', required=False, help='max age of the image in the cache in minutes.')
parser.add_argument("--view-name", "-vn", required=True, help="name of view to download an image of")
parser.add_argument("--filepath", "-f", required=True, help="filepath to save the image returned")
parser.add_argument("--maxage", "-m", required=False, help="max age of the image in the cache in minutes.")

args = parser.parse_args()

Expand All @@ -44,8 +50,9 @@ def main():
with server.auth.sign_in(tableau_auth):
# Step 2: Query for the view that we want an image of
req_option = TSC.RequestOptions()
req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.Equals, args.view_name))
req_option.filter.add(
TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, args.view_name)
)
all_views, pagination_item = server.views.get(req_option)
if not all_views:
raise LookupError("View with the specified name was not found.")
Expand All @@ -55,8 +62,9 @@ def main():
if not max_age:
max_age = 1

image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High,
maxage=max_age)
image_req_option = TSC.ImageRequestOptions(
imageresolution=TSC.ImageRequestOptions.Resolution.High, maxage=max_age
)
server.views.populate_image(view_item, image_req_option)

with open(args.filepath, "wb") as image_file:
Expand All @@ -65,5 +73,5 @@ def main():
print("View image saved to {0}".format(args.filepath))


if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading
0