Skip to content

syncing #1

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 22 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1cf4d1f
fixing translate-with-glossary bug (#2323)
crowdus Aug 8, 2019
7d01d74
Fix region tag (#2328)
averikitsch Aug 9, 2019
67260e9
Translate beta samples fix (#2327)
crowdus Aug 12, 2019
1db16b8
Print actual number of messages pulled (#2078)
olivercoad Aug 12, 2019
c7fdb13
Split Cloud Tasks snippet methods (#2332)
averikitsch Aug 12, 2019
a208992
Fix ssml_to_audio test (#2333)
crowdus Aug 12, 2019
4e44c60
Fix IoT parameters (#2320)
gguuss Aug 12, 2019
8ade7dd
Fix list devices in IoT sample (#2319)
gguuss Aug 12, 2019
767eaa3
Pub/Sub: fix subscriber async region tag mistake (#2334)
anguillanneuf Aug 13, 2019
5f4a9c4
Add DICOMweb retrieve instance/image and download them to machi… (#2331)
noerog Aug 13, 2019
9226981
IAM: added snippet for remove member (#2165)
DSdatsme Aug 14, 2019
0ce1495
Add `fs_update_document_increment` snippet (#2341)
BenWhitehead Aug 15, 2019
ff9a856
Fix Cloud SQL example (MySQL) (#2309)
joangro Aug 16, 2019
d821c97
Fix dependency security vulnerability
engelke Aug 16, 2019
e1d66d8
Using glossaries with tts and vision tutorial sample code (#2325)
crowdus Aug 19, 2019
267a74d
Update region tag for Cloud Tasks snippets (#2350)
averikitsch Aug 20, 2019
5907fab
increase test timeout (#2351)
averikitsch Aug 20, 2019
02998e8
Use print() function in both Python 2 and Python 3 (#2234)
cclauss Aug 20, 2019
7f60075
Makes quickstart more REPL friendly (#2354)
gguuss Aug 20, 2019
a02fa46
Fix style in tests (#2318)
gguuss Aug 20, 2019
41161fb
Change retrieve study output file to use .multipart extension (#2345)
noerog Aug 22, 2019
6996c8e
Asset: Add Real Time Feed API Sample Code (#2352)
cwxie-google Aug 23, 2019
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
26 changes: 22 additions & 4 deletions appengine/flexible/tasks/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,59 @@ def create_task_with_name(project, location, queue, task_name):


def delete_task(project, location, queue):
# [START taskqueues_setup]
# [START taskqueues_deleting_tasks]
client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'
# [START taskqueues_setup]

# [START taskqueues_deleting_tasks]
task_path = client.task_path(project, location, queue, 'foo')
response = client.delete_task(task_path)
# [END taskqueues_deleting_tasks]
return response


def purge_queue(project, location, queue):
# [START taskqueues_purging_tasks]
client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'

queue_path = client.queue_path(project, location, queue)
response = client.purge_queue(queue_path)
# [END taskqueues_purging_tasks]
return response


def pause_queue(project, location, queue):
# [START taskqueues_pause_queue]
client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'

queue_path = client.queue_path(project, location, queue)
response = client.pause_queue(queue_path)
# [END taskqueues_pause_queues]
return response


def delete_queue(project, location, queue):
# [START taskqueues_deleting_queues]
client = tasks.CloudTasksClient()

# TODO(developer): Uncomment these lines and replace with your values.
# project = 'my-project-id'
# location = 'us- central1'
# queue = 'queue1'

# [START taskqueues_deleting_queues]
queue_path = client.queue_path(project, location, queue)
response = client.delete_queue(queue_path)
# [END taskqueues_deleting_queues]
Expand Down
22 changes: 19 additions & 3 deletions appengine/flexible/tasks/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,30 @@ def test_create_task_with_name():

@pytest.mark.order6
def test_delete_task():
result = snippets.delete_task(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
assert result is None


@pytest.mark.order7
def test_purge_queue():
name = "projects/{}/locations/{}/queues/{}".format(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
result = snippets.delete_task(
result = snippets.purge_queue(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
assert name in result.name


@pytest.mark.order7
@pytest.mark.order8
def test_pause_queue():
name = "projects/{}/locations/{}/queues/{}".format(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
result = snippets.pause_queue(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
assert name in result.name


@pytest.mark.order9
def test_delete_queue():
result = snippets.delete_queue(
TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1)
Expand All @@ -89,7 +105,7 @@ def test_delete_queue():
assert result is None


@pytest.mark.order8
@pytest.mark.order10
def test_retry_task():
QUEUE_SIZE = 3
QUEUE_NAME = []
Expand Down
15 changes: 10 additions & 5 deletions appengine/standard/i18n/i18n_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
The idea of this example, especially for how to translate strings in
Javascript is originally from an implementation of Django i18n.
"""

from __future__ import print_function

import gettext
import json
Expand All @@ -31,6 +31,11 @@

from webob import Request

try:
basestring
except NameError:
basestring = str


def _get_plural_forms(js_translations):
"""Extracts the parameters for what constitutes a plural.
Expand All @@ -49,15 +54,15 @@ def _get_plural_forms(js_translations):
for l in js_translations._catalog[''].split('\n'):
if l.startswith('Plural-Forms:'):
plural = l.split(':', 1)[1].strip()
print "plural is %s" % plural
print('plural is {}'.format(plural))
if plural is not None:
for raw_element in plural.split(';'):
element = raw_element.strip()
if element.startswith('nplurals='):
n_plural = int(element.split('=', 1)[1])
elif element.startswith('plural='):
plural = element.split('=', 1)[1]
print "plural is now %s" % plural
print('plural is now {}'.format(plural))
else:
n_plural = 2
plural = '(n == 1) ? 0 : 1'
Expand All @@ -83,9 +88,9 @@ def convert_translations_to_dict(js_translations):
for key, value in js_translations._catalog.items():
if key == '':
continue
if type(key) in (str, unicode):
if isinstance(key, basestring):
translations_dict['catalog'][key] = value
elif type(key) == tuple:
elif isinstance(key, tuple):
if key[0] not in translations_dict['catalog']:
translations_dict['catalog'][key[0]] = [''] * n_plural
translations_dict['catalog'][key[0]][int(key[1])] = value
Expand Down
3 changes: 2 additions & 1 deletion appengine/standard/mail/header.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -40,7 +41,7 @@ def get(self):
</form></body></html>""")

def post(self):
print repr(self.request.POST)
print(repr(self.request.POST))
id = self.request.POST['thread_id']
send_example_mail('{}@appspot.gserviceaccount.com'.format(
app_identity.get_application_id()), id)
Expand Down
3 changes: 2 additions & 1 deletion appengine/standard/ndb/properties/snippets.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -147,4 +148,4 @@ class Part(ndb.Model):

def print_part():
p1 = Part(name='foo', color=Color.RED)
print p1.color # prints "RED"
print(p1.color) # prints "RED"
3 changes: 2 additions & 1 deletion appengine/standard/ndb/queries/snippets_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -343,7 +344,7 @@ def test_fetch_message_accounts_inefficient(testbed):

assert len(message_account_pairs) == 5

print repr(message_account_pairs)
print(repr(message_account_pairs))
for i in range(1, 6):
message, account = message_account_pairs[i - 1]
assert message.content == 'Message %s' % i
Expand Down
2 changes: 1 addition & 1 deletion appengine/standard_python37/django/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Django==2.1.10
Django==2.1.11
PyMySQL==0.9.3
51 changes: 51 additions & 0 deletions asset/cloud-client/quickstart_createfeed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python

# Copyright 2019 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import argparse


def create_feed(project_id, feed_id, asset_names, topic):
# [START asset_quickstart_create_feed]
from google.cloud import asset_v1p2beta1
from google.cloud.asset_v1p2beta1.proto import asset_service_pb2

# TODO project_id = 'Your Google Cloud Project ID'
# TODO feed_id = 'Feed ID you want to create'
# TODO asset_names = 'List of asset names the feed listen to'
# TODO topic = "Topic name of the feed"

client = asset_v1p2beta1.AssetServiceClient()
parent = "projects/{}".format(project_id)
feed = asset_service_pb2.Feed()
feed.asset_names.extend(asset_names)
feed.feed_output_config.pubsub_destination.topic = topic
response = client.create_feed(parent, feed_id, feed)
print('feed: {}'.format(response))
# [END asset_quickstart_create_feed]


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('project_id', help='Your Google Cloud project ID')
parser.add_argument('feed_id', help='Feed ID you want to create')
parser.add_argument('asset_names',
help='List of asset names the feed listen to')
parser.add_argument('topic', help='Topic name of the feed')
args = parser.parse_args()
create_feed(args.project_id, args.feed_id, args.asset_names, args.topic)
44 changes: 44 additions & 0 deletions asset/cloud-client/quickstart_createfeed_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python

# Copyright 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
import os
import time

import quickstart_createfeed
import quickstart_deletefeed
from google.cloud import resource_manager

json_data = open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]).read()
data = json.loads(json_data)
PROJECT = data['project_id']
ASSET_NAME = 'assets-{}'.format(int(time.time()))
FEED_ID = 'feed-{}'.format(int(time.time()))
TOPIC = 'topic-{}'.format(int(time.time()))


def test_create_feed(capsys):
client = resource_manager.Client()
project_number = client.fetch_project(PROJECT).number
full_topic_name = "projects/{}/topics/{}".format(PROJECT, TOPIC)
quickstart_createfeed.create_feed(
PROJECT, FEED_ID, [ASSET_NAME, ], full_topic_name)
out, _ = capsys.readouterr()
assert "feed" in out

# Clean up, delete the feed
feed_name = "projects/{}/feeds/{}".format(project_number, FEED_ID)
quickstart_deletefeed.delete_feed(feed_name)
39 changes: 39 additions & 0 deletions asset/cloud-client/quickstart_deletefeed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python

# Copyright 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import argparse


def delete_feed(feed_name):
# [START asset_quickstart_delete_feed]
from google.cloud import asset_v1p2beta1

# TODO feed_name = 'Feed name you want to delete'

client = asset_v1p2beta1.AssetServiceClient()
client.delete_feed(feed_name)
print('deleted_feed')
# [END asset_quickstart_delete_feed]


if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('feed_name', help='Feed name you want to delete')
args = parser.parse_args()
delete_feed(args.feed_name)
42 changes: 42 additions & 0 deletions asset/cloud-client/quickstart_deletefeed_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python

# Copyright 2018 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import time

import quickstart_createfeed
import quickstart_deletefeed
from google.cloud import resource_manager

PROJECT = os.environ['GCLOUD_PROJECT']
ASSET_NAME = 'assets-{}'.format(int(time.time()))
FEED_ID = 'feed-{}'.format(int(time.time()))
TOPIC = 'topic-{}'.format(int(time.time()))


def test_delete_feed(capsys):
client = resource_manager.Client()
project_number = client.fetch_project(PROJECT).number
# First create the feed, which will be deleted later
full_topic_name = "projects/{}/topics/{}".format(PROJECT, TOPIC)
quickstart_createfeed.create_feed(
PROJECT, FEED_ID, [ASSET_NAME, ], full_topic_name)

feed_name = "projects/{}/feeds/{}".format(project_number, FEED_ID)
quickstart_deletefeed.delete_feed(feed_name)

out, _ = capsys.readouterr()
assert "deleted_feed" in out
Loading