-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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./
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix import order
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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.