@@ -247,18 +247,18 @@ def initialize_library(self, library, lib_type=VERSION_STORE, **kwargs):
247
247
kwargs :
248
248
Arguments passed to the Library type for initialization.
249
249
"""
250
- l = ArcticLibraryBinding (self , library )
250
+ lib = ArcticLibraryBinding (self , library )
251
251
# check that we don't create too many namespaces
252
252
# can be disabled check_library_count=False
253
253
check_library_count = kwargs .pop ('check_library_count' , True )
254
- if len (self ._conn [l .database_name ].list_collection_names ()) > 5000 and check_library_count :
254
+ if len (self ._conn [lib .database_name ].list_collection_names ()) > 5000 and check_library_count :
255
255
raise ArcticException ("Too many namespaces %s, not creating: %s" %
256
- (len (self ._conn [l .database_name ].list_collection_names ()), library ))
257
- l .set_library_type (lib_type )
258
- LIBRARY_TYPES [lib_type ].initialize_library (l , ** kwargs )
256
+ (len (self ._conn [lib .database_name ].list_collection_names ()), library ))
257
+ lib .set_library_type (lib_type )
258
+ LIBRARY_TYPES [lib_type ].initialize_library (lib , ** kwargs )
259
259
# Add a 10G quota just in case the user is calling this with API.
260
- if not l .get_quota ():
261
- l .set_quota (10 * 1024 * 1024 * 1024 )
260
+ if not lib .get_quota ():
261
+ lib .set_quota (10 * 1024 * 1024 * 1024 )
262
262
263
263
@mongo_retry
264
264
def delete_library (self , library ):
@@ -270,19 +270,19 @@ def delete_library(self, library):
270
270
library : `str`
271
271
The name of the library. e.g. 'library' or 'user.library'
272
272
"""
273
- l = ArcticLibraryBinding (self , library )
274
- colname = l .get_top_level_collection ().name
275
- if not [c for c in l ._db .list_collection_names (False ) if re .match (r"^{}([\.].*)?$" .format (colname ), c )]:
273
+ lib = ArcticLibraryBinding (self , library )
274
+ colname = lib .get_top_level_collection ().name
275
+ if not [c for c in lib ._db .list_collection_names (False ) if re .match (r"^{}([\.].*)?$" .format (colname ), c )]:
276
276
logger .info ('Nothing to delete. Arctic library %s does not exist.' % colname )
277
277
logger .info ('Dropping collection: %s' % colname )
278
- l ._db .drop_collection (colname )
279
- for coll in l ._db .list_collection_names ():
278
+ lib ._db .drop_collection (colname )
279
+ for coll in lib ._db .list_collection_names ():
280
280
if coll .startswith (colname + '.' ):
281
281
logger .info ('Dropping collection: %s' % coll )
282
- l ._db .drop_collection (coll )
282
+ lib ._db .drop_collection (coll )
283
283
if library in self ._library_cache :
284
284
del self ._library_cache [library ]
285
- del self ._library_cache [l .get_name ()]
285
+ del self ._library_cache [lib .get_name ()]
286
286
287
287
def get_library (self , library ):
288
288
"""
@@ -299,8 +299,8 @@ def get_library(self, library):
299
299
300
300
try :
301
301
error = None
302
- l = ArcticLibraryBinding (self , library )
303
- lib_type = l .get_library_type ()
302
+ lib = ArcticLibraryBinding (self , library )
303
+ lib_type = lib .get_library_type ()
304
304
except (OperationFailure , AutoReconnect ) as e :
305
305
error = e
306
306
@@ -313,10 +313,10 @@ def get_library(self, library):
313
313
elif lib_type not in LIBRARY_TYPES :
314
314
raise LibraryNotFoundException ("Couldn't load LibraryType '%s' for '%s' (has the class been registered?)" %
315
315
(lib_type , library ))
316
- instance = LIBRARY_TYPES [lib_type ](l )
316
+ instance = LIBRARY_TYPES [lib_type ](lib )
317
317
self ._library_cache [library ] = instance
318
318
# The library official name may be different from 'library': e.g. 'library' vs 'user.library'
319
- self ._library_cache [l .get_name ()] = instance
319
+ self ._library_cache [lib .get_name ()] = instance
320
320
return self ._library_cache [library ]
321
321
322
322
def __getitem__ (self , key ):
@@ -338,8 +338,7 @@ def set_quota(self, library, quota):
338
338
quota : `int`
339
339
Advisory quota for the library - in bytes
340
340
"""
341
- l = ArcticLibraryBinding (self , library )
342
- l .set_quota (quota )
341
+ ArcticLibraryBinding (self , library ).set_quota (quota )
343
342
344
343
def get_quota (self , library ):
345
344
"""
@@ -350,8 +349,7 @@ def get_quota(self, library):
350
349
library : `str`
351
350
The name of the library. e.g. 'library' or 'user.library'
352
351
"""
353
- l = ArcticLibraryBinding (self , library )
354
- return l .get_quota ()
352
+ return ArcticLibraryBinding (self , library ).get_quota ()
355
353
356
354
def check_quota (self , library ):
357
355
"""
@@ -366,8 +364,7 @@ def check_quota(self, library):
366
364
------
367
365
arctic.exceptions.QuotaExceededException if the quota has been exceeded
368
366
"""
369
- l = ArcticLibraryBinding (self , library )
370
- l .check_quota ()
367
+ ArcticLibraryBinding (self , library ).check_quota ()
371
368
372
369
def rename_library (self , from_lib , to_lib ):
373
370
"""
@@ -386,18 +383,18 @@ def rename_library(self, from_lib, to_lib):
386
383
raise ValueError ("Collection can only be renamed in the same database" )
387
384
to_colname = to_lib .split ('.' )[1 ]
388
385
389
- l = ArcticLibraryBinding (self , from_lib )
390
- colname = l .get_top_level_collection ().name
386
+ lib = ArcticLibraryBinding (self , from_lib )
387
+ colname = lib .get_top_level_collection ().name
391
388
392
389
logger .info ('Renaming collection: %s' % colname )
393
- l ._db [colname ].rename (to_colname )
394
- for coll in l ._db .list_collection_names ():
390
+ lib ._db [colname ].rename (to_colname )
391
+ for coll in lib ._db .list_collection_names ():
395
392
if coll .startswith (colname + '.' ):
396
- l ._db [coll ].rename (coll .replace (colname , to_colname ))
393
+ lib ._db [coll ].rename (coll .replace (colname , to_colname ))
397
394
398
395
if from_lib in self ._library_cache :
399
396
del self ._library_cache [from_lib ]
400
- del self ._library_cache [l .get_name ()]
397
+ del self ._library_cache [lib .get_name ()]
401
398
402
399
def get_library_type (self , lib ):
403
400
"""
@@ -408,8 +405,7 @@ def get_library_type(self, lib):
408
405
lib: str
409
406
the library
410
407
"""
411
- l = ArcticLibraryBinding (self , lib )
412
- return l .get_library_type ()
408
+ return ArcticLibraryBinding (self , lib ).get_library_type ()
413
409
414
410
415
411
class ArcticLibraryBinding (object ):
@@ -565,14 +561,14 @@ def to_gigabytes(bytes_):
565
561
remaining_count = remaining / avg_size
566
562
if remaining_count < 100 or float (remaining ) / self .quota < 0.1 :
567
563
logger .warning ("Mongo Quota: %s %.3f / %.0f GB used" % (
568
- '.' .join ([self .database_name , self .library ]),
569
- to_gigabytes (size ),
570
- to_gigabytes (self .quota )))
564
+ '.' .join ([self .database_name , self .library ]),
565
+ to_gigabytes (size ),
566
+ to_gigabytes (self .quota )))
571
567
else :
572
568
logger .info ("Mongo Quota: %s %.3f / %.0f GB used" % (
573
- '.' .join ([self .database_name , self .library ]),
574
- to_gigabytes (size ),
575
- to_gigabytes (self .quota )))
569
+ '.' .join ([self .database_name , self .library ]),
570
+ to_gigabytes (size ),
571
+ to_gigabytes (self .quota )))
576
572
577
573
# Set-up a timer to prevent us for checking for a few writes.
578
574
# This will check every average half-life
0 commit comments