Skip to content

Commit 000ff37

Browse files
author
Jonathan Wayne Parrott
committed
Merge pull request #104 from GoogleCloudPlatform/storage-transfer-update
Adding standard module docstrings and argparse description to transfe…
2 parents d54f0a9 + 54d72e8 commit 000ff37

File tree

4 files changed

+51
-36
lines changed

4 files changed

+51
-36
lines changed

storage/transfer_service/aws_request.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
13
# Copyright 2015, Google, Inc.
24
# Licensed under the Apache License, Version 2.0 (the "License");
35
# you may not use this file except in compliance with the License.
@@ -10,20 +12,26 @@
1012
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1113
# See the License for the specific language governing permissions and
1214
# limitations under the License.
13-
#
15+
1416
# [START all]
17+
"""Command-line sample that creates a one-time transfer from Amazon S3 to
18+
Google Cloud Storage.
19+
20+
This sample is used on this page:
21+
22+
https://cloud.google.com/storage/transfer/create-transfer
23+
24+
For more information, see README.md.
25+
"""
26+
1527
import argparse
1628
import datetime
1729
import json
18-
import logging
1930

2031
from apiclient import discovery
2132
from oauth2client.client import GoogleCredentials
2233

2334

24-
logging.basicConfig(level=logging.DEBUG)
25-
26-
2735
# [START main]
2836
def main(description, project_id, day, month, year, hours, minutes,
2937
source_bucket, access_key, secret_access_key, sink_bucket):
@@ -69,13 +77,14 @@ def main(description, project_id, day, month, year, hours, minutes,
6977
}
7078

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

7584
if __name__ == '__main__':
7685
parser = argparse.ArgumentParser(
77-
description='Create a one-off transfer from Amazon S3 to Google Cloud '
78-
'Storage.')
86+
description=__doc__,
87+
formatter_class=argparse.RawDescriptionHelpFormatter)
7988
parser.add_argument('description', help='Transfer description.')
8089
parser.add_argument('project_id', help='Your Google Cloud project ID.')
8190
parser.add_argument('date', help='Date YYYY/MM/DD.')
@@ -102,5 +111,4 @@ def main(description, project_id, day, month, year, hours, minutes,
102111
args.access_key,
103112
args.secret_access_key,
104113
args.sink_bucket)
105-
106114
# [END all]

storage/transfer_service/create_client.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,13 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
13-
#
14-
# [START all]
15-
import logging
1613

14+
# [START all]
1715
from apiclient import discovery
1816
from oauth2client.client import GoogleCredentials
1917

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

2319
def create_transfer_client():
24-
"""Create a transfer client."""
25-
26-
logging.getLogger().setLevel(logging.DEBUG)
2720
credentials = GoogleCredentials.get_application_default()
2821
return discovery.build('storagetransfer', 'v1', credentials=credentials)
2922
# [END all]

storage/transfer_service/nearline_request.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,27 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
13-
#
13+
1414
# [START all]
15+
16+
"""Command-line sample that creates a one-time transfer from Google Cloud
17+
Storage standard class to the Nearline storage class."
18+
19+
This sample is used on this page:
20+
21+
https://cloud.google.com/storage/transfer/create-transfer
22+
23+
For more information, see README.md.
24+
"""
25+
1526
import argparse
1627
import datetime
1728
import json
18-
import logging
1929

2030
from apiclient import discovery
2131
from oauth2client.client import GoogleCredentials
2232

2333

24-
logging.basicConfig(level=logging.DEBUG)
25-
26-
2734
# [START main]
2835
def main(description, project_id, day, month, year, hours, minutes,
2936
source_bucket, sink_bucket):
@@ -67,13 +74,14 @@ def main(description, project_id, day, month, year, hours, minutes,
6774
}
6875

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

7381
if __name__ == '__main__':
7482
parser = argparse.ArgumentParser(
75-
description='Create a transfer from the Google Cloud Storage Standard '
76-
'class to the Nearline Storage class.')
83+
description=__doc__,
84+
formatter_class=argparse.RawDescriptionHelpFormatter)
7785
parser.add_argument('description', help='Transfer description.')
7886
parser.add_argument('project_id', help='Your Google Cloud project ID.')
7987
parser.add_argument('date', help='Date YYYY/MM/DD.')
@@ -95,5 +103,4 @@ def main(description, project_id, day, month, year, hours, minutes,
95103
time.minute,
96104
args.source_bucket,
97105
args.sink_bucket)
98-
99106
# [END all]

storage/transfer_service/transfer_check.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env
2+
13
# Copyright 2015, Google, Inc.
24
# Licensed under the Apache License, Version 2.0 (the "License");
35
# you may not use this file except in compliance with the License.
@@ -10,19 +12,25 @@
1012
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1113
# See the License for the specific language governing permissions and
1214
# limitations under the License.
13-
#
15+
1416
# [START all]
17+
18+
"""Command-line sample that checks the status of an in-process transfer.
19+
20+
This sample is used on this page:
21+
22+
https://cloud.google.com/storage/transfer/create-transfer
23+
24+
For more information, see README.md.
25+
"""
26+
1527
import argparse
1628
import json
17-
import logging
1829

1930
from apiclient import discovery
2031
from oauth2client.client import GoogleCredentials
2132

2233

23-
logging.basicConfig(level=logging.DEBUG)
24-
25-
2634
# [START main]
2735
def main(project_id, job_name):
2836
"""Review the transfer operations associated with a transfer job."""
@@ -38,19 +46,18 @@ def main(project_id, job_name):
3846
result = storagetransfer.transferOperations().list(
3947
name="transferOperations",
4048
filter=filterString).execute()
41-
logging.info('Result of transferOperations/list: %s',
42-
json.dumps(result, indent=4, sort_keys=True))
49+
print('Result of transferOperations/list: {}'.format(
50+
json.dumps(result, indent=4, sort_keys=True)))
4351
# [END main]
4452

4553
if __name__ == '__main__':
4654
parser = argparse.ArgumentParser(
47-
description='Review the transfer operations associated with a '
48-
'transfer job.')
55+
description=__doc__,
56+
formatter_class=argparse.RawDescriptionHelpFormatter)
4957
parser.add_argument('project_id', help='Your Google Cloud project ID.')
5058
parser.add_argument('job_name', help='Your job name.')
5159

5260
args = parser.parse_args()
5361

5462
main(args.project_id, args.job_name)
55-
5663
# [END all]

0 commit comments

Comments
 (0)