diff --git a/bigtable/hello/main.py b/bigtable/hello/main.py index c0c610ca23b..8bf927d9dc3 100644 --- a/bigtable/hello/main.py +++ b/bigtable/hello/main.py @@ -41,9 +41,9 @@ def main(project_id, instance_id, table_id): # [END connecting_to_bigtable] # [START creating_a_table] - print 'Creating the {} table.'.format(table_id) + print('Creating the {} table.'.format(table_id)) table = instance.table(table_id) - print 'Creating column family cf1 with Max Version GC rule...' + print('Creating column family cf1 with Max Version GC rule...') # Create a column family with GC policy : most recent N versions # Define the GC policy to retain only the most recent 2 versions max_versions_rule = column_family.MaxVersionsGCRule(2) @@ -52,11 +52,11 @@ def main(project_id, instance_id, table_id): if not table.exists(): table.create(column_families=column_families) else: - print "Table {} already exists.".format(table_id) + print("Table {} already exists.".format(table_id)) # [END creating_a_table] # [START writing_rows] - print 'Writing some greetings to the table.' + print('Writing some greetings to the table.') greetings = ['Hello World!', 'Hello Cloud Bigtable!', 'Hello Python!'] rows = [] column = 'greeting' @@ -82,26 +82,26 @@ def main(project_id, instance_id, table_id): # [END writing_rows] # [START getting_a_row] - print 'Getting a single greeting by row key.' + print('Getting a single greeting by row key.') key = 'greeting0' # Only retrieve the most recent version of the cell. row_filter = row_filters.CellsColumnLimitFilter(1) row = table.read_row(key, row_filter) - print row.cell_value(column_family_id, column) + print(row.cell_value(column_family_id, column)) # [END getting_a_row] # [START scanning_all_rows] - print 'Scanning for all greetings:' + print('Scanning for all greetings:') partial_rows = table.read_rows(filter_=row_filter) for row in partial_rows: cell = row.cells[column_family_id][column][0] - print cell.value.decode('utf-8') + print(cell.value.decode('utf-8')) # [END scanning_all_rows] # [START deleting_a_table] - print 'Deleting the {} table.'.format(table_id) + print('Deleting the {} table.'.format(table_id)) table.delete() # [END deleting_a_table] diff --git a/bigtable/instanceadmin/instanceadmin.py b/bigtable/instanceadmin/instanceadmin.py index 55a18567c76..32120eb6375 100644 --- a/bigtable/instanceadmin/instanceadmin.py +++ b/bigtable/instanceadmin/instanceadmin.py @@ -59,9 +59,9 @@ def run_instance_operations(project_id, instance_id): # [START bigtable_check_instance_exists] if not instance.exists(): - print 'Instance {} does not exists.'.format(instance_id) + print('Instance {} does not exists.'.format(instance_id)) else: - print 'Instance {} already exists.'.format(instance_id) + print('Instance {} already exists.'.format(instance_id)) # [END bigtable_check_instance_exists] # [START bigtable_create_prod_instance] @@ -69,27 +69,27 @@ def run_instance_operations(project_id, instance_id): serve_nodes=serve_nodes, default_storage_type=storage_type) if not instance.exists(): - print '\nCreating an Instance' + print('\nCreating an Instance') # Create instance with given options instance.create(clusters=[cluster]) - print '\nCreated instance: {}'.format(instance_id) + print('\nCreated instance: {}'.format(instance_id)) # [END bigtable_create_prod_instance] # [START bigtable_list_instances] - print '\nListing Instances:' + print('\nListing Instances:') for instance_local in client.list_instances()[0]: - print instance_local.instance_id + print(instance_local.instance_id) # [END bigtable_list_instances] # [START bigtable_get_instance] - print '\nName of instance:{}\nLabels:{}'.format(instance.display_name, - instance.labels) + print('\nName of instance:{}\nLabels:{}'.format(instance.display_name, + instance.labels)) # [END bigtable_get_instance] # [START bigtable_get_clusters] - print '\nListing Clusters...' + print('\nListing Clusters...') for cluster in instance.list_clusters()[0]: - print cluster.cluster_id + print(cluster.cluster_id) # [END bigtable_get_clusters] @@ -109,7 +109,7 @@ def create_dev_instance(project_id, instance_id, cluster_id): client = bigtable.Client(project=project_id, admin=True) # [START bigtable_create_dev_instance] - print '\nCreating a DEVELOPMENT Instance' + print('\nCreating a DEVELOPMENT Instance') # Set options to create an Instance location_id = 'us-central1-f' development = enums.Instance.Type.DEVELOPMENT @@ -125,9 +125,9 @@ def create_dev_instance(project_id, instance_id, cluster_id): # Create development instance with given options if not instance.exists(): instance.create(clusters=[cluster]) - print 'Created development instance: {}'.format(instance_id) + print('Created development instance: {}'.format(instance_id)) else: - print 'Instance {} already exists.'.format(instance_id) + print('Instance {} already exists.'.format(instance_id)) # [END bigtable_create_dev_instance] @@ -145,12 +145,12 @@ def delete_instance(project_id, instance_id): client = bigtable.Client(project=project_id, admin=True) instance = client.instance(instance_id) # [START bigtable_delete_instance] - print '\nDeleting Instance' + print('\nDeleting Instance') if not instance.exists(): - print 'Instance {} does not exists.'.format(instance_id) + print('Instance {} does not exists.'.format(instance_id)) else: instance.delete() - print 'Deleted Instance: {}'.format(instance_id) + print('Deleted Instance: {}'.format(instance_id)) # [END bigtable_delete_instance] @@ -174,22 +174,24 @@ def add_cluster(project_id, instance_id, cluster_id): storage_type = enums.StorageType.SSD if not instance.exists(): - print 'Instance {} does not exists.'.format(instance_id) + print('Instance {} does not exists.'.format(instance_id)) else: - print '\nAdding Cluster to Instance {}'.format(instance_id) + print('\nAdding Cluster to Instance {}'.format(instance_id)) # [START bigtable_create_cluster] - print '\nListing Clusters...' + print('\nListing Clusters...') for cluster in instance.list_clusters()[0]: - print cluster.cluster_id + print(cluster.cluster_id) cluster = instance.cluster(cluster_id, location_id=location_id, serve_nodes=serve_nodes, default_storage_type=storage_type) if cluster.exists(): - print '\nCluster not created, as {} already exists.'.\ - format(cluster_id) + print( + '\nCluster not created, as {} already exists.'. + format(cluster_id) + ) else: cluster.create() - print '\nCluster created: {}'.format(cluster_id) + print('\nCluster created: {}'.format(cluster_id)) # [END bigtable_create_cluster] @@ -211,12 +213,12 @@ def delete_cluster(project_id, instance_id, cluster_id): cluster = instance.cluster(cluster_id) # [START bigtable_delete_cluster] - print '\nDeleting Cluster' + print('\nDeleting Cluster') if cluster.exists(): cluster.delete() - print 'Cluster deleted: {}'.format(cluster_id) + print('Cluster deleted: {}'.format(cluster_id)) else: - print '\nCluster {} does not exist.'.format(cluster_id) + print('\nCluster {} does not exist.'.format(cluster_id)) # [END bigtable_delete_cluster] @@ -253,5 +255,5 @@ def delete_cluster(project_id, instance_id, cluster_id): elif args.command.lower() == 'del-cluster': delete_cluster(args.project_id, args.instance_id, args.cluster_id) else: - print 'Command should be either run \n Use argument -h, \ - --help to show help and exit.' + print('Command should be either run \n Use argument -h, \ + --help to show help and exit.') diff --git a/bigtable/tableadmin/tableadmin.py b/bigtable/tableadmin/tableadmin.py index 9e6e73ac140..6bad0bebae8 100644 --- a/bigtable/tableadmin/tableadmin.py +++ b/bigtable/tableadmin/tableadmin.py @@ -56,26 +56,26 @@ def run_table_operations(project_id, instance_id, table_id): # Check whether table exists in an instance. # Create table if it does not exists. - print 'Checking if table {} exists...'.format(table_id) + print('Checking if table {} exists...'.format(table_id)) if table.exists(): - print 'Table {} already exists.'.format(table_id) + print('Table {} already exists.'.format(table_id)) else: - print 'Creating the {} table.'.format(table_id) + print('Creating the {} table.'.format(table_id)) table.create() - print 'Created table {}.'.format(table_id) + print('Created table {}.'.format(table_id)) # [START bigtable_list_tables] tables = instance.list_tables() - print 'Listing tables in current project...' + print('Listing tables in current project...') if tables != []: for tbl in tables: - print tbl.table_id + print(tbl.table_id) else: - print 'No table exists in current project...' + print('No table exists in current project...') # [END bigtable_list_tables] # [START bigtable_create_family_gc_max_age] - print 'Creating column family cf1 with with MaxAge GC Rule...' + print('Creating column family cf1 with with MaxAge GC Rule...') # Create a column family with GC policy : maximum age # where age = current time minus cell timestamp @@ -84,11 +84,11 @@ def run_table_operations(project_id, instance_id, table_id): column_family1 = table.column_family('cf1', max_age_rule) column_family1.create() - print 'Created column family cf1 with MaxAge GC Rule.' + print('Created column family cf1 with MaxAge GC Rule.') # [END bigtable_create_family_gc_max_age] # [START bigtable_create_family_gc_max_versions] - print 'Creating column family cf2 with max versions GC rule...' + print('Creating column family cf2 with max versions GC rule...') # Create a column family with GC policy : most recent N versions # where 1 = most recent version @@ -97,11 +97,11 @@ def run_table_operations(project_id, instance_id, table_id): column_family2 = table.column_family('cf2', max_versions_rule) column_family2.create() - print 'Created column family cf2 with Max Versions GC Rule.' + print('Created column family cf2 with Max Versions GC Rule.') # [END bigtable_create_family_gc_max_versions] # [START bigtable_create_family_gc_union] - print 'Creating column family cf3 with union GC rule...' + print('Creating column family cf3 with union GC rule...') # Create a column family with GC policy to drop data that matches # at least one condition. # 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): column_family3 = table.column_family('cf3', union_rule) column_family3.create() - print 'Created column family cf3 with Union GC rule' + print('Created column family cf3 with Union GC rule') # [END bigtable_create_family_gc_union] # [START bigtable_create_family_gc_intersection] - print 'Creating column family cf4 with Intersection GC rule...' + print('Creating column family cf4 with Intersection GC rule...') # Create a column family with GC policy to drop data that matches # all conditions # 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): column_family4 = table.column_family('cf4', intersection_rule) column_family4.create() - print 'Created column family cf4 with Intersection GC rule.' + print('Created column family cf4 with Intersection GC rule.') # [END bigtable_create_family_gc_intersection] # [START bigtable_create_family_gc_nested] - print 'Creating column family cf5 with a Nested GC rule...' + print('Creating column family cf5 with a Nested GC rule...') # Create a column family with nested GC policies. # Create a nested GC rule: # 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): column_family5 = table.column_family('cf5', nested_rule) column_family5.create() - print 'Created column family cf5 with a Nested GC rule.' + print('Created column family cf5 with a Nested GC rule.') # [END bigtable_create_family_gc_nested] # [START bigtable_list_column_families] - print 'Printing Column Family and GC Rule for all column families...' + print('Printing Column Family and GC Rule for all column families...') column_families = table.list_column_families() for column_family_name, gc_rule in sorted(column_families.items()): - print 'Column Family:', column_family_name - print 'GC Rule:' - print gc_rule.to_pb() + print('Column Family:', column_family_name) + print('GC Rule:') + print(gc_rule.to_pb()) # Sample output: # Column Family: cf4 # GC Rule: @@ -174,33 +174,33 @@ def run_table_operations(project_id, instance_id, table_id): # } # [END bigtable_list_column_families] - print 'Print column family cf1 GC rule before update...' - print 'Column Family: cf1' - print column_family1.to_pb() + print('Print column family cf1 GC rule before update...') + print('Column Family: cf1') + print(column_family1.to_pb()) # [START bigtable_update_gc_rule] - print 'Updating column family cf1 GC rule...' + print('Updating column family cf1 GC rule...') # Update the column family cf1 to update the GC rule column_family1 = table.column_family( 'cf1', column_family.MaxVersionsGCRule(1)) column_family1.update() - print 'Updated column family cf1 GC rule\n' + print('Updated column family cf1 GC rule\n') # [END bigtable_update_gc_rule] - print 'Print column family cf1 GC rule after update...' - print 'Column Family: cf1' - print column_family1.to_pb() + print('Print column family cf1 GC rule after update...') + print('Column Family: cf1') + print(column_family1.to_pb()) # [START bigtable_delete_family] - print 'Delete a column family cf2...' + print('Delete a column family cf2...') # Delete a column family column_family2.delete() - print 'Column family cf2 deleted successfully.' + print('Column family cf2 deleted successfully.') # [END bigtable_delete_family] - print 'execute command "python tableadmin.py delete [project_id] \ - [instance_id] --table [tableName]" to delete the table.' + print('execute command "python tableadmin.py delete [project_id] \ + [instance_id] --table [tableName]" to delete the table.') def delete_table(project_id, instance_id, table_id): @@ -223,14 +223,14 @@ def delete_table(project_id, instance_id, table_id): # [START bigtable_delete_table] # Delete the entire table - print 'Checking if table {} exists...'.format(table_id) + print('Checking if table {} exists...'.format(table_id)) if table.exists(): - print 'Table {} exists.'.format(table_id) - print 'Deleting {} table.'.format(table_id) + print('Table {} exists.'.format(table_id)) + print('Deleting {} table.'.format(table_id)) table.delete() - print 'Deleted {} table.'.format(table_id) + print('Deleted {} table.'.format(table_id)) else: - print 'Table {} does not exists.'.format(table_id) + print('Table {} does not exists.'.format(table_id)) # [END bigtable_delete_table] @@ -261,5 +261,5 @@ def delete_table(project_id, instance_id, table_id): elif args.command.lower() == 'delete': delete_table(args.project_id, args.instance_id, args.table) else: - print 'Command should be either run or delete.\n Use argument -h,\ - --help to show help and exit.' + print('Command should be either run or delete.\n Use argument -h,\ + --help to show help and exit.')