11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
- """Convenience wrapper for invoking APIs/factories w/ a dataset ID ."""
14
+ """Convenience wrapper for invoking APIs/factories w/ a project ."""
15
15
16
16
import os
17
17
23
23
from gcloud .datastore .connection import Connection
24
24
from gcloud .datastore .batch import Batch
25
25
from gcloud .datastore .entity import Entity
26
+ from gcloud .datastore .key import _projects_equal
26
27
from gcloud .datastore .key import Key
27
- from gcloud .datastore .key import _dataset_ids_equal
28
28
from gcloud .datastore .query import Query
29
29
from gcloud .datastore .transaction import Transaction
30
30
from gcloud .environment_vars import DATASET
35
35
"""Maximum number of iterations to wait for deferred keys."""
36
36
37
37
38
- def _get_production_dataset_id ():
38
+ def _get_production_project ():
39
39
"""Gets the production application ID if it can be inferred."""
40
40
return os .getenv (DATASET )
41
41
42
42
43
- def _get_gcd_dataset_id ():
43
+ def _get_gcd_project ():
44
44
"""Gets the GCD application ID if it can be inferred."""
45
45
return os .getenv (GCD_DATASET )
46
46
47
47
48
- def _determine_default_dataset_id ( dataset_id = None ):
49
- """Determine default dataset ID explicitly or implicitly as fall-back.
48
+ def _determine_default_project ( project = None ):
49
+ """Determine default project explicitly or implicitly as fall-back.
50
50
51
51
In implicit case, supports four environments. In order of precedence, the
52
52
implicit environments are:
@@ -56,28 +56,28 @@ def _determine_default_dataset_id(dataset_id=None):
56
56
* Google App Engine application ID
57
57
* Google Compute Engine project ID (from metadata server)
58
58
59
- :type dataset_id : string
60
- :param dataset_id : Optional. The dataset ID to use as default.
59
+ :type project : string
60
+ :param project : Optional. The project to use as default.
61
61
62
62
:rtype: string or ``NoneType``
63
- :returns: Default dataset ID if it can be determined.
63
+ :returns: Default project if it can be determined.
64
64
"""
65
- if dataset_id is None :
66
- dataset_id = _get_production_dataset_id ()
65
+ if project is None :
66
+ project = _get_production_project ()
67
67
68
- if dataset_id is None :
69
- dataset_id = _get_gcd_dataset_id ()
68
+ if project is None :
69
+ project = _get_gcd_project ()
70
70
71
- if dataset_id is None :
72
- dataset_id = _app_engine_id ()
71
+ if project is None :
72
+ project = _app_engine_id ()
73
73
74
- if dataset_id is None :
75
- dataset_id = _compute_engine_id ()
74
+ if project is None :
75
+ project = _compute_engine_id ()
76
76
77
- return dataset_id
77
+ return project
78
78
79
79
80
- def _extended_lookup (connection , dataset_id , key_pbs ,
80
+ def _extended_lookup (connection , project , key_pbs ,
81
81
missing = None , deferred = None ,
82
82
eventual = False , transaction_id = None ):
83
83
"""Repeat lookup until all keys found (unless stop requested).
@@ -87,8 +87,8 @@ def _extended_lookup(connection, dataset_id, key_pbs,
87
87
:type connection: :class:`gcloud.datastore.connection.Connection`
88
88
:param connection: The connection used to connect to datastore.
89
89
90
- :type dataset_id : string
91
- :param dataset_id : The ID of the dataset of which to make the request.
90
+ :type project : string
91
+ :param project : The project to make the request for .
92
92
93
93
:type key_pbs: list of :class:`gcloud.datastore._generated.entity_pb2.Key`
94
94
:param key_pbs: The keys to retrieve from the datastore.
@@ -130,7 +130,7 @@ def _extended_lookup(connection, dataset_id, key_pbs,
130
130
loop_num += 1
131
131
132
132
results_found , missing_found , deferred_found = connection .lookup (
133
- dataset_id = dataset_id ,
133
+ project = project ,
134
134
key_pbs = key_pbs ,
135
135
eventual = eventual ,
136
136
transaction_id = transaction_id ,
@@ -156,10 +156,10 @@ def _extended_lookup(connection, dataset_id, key_pbs,
156
156
157
157
158
158
class Client (_BaseClient ):
159
- """Convenience wrapper for invoking APIs/factories w/ a dataset ID .
159
+ """Convenience wrapper for invoking APIs/factories w/ a project .
160
160
161
- :type dataset_id : string
162
- :param dataset_id : (optional) dataset ID to pass to proxied API methods.
161
+ :type project : string
162
+ :param project : (optional) The project to pass to proxied API methods.
163
163
164
164
:type namespace: string
165
165
:param namespace: (optional) namespace to pass to proxied API methods.
@@ -178,12 +178,12 @@ class Client(_BaseClient):
178
178
"""
179
179
_connection_class = Connection
180
180
181
- def __init__ (self , dataset_id = None , namespace = None ,
181
+ def __init__ (self , project = None , namespace = None ,
182
182
credentials = None , http = None ):
183
- dataset_id = _determine_default_dataset_id ( dataset_id )
184
- if dataset_id is None :
185
- raise EnvironmentError ('Dataset ID could not be inferred.' )
186
- self .dataset_id = dataset_id
183
+ project = _determine_default_project ( project )
184
+ if project is None :
185
+ raise EnvironmentError ('Project could not be inferred.' )
186
+ self .project = project
187
187
self .namespace = namespace
188
188
self ._batch_stack = _LocalStack ()
189
189
super (Client , self ).__init__ (credentials , http )
@@ -281,22 +281,22 @@ def get_multi(self, keys, missing=None, deferred=None):
281
281
282
282
:rtype: list of :class:`gcloud.datastore.entity.Entity`
283
283
:returns: The requested entities.
284
- :raises: :class:`ValueError` if one or more of ``keys`` has a dataset
285
- ID which does not match our dataset ID .
284
+ :raises: :class:`ValueError` if one or more of ``keys`` has a project
285
+ which does not match our project .
286
286
"""
287
287
if not keys :
288
288
return []
289
289
290
- ids = set (key .dataset_id for key in keys )
290
+ ids = set (key .project for key in keys )
291
291
for current_id in ids :
292
- if not _dataset_ids_equal (current_id , self .dataset_id ):
293
- raise ValueError ('Keys do not match dataset ID ' )
292
+ if not _projects_equal (current_id , self .project ):
293
+ raise ValueError ('Keys do not match project ' )
294
294
295
295
transaction = self .current_transaction
296
296
297
297
entity_pbs = _extended_lookup (
298
298
connection = self .connection ,
299
- dataset_id = self .dataset_id ,
299
+ project = self .project ,
300
300
key_pbs = [k .to_protobuf () for k in keys ],
301
301
missing = missing ,
302
302
deferred = deferred ,
@@ -414,7 +414,7 @@ def allocate_ids(self, incomplete_key, num_ids):
414
414
incomplete_key_pbs = [incomplete_key_pb ] * num_ids
415
415
416
416
conn = self .connection
417
- allocated_key_pbs = conn .allocate_ids (incomplete_key .dataset_id ,
417
+ allocated_key_pbs = conn .allocate_ids (incomplete_key .project ,
418
418
incomplete_key_pbs )
419
419
allocated_ids = [allocated_key_pb .path_element [- 1 ].id
420
420
for allocated_key_pb in allocated_key_pbs ]
@@ -424,39 +424,33 @@ def allocate_ids(self, incomplete_key, num_ids):
424
424
def key (self , * path_args , ** kwargs ):
425
425
"""Proxy to :class:`gcloud.datastore.key.Key`.
426
426
427
- Passes our ``dataset_id ``.
427
+ Passes our ``project ``.
428
428
"""
429
- if 'dataset_id ' in kwargs :
430
- raise TypeError ('Cannot pass dataset_id ' )
431
- kwargs ['dataset_id ' ] = self .dataset_id
429
+ if 'project ' in kwargs :
430
+ raise TypeError ('Cannot pass project ' )
431
+ kwargs ['project ' ] = self .project
432
432
if 'namespace' not in kwargs :
433
433
kwargs ['namespace' ] = self .namespace
434
434
return Key (* path_args , ** kwargs )
435
435
436
436
def batch (self ):
437
- """Proxy to :class:`gcloud.datastore.batch.Batch`.
438
-
439
- Passes our ``dataset_id``.
440
- """
437
+ """Proxy to :class:`gcloud.datastore.batch.Batch`."""
441
438
return Batch (self )
442
439
443
440
def transaction (self ):
444
- """Proxy to :class:`gcloud.datastore.transaction.Transaction`.
445
-
446
- Passes our ``dataset_id``.
447
- """
441
+ """Proxy to :class:`gcloud.datastore.transaction.Transaction`."""
448
442
return Transaction (self )
449
443
450
444
def query (self , ** kwargs ):
451
445
"""Proxy to :class:`gcloud.datastore.query.Query`.
452
446
453
- Passes our ``dataset_id ``.
447
+ Passes our ``project ``.
454
448
"""
455
449
if 'client' in kwargs :
456
450
raise TypeError ('Cannot pass client' )
457
- if 'dataset_id ' in kwargs :
458
- raise TypeError ('Cannot pass dataset_id ' )
459
- kwargs ['dataset_id ' ] = self .dataset_id
451
+ if 'project ' in kwargs :
452
+ raise TypeError ('Cannot pass project ' )
453
+ kwargs ['project ' ] = self .project
460
454
if 'namespace' not in kwargs :
461
455
kwargs ['namespace' ] = self .namespace
462
456
return Query (self , ** kwargs )
0 commit comments