Skip to content

Commit

Permalink
Merge pull request #104 from GoogleCloudPlatform/storage-transfer-update
Browse files Browse the repository at this point in the history
Adding standard module docstrings and argparse description to transfe…
  • Loading branch information
Jonathan Wayne Parrott committed Sep 18, 2015
2 parents d54f0a9 + 54d72e8 commit 000ff37
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
26 changes: 17 additions & 9 deletions storage/transfer_service/aws_request.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# Copyright 2015, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -10,20 +12,26 @@
# 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.
#

# [START all]
"""Command-line sample that creates a one-time transfer from Amazon S3 to
Google Cloud Storage.
This sample is used on this page:
https://cloud.google.com/storage/transfer/create-transfer
For more information, see README.md.
"""

import argparse
import datetime
import json
import logging

from apiclient import discovery
from oauth2client.client import GoogleCredentials


logging.basicConfig(level=logging.DEBUG)


# [START main]
def main(description, project_id, day, month, year, hours, minutes,
source_bucket, access_key, secret_access_key, sink_bucket):
Expand Down Expand Up @@ -69,13 +77,14 @@ def main(description, project_id, day, month, year, hours, minutes,
}

result = storagetransfer.transferJobs().create(body=transfer_job).execute()
logging.info('Returned transferJob: %s', json.dumps(result, indent=4))
print('Returned transferJob: {}'.format(
json.dumps(result, indent=4)))
# [END main]

if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Create a one-off transfer from Amazon S3 to Google Cloud '
'Storage.')
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('description', help='Transfer description.')
parser.add_argument('project_id', help='Your Google Cloud project ID.')
parser.add_argument('date', help='Date YYYY/MM/DD.')
Expand All @@ -102,5 +111,4 @@ def main(description, project_id, day, month, year, hours, minutes,
args.access_key,
args.secret_access_key,
args.sink_bucket)

# [END all]
9 changes: 1 addition & 8 deletions storage/transfer_service/create_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@
# 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.
#
# [START all]
import logging

# [START all]
from apiclient import discovery
from oauth2client.client import GoogleCredentials

CLOUD_SCOPES = 'https://www.googleapis.com/auth/cloud-platform'


def create_transfer_client():
"""Create a transfer client."""

logging.getLogger().setLevel(logging.DEBUG)
credentials = GoogleCredentials.get_application_default()
return discovery.build('storagetransfer', 'v1', credentials=credentials)
# [END all]
25 changes: 16 additions & 9 deletions storage/transfer_service/nearline_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@
# 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.
#

# [START all]

"""Command-line sample that creates a one-time transfer from Google Cloud
Storage standard class to the Nearline storage class."
This sample is used on this page:
https://cloud.google.com/storage/transfer/create-transfer
For more information, see README.md.
"""

import argparse
import datetime
import json
import logging

from apiclient import discovery
from oauth2client.client import GoogleCredentials


logging.basicConfig(level=logging.DEBUG)


# [START main]
def main(description, project_id, day, month, year, hours, minutes,
source_bucket, sink_bucket):
Expand Down Expand Up @@ -67,13 +74,14 @@ def main(description, project_id, day, month, year, hours, minutes,
}

result = storagetransfer.transferJobs().create(body=transfer_job).execute()
logging.info('Returned transferJob: %s', json.dumps(result, indent=4))
print('Returned transferJob: {}'.format(
json.dumps(result, indent=4)))
# [END main]

if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Create a transfer from the Google Cloud Storage Standard '
'class to the Nearline Storage class.')
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('description', help='Transfer description.')
parser.add_argument('project_id', help='Your Google Cloud project ID.')
parser.add_argument('date', help='Date YYYY/MM/DD.')
Expand All @@ -95,5 +103,4 @@ def main(description, project_id, day, month, year, hours, minutes,
time.minute,
args.source_bucket,
args.sink_bucket)

# [END all]
27 changes: 17 additions & 10 deletions storage/transfer_service/transfer_check.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env

# Copyright 2015, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -10,19 +12,25 @@
# 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.
#

# [START all]

"""Command-line sample that checks the status of an in-process transfer.
This sample is used on this page:
https://cloud.google.com/storage/transfer/create-transfer
For more information, see README.md.
"""

import argparse
import json
import logging

from apiclient import discovery
from oauth2client.client import GoogleCredentials


logging.basicConfig(level=logging.DEBUG)


# [START main]
def main(project_id, job_name):
"""Review the transfer operations associated with a transfer job."""
Expand All @@ -38,19 +46,18 @@ def main(project_id, job_name):
result = storagetransfer.transferOperations().list(
name="transferOperations",
filter=filterString).execute()
logging.info('Result of transferOperations/list: %s',
json.dumps(result, indent=4, sort_keys=True))
print('Result of transferOperations/list: {}'.format(
json.dumps(result, indent=4, sort_keys=True)))
# [END main]

if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Review the transfer operations associated with a '
'transfer job.')
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('project_id', help='Your Google Cloud project ID.')
parser.add_argument('job_name', help='Your job name.')

args = parser.parse_args()

main(args.project_id, args.job_name)

# [END all]

0 comments on commit 000ff37

Please sign in to comment.