8000 Add example for retrieving a large file from Cloud Storage onto a device by noerog · Pull Request #1350 · GoogleCloudPlatform/python-docs-samples · GitHub
[go: up one dir, main page]

Skip to content

Add example for retrieving a large file from Cloud Storage onto a device #1350

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 11 commits into from
Feb 16, 2018

Conversation

noerog
Copy link
Contributor
@noerog noerog commented Feb 6, 2018

The main use case for this example is for devices to be able to retrieve configuration updates that are larger than 64 KB, as 64 KB is the current limit (https://cloud.google.com/iot/docs/concepts/limitations). A sample binary file is provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 6, 2018
@theacodes theacodes requested a review from gguuss February 6, 2018 23:04
Copy link
Contributor
@gguuss gguuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix the lint errors
  • Run the doc generator script on README.rst.in
  • I see you have a big binary blob in this commit, consider removing it if possible as large files make clones slower and accumulate over time
  • Copyright dates typically have year of first publication

url: https://cloud.google.com/iot/docs
description: >
`Google Cloud IoT Core`_ allows developers to easily integrate Publish and
Subscribe functionality with devices and programmatically manage device
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/programmatically manage device auth/programmatically authorize devices./

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,252 @@
# Copyright 2017 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the first commit of the file, update year to 2018, same for other headers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

file: gcs_send_to_device.py
show_help: True

cloud_client_library: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you run the doc generation script to get the restructured text back?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done.

devices and running them all at the same time.
"""

import argparse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix imports so they pass lint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return '{}: {}'.format(rc, mqtt.error_string(rc))


class Device(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample code generally avoids OO programming because it adds complexity, so use static methods if possible. If you can't work around having your device object, it's ok for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep as-is for now if it's OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM.

# 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.
r"""Sample script that pushes a large (~1MB) file to Google Cloud IoT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We generally avoid long descriptions in our sample code. Consider moving this content to the docs if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Comments now just describe what the program does.

storage_client = storage.Client()

try:
bucket = storage_client.create_bucket(bucket_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint doesn't like that this variable is assigned but never used, maybe just don't assign the result from create_bucket

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

import json
import os

from googleapiclient import discovery
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix import order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

# See the License for the specific language governing permissions and
# limitations under the License.

import mock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint doesn't like the import order here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -0,0 +1,176 @@
# Copyright 2017 Google, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date on copyright to 2018

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@theacodes theacodes merged commit 7a96771 into GoogleCloudPlatform:master Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0