Skip to content

Commit abc419a

Browse files
authored
Fixed print statements (GoogleCloudPlatform#1755)
* Updated trampoline script to match latest version that cleans up files * Added newline to end of trampoline script * A quickstart test was missing requirements.txt * Replaced print statements with print function calls * Missed a print issue last time * Bad indent fixed
1 parent f82b29f commit abc419a

File tree

3 files changed

+79
-77
lines changed

3 files changed

+79
-77
lines changed

bigtable/hello/main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def main(project_id, instance_id, table_id):
4141
# [END connecting_to_bigtable]
4242

4343
# [START creating_a_table]
44-
print 'Creating the {} table.'.format(table_id)
44+
print('Creating the {} table.'.format(table_id))
4545
table = instance.table(table_id)
46-
print 'Creating column family cf1 with Max Version GC rule...'
46+
print('Creating column family cf1 with Max Version GC rule...')
4747
# Create a column family with GC policy : most recent N versions
4848
# Define the GC policy to retain only the most recent 2 versions
4949
max_versions_rule = column_family.MaxVersionsGCRule(2)
@@ -52,11 +52,11 @@ def main(project_id, instance_id, table_id):
5252
if not table.exists():
5353
table.create(column_families=column_families)
5454
else:
55-
print "Table {} already exists.".format(table_id)
55+
print("Table {} already exists.".format(table_id))
5656
# [END creating_a_table]
5757

5858
# [START writing_rows]
59-
print 'Writing some greetings to the table.'
59+
print('Writing some greetings to the table.')
6060
greetings = ['Hello World!', 'Hello Cloud Bigtable!', 'Hello Python!']
6161
rows = []
6262
column = 'greeting'
@@ -82,26 +82,26 @@ def main(project_id, instance_id, table_id):
8282
# [END writing_rows]
8383

8484
# [START getting_a_row]
85-
print 'Getting a single greeting by row key.'
85+
print('Getting a single greeting by row key.')
8686
key = 'greeting0'
8787

8888
# Only retrieve the most recent version of the cell.
8989
row_filter = row_filters.CellsColumnLimitFilter(1)
9090
row = table.read_row(key, row_filter)
91-
print row.cell_value(column_family_id, column)
91+
print(row.cell_value(column_family_id, column))
9292
# [END getting_a_row]
9393

9494
# [START scanning_all_rows]
95-
print 'Scanning for all greetings:'
95+
print('Scanning for all greetings:')
9696
partial_rows = table.read_rows(filter_=row_filter)
9797

9898
for row in partial_rows:
9999
cell = row.cells[column_family_id][column][0]
100-
print cell.value.decode('utf-8')
100+
print(cell.value.decode('utf-8'))
101101
# [END scanning_all_rows]
102102

103103
# [START deleting_a_table]
104-
print 'Deleting the {} table.'.format(table_id)
104+
print('Deleting the {} table.'.format(table_id))
105105
table.delete()
106106
# [END deleting_a_table]
107107

bigtable/instanceadmin/instanceadmin.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,37 @@ def run_instance_operations(project_id, instance_id):
5959

6060
# [START bigtable_check_instance_exists]
6161
if not instance.exists():
62-
print 'Instance {} does not exists.'.format(instance_id)
62+
print('Instance {} does not exists.'.format(instance_id))
6363
else:
64-
print 'Instance {} already exists.'.format(instance_id)
64+
print('Instance {} already exists.'.format(instance_id))
6565
# [END bigtable_check_instance_exists]
6666

6767
# [START bigtable_create_prod_instance]
6868
cluster = instance.cluster("ssd-cluster1", location_id=location_id,
6969
serve_nodes=serve_nodes,
7070
default_storage_type=storage_type)
7171
if not instance.exists():
72-
print '\nCreating an Instance'
72+
print('\nCreating an Instance')
7373
# Create instance with given options
7474
instance.create(clusters=[cluster])
75-
print '\nCreated instance: {}'.format(instance_id)
75+
print('\nCreated instance: {}'.format(instance_id))
7676
# [END bigtable_create_prod_instance]
7777

7878
# [START bigtable_list_instances]
79-
print '\nListing Instances:'
79+
print('\nListing Instances:')
8080
for instance_local in client.list_instances()[0]:
81-
print instance_local.instance_id
81+
print(instance_local.instance_id)
8282
# [END bigtable_list_instances]
8383

8484
# [START bigtable_get_instance]
85-
print '\nName of instance:{}\nLabels:{}'.format(instance.display_name,
86-
instance.labels)
85+
print('\nName of instance:{}\nLabels:{}'.format(instance.display_name,
86+
instance.labels))
8787
# [END bigtable_get_instance]
8888

8989
# [START bigtable_get_clusters]
90-
print '\nListing Clusters...'
90+
print('\nListing Clusters...')
9191
for cluster in instance.list_clusters()[0]:
92-
print cluster.cluster_id
92+
print(cluster.cluster_id)
9393
# [END bigtable_get_clusters]
9494

9595

@@ -109,7 +109,7 @@ def create_dev_instance(project_id, instance_id, cluster_id):
109109
client = bigtable.Client(project=project_id, admin=True)
110110

111111
# [START bigtable_create_dev_instance]
112-
print '\nCreating a DEVELOPMENT Instance'
112+
print('\nCreating a DEVELOPMENT Instance')
113113
# Set options to create an Instance
114114
location_id = 'us-central1-f'
115115
development = enums.Instance.Type.DEVELOPMENT
@@ -125,9 +125,9 @@ def create_dev_instance(project_id, instance_id, cluster_id):
125125
# Create development instance with given options
126126
if not instance.exists():
127127
instance.create(clusters=[cluster])
128-
print 'Created development instance: {}'.format(instance_id)
128+
print('Created development instance: {}'.format(instance_id))
129129
else:
130-
print 'Instance {} already exists.'.format(instance_id)
130+
print('Instance {} already exists.'.format(instance_id))
131131

132132
# [END bigtable_create_dev_instance]
133133

@@ -145,12 +145,12 @@ def delete_instance(project_id, instance_id):
145145
client = bigtable.Client(project=project_id, admin=True)
146146
instance = client.instance(instance_id)
147147
# [START bigtable_delete_instance]
148-
print '\nDeleting Instance'
148+
print('\nDeleting Instance')
149149
if not instance.exists():
150-
print 'Instance {} does not exists.'.format(instance_id)
150+
print('Instance {} does not exists.'.format(instance_id))
151151
else:
152152
instance.delete()
153-
print 'Deleted Instance: {}'.format(instance_id)
153+
print('Deleted Instance: {}'.format(instance_id))
154154
# [END bigtable_delete_instance]
155155

156156

@@ -174,22 +174,24 @@ def add_cluster(project_id, instance_id, cluster_id):
174174
storage_type = enums.StorageType.SSD
175175

176176
if not instance.exists():
177-
print 'Instance {} does not exists.'.format(instance_id)
177+
print('Instance {} does not exists.'.format(instance_id))
178178
else:
179-
print '\nAdding Cluster to Instance {}'.format(instance_id)
179+
print('\nAdding Cluster to Instance {}'.format(instance_id))
180180
# [START bigtable_create_cluster]
181-
print '\nListing Clusters...'
181+
print('\nListing Clusters...')
182182
for cluster in instance.list_clusters()[0]:
183-
print cluster.cluster_id
183+
print(cluster.cluster_id)
184184
cluster = instance.cluster(cluster_id, location_id=location_id,
185185
serve_nodes=serve_nodes,
186186
default_storage_type=storage_type)
187187
if cluster.exists():
188-
print '\nCluster not created, as {} already exists.'.\
189-
format(cluster_id)
188+
print(
189+
'\nCluster not created, as {} already exists.'.
190+
format(cluster_id)
191+
)
190192
else:
191193
cluster.create()
192-
print '\nCluster created: {}'.format(cluster_id)
194+
print('\nCluster created: {}'.format(cluster_id))
193195
# [END bigtable_create_cluster]
194196

195197

@@ -211,12 +213,12 @@ def delete_cluster(project_id, instance_id, cluster_id):
211213
cluster = instance.cluster(cluster_id)
212214

213215
# [START bigtable_delete_cluster]
214-
print '\nDeleting Cluster'
216+
print('\nDeleting Cluster')
215217
if cluster.exists():
216218
cluster.delete()
217-
print 'Cluster deleted: {}'.format(cluster_id)
219+
print('Cluster deleted: {}'.format(cluster_id))
218220
else:
219-
print '\nCluster {} does not exist.'.format(cluster_id)
221+
print('\nCluster {} does not exist.'.format(cluster_id))
220222

221223
# [END bigtable_delete_cluster]
222224

@@ -253,5 +255,5 @@ def delete_cluster(project_id, instance_id, cluster_id):
253255
elif args.command.lower() == 'del-cluster':
254256
delete_cluster(args.project_id, args.instance_id, args.cluster_id)
255257
else:
256-
print 'Command should be either run \n Use argument -h, \
257-
--help to show help and exit.'
258+
print('Command should be either run \n Use argument -h, \
259+
--help to show help and exit.')

bigtable/tableadmin/tableadmin.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,26 @@ def run_table_operations(project_id, instance_id, table_id):
5656

5757
# Check whether table exists in an instance.
5858
# Create table if it does not exists.
59-
print 'Checking if table {} exists...'.format(table_id)
59+
print('Checking if table {} exists...'.format(table_id))
6060
if table.exists():
61-
print 'Table {} already exists.'.format(table_id)
61+
print('Table {} already exists.'.format(table_id))
6262
else:
63-
print 'Creating the {} table.'.format(table_id)
63+
print('Creating the {} table.'.format(table_id))
6464
table.create()
65-
print 'Created table {}.'.format(table_id)
65+
print('Created table {}.'.format(table_id))
6666

6767
# [START bigtable_list_tables]
6868
tables = instance.list_tables()
69-
print 'Listing tables in current project...'
69+
print('Listing tables in current project...')
7070
if tables != []:
7171
for tbl in tables:
72-
print tbl.table_id
72+
print(tbl.table_id)
7373
else:
74-
print 'No table exists in current project...'
74+
print('No table exists in current project...')
7575
# [END bigtable_list_tables]
7676

7777
# [START bigtable_create_family_gc_max_age]
78-
print 'Creating column family cf1 with with MaxAge GC Rule...'
78+
print('Creating column family cf1 with with MaxAge GC Rule...')
7979
# Create a column family with GC policy : maximum age
8080
# where age = current time minus cell timestamp
8181

@@ -84,11 +84,11 @@ def run_table_operations(project_id, instance_id, table_id):
8484

8585
column_family1 = table.column_family('cf1', max_age_rule)
8686
column_family1.create()
87-
print 'Created column family cf1 with MaxAge GC Rule.'
87+
print('Created column family cf1 with MaxAge GC Rule.')
8888
# [END bigtable_create_family_gc_max_age]
8989

9090
# [START bigtable_create_family_gc_max_versions]
91-
print 'Creating column family cf2 with max versions GC rule...'
91+
print('Creating column family cf2 with max versions GC rule...')
9292
# Create a column family with GC policy : most recent N versions
9393
# where 1 = most recent version
9494

@@ -97,11 +97,11 @@ def run_table_operations(project_id, instance_id, table_id):
9797

9898
column_family2 = table.column_family('cf2', max_versions_rule)
9999
column_family2.create()
100-
print 'Created column family cf2 with Max Versions GC Rule.'
100+
print('Created column family cf2 with Max Versions GC Rule.')
101101
# [END bigtable_create_family_gc_max_versions]
102102

103103
# [START bigtable_create_family_gc_union]
104-
print 'Creating column family cf3 with union GC rule...'
104+
print('Creating column family cf3 with union GC rule...')
105105
# Create a column family with GC policy to drop data that matches
106106
# at least one condition.
107107
# Define a GC rule to drop cells older than 5 days or not the
@@ -112,11 +112,11 @@ def run_table_operations(project_id, instance_id, table_id):
112112

113113
column_family3 = table.column_family('cf3', union_rule)
114114
column_family3.create()
115-
print 'Created column family cf3 with Union GC rule'
115+
print('Created column family cf3 with Union GC rule')
116116
# [END bigtable_create_family_gc_union]
117117

118118
# [START bigtable_create_family_gc_intersection]
119-
print 'Creating column family cf4 with Intersection GC rule...'
119+
print('Creating column family cf4 with Intersection GC rule...')
120120
# Create a column family with GC policy to drop data that matches
121121
# all conditions
122122
# GC rule: Drop cells older than 5 days AND older than the most
@@ -127,11 +127,11 @@ def run_table_operations(project_id, instance_id, table_id):
127127

128128
column_family4 = table.column_family('cf4', intersection_rule)
129129
column_family4.create()
130-
print 'Created column family cf4 with Intersection GC rule.'
130+
print('Created column family cf4 with Intersection GC rule.')
131131
# [END bigtable_create_family_gc_intersection]
132132

133133
# [START bigtable_create_family_gc_nested]
134-
print 'Creating column family cf5 with a Nested GC rule...'
134+
print('Creating column family cf5 with a Nested GC rule...')
135135
# Create a column family with nested GC policies.
136136
# Create a nested GC rule:
137137
# Drop cells that are either older than the 10 recent versions
@@ -147,16 +147,16 @@ def run_table_operations(project_id, instance_id, table_id):
147147

148148
column_family5 = table.column_family('cf5', nested_rule)
149149
column_family5.create()
150-
print 'Created column family cf5 with a Nested GC rule.'
150+
print('Created column family cf5 with a Nested GC rule.')
151151
# [END bigtable_create_family_gc_nested]
152152

153153
# [START bigtable_list_column_families]
154-
print 'Printing Column Family and GC Rule for all column families...'
154+
print('Printing Column Family and GC Rule for all column families...')
155155
column_families = table.list_column_families()
156156
for column_family_name, gc_rule in sorted(column_families.items()):
157-
print 'Column Family:', column_family_name
158-
print 'GC Rule:'
159-
print gc_rule.to_pb()
157+
print('Column Family:', column_family_name)
158+
print('GC Rule:')
159+
print(gc_rule.to_pb())
160160
# Sample output:
161161
# Column Family: cf4
162162
# GC Rule:
@@ -174,33 +174,33 @@ def run_table_operations(project_id, instance_id, table_id):
174174
# }
175175
# [END bigtable_list_column_families]
176176

177-
print 'Print column family cf1 GC rule before update...'
178-
print 'Column Family: cf1'
179-
print column_family1.to_pb()
177+
print('Print column family cf1 GC rule before update...')
178+
print('Column Family: cf1')
179+
print(column_family1.to_pb())
180180

181181
# [START bigtable_update_gc_rule]
182-
print 'Updating column family cf1 GC rule...'
182+
print('Updating column family cf1 GC rule...')
183183
# Update the column family cf1 to update the GC rule
184184
column_family1 = table.column_family(
185185
'cf1',
186186
column_family.MaxVersionsGCRule(1))
187187
column_family1.update()
188-
print 'Updated column family cf1 GC rule\n'
188+
print('Updated column family cf1 GC rule\n')
189189
# [END bigtable_update_gc_rule]
190190

191-
print 'Print column family cf1 GC rule after update...'
192-
print 'Column Family: cf1'
193-
print column_family1.to_pb()
191+
print('Print column family cf1 GC rule after update...')
192+
print('Column Family: cf1')
193+
print(column_family1.to_pb())
194194

195195
# [START bigtable_delete_family]
196-
print 'Delete a column family cf2...'
196+
print('Delete a column family cf2...')
197197
# Delete a column family
198198
column_family2.delete()
199-
print 'Column family cf2 deleted successfully.'
199+
print('Column family cf2 deleted successfully.')
200200
# [END bigtable_delete_family]
201201

202-
print 'execute command "python tableadmin.py delete [project_id] \
203-
[instance_id] --table [tableName]" to delete the table.'
202+
print('execute command "python tableadmin.py delete [project_id] \
203+
[instance_id] --table [tableName]" to delete the table.')
204204

205205

206206
def delete_table(project_id, instance_id, table_id):
@@ -223,14 +223,14 @@ def delete_table(project_id, instance_id, table_id):
223223
# [START bigtable_delete_table]
224224
# Delete the entire table
225225

226-
print 'Checking if table {} exists...'.format(table_id)
226+
print('Checking if table {} exists...'.format(table_id))
227227
if table.exists():
228-
print 'Table {} exists.'.format(table_id)
229-
print 'Deleting {} table.'.format(table_id)
228+
print('Table {} exists.'.format(table_id))
229+
print('Deleting {} table.'.format(table_id))
230230
table.delete()
231-
print 'Deleted {} table.'.format(table_id)
231+
print('Deleted {} table.'.format(table_id))
232232
else:
233-
print 'Table {} does not exists.'.format(table_id)
233+
print('Table {} does not exists.'.format(table_id))
234234
# [END bigtable_delete_table]
235235

236236

@@ -261,5 +261,5 @@ def delete_table(project_id, instance_id, table_id):
261261
elif args.command.lower() == 'delete':
262262
delete_table(args.project_id, args.instance_id, args.table)
263263
else:
264-
print 'Command should be either run or delete.\n Use argument -h,\
265-
--help to show help and exit.'
264+
print('Command should be either run or delete.\n Use argument -h,\
265+
--help to show help and exit.')

0 commit comments

Comments
 (0)