8000 Squashed commit of the following: · jorwoods/server-client-python@15a7211 · GitHub
[go: up one dir, main page]

Skip to content

Commit 15a7211

Browse files
committed
Squashed commit of the following:
commit b836f33 Author: Brian Cantoni <bcantoni@salesforce.com> Date: Thu Jan 27 19:29:50 2022 -0800 WIP: Enable Black for CI and add as dependency (tableau#935) * Enable Black for CI and add as dependency * Bulk reformat with Black, line length 120 Co-authored-by: Jac Fitzgerald <jac.fitzgerald@salesforce.com>
1 parent 0b74782 commit 15a7211

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3106
-2768
lines changed

.github/workflows/run-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
python -m pip install --upgrade pip
2626
pip install -e .[test]
2727
28+
- name: Format with black
29+
run: |
30+
black --check --line-length 120 tableauserverclient samples test
31+
2832
- name: Test with pytest
2933
run: |
3034
pytest test

samples/add_default_permission.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@
1616

1717

1818
def main():
19-
parser = argparse.ArgumentParser(description='Add workbook default permissions for a given project.')
19+
parser = argparse.ArgumentParser(description="Add workbook default permissions for a given project.")
2020
# Common options; please keep those in sync across all samples
21-
parser.add_argument('--server', '-s', required=True, help='server address')
22-
parser.add_argument('--site', '-S', help='site name')
23-
parser.add_argument('--token-name', '-p', required=True,
24-
help='name of the personal access token used to sign into the server')
25-
parser.add_argument('--token-value', '-v', required=True,
26-
help='value of the personal access token used to sign into the server')
27-
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
28-
help='desired logging level (set to error by default)')
21+
parser.add_argument("--server", "-s", required=True, help="server address")
22+
parser.add_argument("--site", "-S", help="site name")
23+
parser.add_argument(
24+
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
25+
)
26+
parser.add_argument(
27+
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
28+
)
29+
parser.add_argument(
30+
"--logging-level",
31+
"-l",
32+
choices=["debug", "info", "error"],
33+
default="error",
34+
help="desired logging level (set to error by default)",
35+
)
2936
# Options specific to this sample
3037
# This sample has no additional options, yet. If you add some, please add them here
3138

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

5562
# Each PermissionRule in the list contains a grantee and a dict of capabilities
56-
new_rules = [TSC.PermissionsRule(
57-
grantee=default_permissions.grantee,
58-
capabilities=new_capabilities
59-
)]
63+
new_rules = [TSC.PermissionsRule(grantee=default_permissions.grantee, capabilities=new_capabilities)]
6064

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

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

8084

81-
if __name__ == '__main__':
85+
if __name__ == "__main__":
8286
main()

samples/create_group.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@
1616

1717
def main():
1818

19-
parser = argparse.ArgumentParser(description='Creates a sample user group.')
19+
parser = argparse.ArgumentParser(description="Creates a sample user group.")
2020
# Common options; please keep those in sync across all samples
21-
parser.add_argument('--server', '-s', required=True, help='server address')
22-
parser.add_argument('--site', '-S', help='site name')
23-
parser.add_argument('--token-name', '-p', required=True,
24-
help='name of the personal access token used to sign into the server')
25-
parser.add_argument('--token-value', '-v', required=True,
26-
help='value of the personal access token used to sign into the server')
27-
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
28-
help='desired logging level (set to error by default)')
21+
parser.add_argument("--server", "-s", required=True, help="server address")
22+
parser.add_argument("--site", "-S", help="site name")
23+
parser.add_argument(
24+
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
25+
)
26+
parser.add_argument(
27+
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
28+
)
29+
parser.add_argument(
30+
"--logging-level",
31+
"-l",
32+
choices=["debug", "info", "error"],
33+
default="error",
34+
help="desired logging level (set to error by default)",
35+
)
2936
# Options specific to this sample
3037
# This sample has no additional options, yet. If you add some, please add them here
3138

@@ -38,10 +45,10 @@ def main():
3845
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
3946
server = TSC.Server(args.server, use_server_version=True)
4047
with server.auth.sign_in(tableau_auth):
41-
group = TSC.GroupItem('test')
48+
group = TSC.GroupItem("test")
4249
group = server.groups.create(group)
4350
print(group)
4451

4552

46-
if __name__ == '__main__':
53+
if __name__ == "__main__":
4754
main()

samples/create_project.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,31 @@
1717
def create_project(server, project_item, samples=False):
1818
try:
1919
project_item = server.projects.create(project_item, samples)
20-
print('Created a new project called: %s' % project_item.name)
20+
print("Created a new project called: %s" % project_item.name)
2121
return project_item
2222
except TSC.ServerResponseError:
23-
print('We have already created this project: %s' % project_item.name)
23+
print("We have already created this project: %s" % project_item.name)
2424
sys.exit(1)
2525

2626

2727
def main():
28-
parser = argparse.ArgumentParser(description='Create new projects.')
28+
parser = argparse.ArgumentParser(description="Create new projects.")
2929
# Common options; please keep those in sync across all samples
30-
parser.add_argument('--server', '-s', required=True, help='server address')
31-
parser.add_argument('--site', '-S', help='site name')
32-
parser.add_argument('--token-name', '-p', required=True,
33-
help='name of the personal access token used to sign into the server')
34-
parser.add_argument('--token-value', '-v', required=True,
35-
help='value of the personal access token used to sign into the server')
36-
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
37-
help='desired logging level (set to error by default)')
30+
parser.add_argument("--server", "-s", required=True, help="server address")
31+
parser.add_argument("--site", "-S", help="site name")
32+
parser.add_argument(
33+
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
34+
)
35+
parser.add_argument(
36+
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
37+
)
38+
parser.add_argument(
39+
"--logging-level",
40+
"-l",
41+
choices=["debug", "info", "error"],
42+
default="error",
43+
help="desired logging level (set to error by default)",
44+
)
3845
# Options specific to this sample
3946
# This sample has no additional options, yet. If you add some, please add them here
4047

@@ -52,20 +59,20 @@ def main():
5259
server.use_server_version()
5360

5461
# Without parent_id specified, projects are created at the top level.
55-
top_level_project = TSC.ProjectItem(name='Top Level Project')
62+
top_level_project = TSC.ProjectItem(name="Top Level Project")
5663
top_level_project = create_project(server, top_level_project)
5764

5865
# Specifying parent_id creates a nested projects.
59-
child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id)
66+
child_project = TSC.ProjectItem(name="Child Project", parent_id=top_level_project.id)
6067
child_project = create_project(server, child_project, samples=True)
6168

6269
# Projects can be nested at any level.
63-
grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id)
70+
grand_child_project = TSC.ProjectItem(name="Grand Child Project", parent_id=child_project.id)
6471
grand_child_project = create_project(server, grand_child_project)
6572

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

6976

70-
if __name__ == '__main__':
77+
if __name__ == "__main__":
7178
main()

samples/create_schedules.py

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@
1616

1717
def main():
1818

19-
parser = argparse.ArgumentParser(description='Creates sample schedules for each type of frequency.')
19+
parser = argparse.ArgumentParser(description="Creates sample schedules for each type of frequency.")
2020
# Common options; please keep those in sync across all samples
21-
parser.add_argument('--server', '-s', required=True, help='server address')
22-
parser.add_argument('--site', '-S', help='site name')
23-
parser.add_argument('--token-name', '-p', required=True,
24-
help='name of the personal access token used to sign into the server')
25-
parser.add_argument('--token-value', '-v', required=True,
26-
help='value of the personal access token used to sign into the server')
27-
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
28-
help='desired logging level (set to error by default)')
21+
parser.add_argument("--server", "-s", required=True, help="server address")
22+
parser.add_argument("--site", "-S", help="site name")
23+
parser.add_argument(
24+
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
25+
)
26+
parser.add_argument(
27+
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
28+
)
29+
parser.add_argument(
30+
"--logging-level",
31+
"-l",
32+
choices=["debug", "info", "error"],
33+
default="error",
34+
help="desired logging level (set to error by default)",
35+
)
2936
# Options specific to this sample
3037
# This sample has no additional options, yet. If you add some, please add them here
3138

@@ -40,43 +47,59 @@ def main():
4047
with server.auth.sign_in(tableau_auth):
4148
# Hourly Schedule
4249
# This schedule will run every 2 hours between 2:30AM and 11:00PM
43-
hourly_interval = TSC.HourlyInterval(start_time=time(2, 30),
44-
end_time=time(23, 0),
45-
interval_value=2)
46-
47-
hourly_schedule = TSC.ScheduleItem("Hourly-Schedule", 50, TSC.ScheduleItem.Type.Extract,
48-
TSC.ScheduleItem.ExecutionOrder.Parallel, hourly_interval)
50+
hourly_interval = TSC.HourlyInterval(start_time=time(2, 30), end_time=time(23, 0), interval_value=2)
51+
52+
hourly_schedule = TSC.ScheduleItem(
53+
"Hourly-Schedule",
54+
50,
55+
TSC.ScheduleItem.Type.Extract,
56+
TSC.ScheduleItem.ExecutionOrder.Parallel,
57+
hourly_interval,
58+
)
4959
hourly_schedule = server.schedules.create(hourly_schedule)
5060
print("Hourly schedule created (ID: {}).".format(hourly_schedule.id))
5161

5262
# Daily Schedule
5363
# This schedule will run every day at 5AM
5464
daily_interval = TSC.DailyInterval(start_time=time(5))
55-
daily_schedule = TSC.ScheduleItem("Daily-Schedule", 60, TSC.ScheduleItem.Type.Subscription,
56-
TSC.ScheduleItem.ExecutionOrder.Serial, daily_interval)
65+
daily_schedule = TSC.ScheduleItem(
66+
"Daily-Schedule",
67+
60,
68+
TSC.ScheduleItem.Type.Subscription,
69+
TSC.ScheduleItem.ExecutionOrder.Serial,
70+
daily_interval,
71+
)
5772
daily_schedule = server.schedules.create(daily_schedule)
5873
print("Daily schedule created (ID: {}).".format(daily_schedule.id))
5974

6075
# Weekly Schedule
6176
# This schedule will wun every Monday, Wednesday, and Friday at 7:15PM
62-
weekly_interval = TSC.WeeklyInterval(time(19, 15),
63-
TSC.IntervalItem.Day.Monday,
64-
TSC.IntervalItem.Day.Wednesday,
65-
TSC.IntervalItem.Day.Friday)
66-
weekly_schedule = TSC.ScheduleItem("Weekly-Schedule", 70, TSC.ScheduleItem.Type.Extract,
67-
TSC.ScheduleItem.ExecutionOrder.Serial, weekly_interval)
77+
weekly_interval = TSC.WeeklyInterval(
78+
time(19, 15), TSC.IntervalItem.Day.Monday, TSC.IntervalItem.Day.Wednesday, TSC.IntervalItem.Day.Friday
79+
)
80+
weekly_schedule = TSC.ScheduleItem(
81+
"Weekly-Schedule",
82+
70,
83+
TSC.ScheduleItem.Type.Extract,
84+
TSC.ScheduleItem.ExecutionOrder.Serial,
85+
weekly_interval,
86+
)
6887
weekly_schedule = server.schedules.create(weekly_schedule)
6988
print("Weekly schedule created (ID: {}).".format(weekly_schedule.id))
7089

7190
# Monthly Schedule
7291
# This schedule will run on the 15th of every month at 11:30PM
73-
monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30),
74-
interval_value=15)
75-
monthly_schedule = TSC.ScheduleItem("Monthly-Schedule", 80, TSC.ScheduleItem.Type.Subscription,
76-
TSC.ScheduleItem.ExecutionOrder.Parallel, monthly_interval)
92+
monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30), interval_value=15)
93+
monthly_schedule = TSC.ScheduleItem(
94+
"Monthly-Schedule",
95+
80,
96+
TSC.ScheduleItem.Type.Subscription,
97+
TSC.ScheduleItem.ExecutionOrder.Parallel,
98+
monthly_interval,
99+
)
77100
monthly_schedule = server.schedules.create(monthly_schedule)
78101
print("Monthly schedule created (ID: {}).".format(monthly_schedule.id))
79102

80103

81-
if __name__ == '__main__':
104+
if __name__ == "__main__":
82105
main()

samples/download_view_image.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,27 @@
1616

1717
def main():
1818

19-
parser = argparse.ArgumentParser(description='Download image of a specified view.')
19+
parser = argparse.ArgumentParser(description="Download image of a specified view.")
2020
# Common options; please keep those in sync across all samples
21-
parser.add_argument('--server', '-s', required=True, help='server address')
22-
parser.add_argument('--site', '-S', help='site name')
23-
parser.add_argument('--token-name', '-p', required=True,
24-
help='name of the personal access token used to sign into the server')
25-
parser.add_argument('--token-value', '-v', required=True,
26-
help='value of the personal access token used to sign into the server')
27-
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
28-
help='desired logging level (set to error by default)')
21+
parser.add_argument("--server", "-s", required=True, help="server address")
22+
parser.add_argument("--site", "-S", help="site name")
23+
parser.add_argument(
24+
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
25+
)
26+
parser.add_argument(
27+
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
28+
)
29+
parser.add_argument(
30+
"--logging-level",
31+
"-l",
32+
choices=["debug", "info", "error"],
33+
default="error",
34+
help="desired logging level (set to error by default)",
35+
)
2936
# Options specific to this sample
30-
parser.add_argument('--view-name', '-vn', required=True,
31-
help='name of view to download an image of')
32-
parser.add_argument('--filepath', '-f', required=True, help='filepath to save the image returned')
33-
parser.add_argument('--maxage', '-m', required=False, help='max age of the image in the cache in minutes.')
37+
parser.add_argument("--view-name", "-vn", required=True, help="name of view to download an image of")
38+
parser.add_argument("--filepath", "-f", required=True, help="filepath to save the image returned")
39+
parser.add_argument("--maxage", "-m", required=False, help="max age of the image in the cache in minutes.")
3440

3541
args = parser.parse_args()
3642

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

58-
image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High,
59-
maxage=max_age)
65+
image_req_option = TSC.ImageRequestOptions(
66+
imageresolution=TSC.ImageRequestOptions.Resolution.High, maxage=max_age
67+
)
6068
server.views.populate_image(view_item, image_req_option)
6169

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

6775

68-
if __name__ == '__main__':
76+
if __name__ == "__main__":
6977
main()

0 commit comments

Comments
 (0)
0