Rename NewLazyLoader to LazyLoader (since the old one was deleted)

This commit is contained in:
Thomas Jackson 2015-02-03 18:26:31 -08:00
parent 69f73df099
commit 7b03fad8cd
3 changed files with 36 additions and 35 deletions

View File

@ -116,7 +116,7 @@ def minion_mods(opts, context=None, whitelist=None, include_errors=False, initia
context = {} context = {}
if not whitelist: if not whitelist:
whitelist = opts.get('whitelist_modules', None) whitelist = opts.get('whitelist_modules', None)
ret = NewLazyLoader(_module_dirs(opts, 'modules', 'module'), ret = LazyLoader(_module_dirs(opts, 'modules', 'module'),
opts, opts,
tag='modules', tag='modules',
whitelist=whitelist, whitelist=whitelist,
@ -147,7 +147,7 @@ def raw_mod(opts, _, functions, mod='modules'):
''' '''
pack = {'name': '__salt__', pack = {'name': '__salt__',
'value': functions} 'value': functions}
return NewLazyLoader(_module_dirs(opts, mod, 'rawmodule'), return LazyLoader(_module_dirs(opts, mod, 'rawmodule'),
opts, opts,
tag=mod, tag=mod,
virtual_enable=False, virtual_enable=False,
@ -161,7 +161,7 @@ def proxy(opts, functions, whitelist=None):
''' '''
pack = {'name': '__proxy__', pack = {'name': '__proxy__',
'value': functions} 'value': functions}
return NewLazyLoader(_module_dirs(opts, 'proxy', 'proxy'), return LazyLoader(_module_dirs(opts, 'proxy', 'proxy'),
opts, opts,
tag='proxy', tag='proxy',
whitelist=whitelist, whitelist=whitelist,
@ -175,7 +175,7 @@ def returners(opts, functions, whitelist=None):
''' '''
pack = {'name': '__salt__', pack = {'name': '__salt__',
'value': functions} 'value': functions}
return NewLazyLoader(_module_dirs(opts, 'returners', 'returner'), return LazyLoader(_module_dirs(opts, 'returners', 'returner'),
opts, opts,
tag='returners', tag='returners',
whitelist=whitelist, whitelist=whitelist,
@ -187,7 +187,7 @@ def utils(opts, whitelist=None):
''' '''
Returns the utility modules Returns the utility modules
''' '''
return NewLazyLoader(_module_dirs(opts, 'utils', 'utils', ext_type_dirs='utils_dirs'), return LazyLoader(_module_dirs(opts, 'utils', 'utils', ext_type_dirs='utils_dirs'),
opts, opts,
tag='utils', tag='utils',
whitelist=whitelist, whitelist=whitelist,
@ -201,7 +201,7 @@ def pillars(opts, functions):
pack = {'name': '__salt__', pack = {'name': '__salt__',
'value': functions} 'value': functions}
ret = NewLazyLoader(_module_dirs(opts, 'pillar', 'pillar'), ret = LazyLoader(_module_dirs(opts, 'pillar', 'pillar'),
opts, opts,
tag='pillar', tag='pillar',
pack=pack, pack=pack,
@ -216,7 +216,7 @@ def tops(opts):
if 'master_tops' not in opts: if 'master_tops' not in opts:
return {} return {}
whitelist = opts['master_tops'].keys() whitelist = opts['master_tops'].keys()
ret = NewLazyLoader(_module_dirs(opts, 'tops', 'top'), ret = LazyLoader(_module_dirs(opts, 'tops', 'top'),
opts, opts,
tag='tops', tag='tops',
whitelist=whitelist, whitelist=whitelist,
@ -228,7 +228,7 @@ def wheels(opts, whitelist=None):
''' '''
Returns the wheels modules Returns the wheels modules
''' '''
return NewLazyLoader(_module_dirs(opts, 'wheel', 'wheel'), return LazyLoader(_module_dirs(opts, 'wheel', 'wheel'),
opts, opts,
tag='wheel', tag='wheel',
whitelist=whitelist, whitelist=whitelist,
@ -239,7 +239,7 @@ def outputters(opts):
''' '''
Returns the outputters modules Returns the outputters modules
''' '''
ret = NewLazyLoader(_module_dirs(opts, 'output', 'output', ext_type_dirs='outputter_dirs'), ret = LazyLoader(_module_dirs(opts, 'output', 'output', ext_type_dirs='outputter_dirs'),
opts, opts,
tag='output', tag='output',
) )
@ -257,7 +257,7 @@ def auth(opts, whitelist=None):
''' '''
pack = {'name': '__salt__', pack = {'name': '__salt__',
'value': minion_mods(opts)} 'value': minion_mods(opts)}
return NewLazyLoader(_module_dirs(opts, 'auth', 'auth'), return LazyLoader(_module_dirs(opts, 'auth', 'auth'),
opts, opts,
tag='auth', tag='auth',
whitelist=whitelist, whitelist=whitelist,
@ -269,7 +269,7 @@ def fileserver(opts, backends):
''' '''
Returns the file server modules Returns the file server modules
''' '''
return NewLazyLoader(_module_dirs(opts, 'fileserver', 'fileserver'), return LazyLoader(_module_dirs(opts, 'fileserver', 'fileserver'),
opts, opts,
tag='fileserver', tag='fileserver',
whitelist=backends, whitelist=backends,
@ -280,7 +280,7 @@ def roster(opts, whitelist=None):
''' '''
Returns the roster modules Returns the roster modules
''' '''
return NewLazyLoader(_module_dirs(opts, 'roster', 'roster'), return LazyLoader(_module_dirs(opts, 'roster', 'roster'),
opts, opts,
tag='roster', tag='roster',
whitelist=whitelist, whitelist=whitelist,
@ -301,7 +301,7 @@ def states(opts, functions, whitelist=None):
''' '''
pack = {'name': '__salt__', pack = {'name': '__salt__',
'value': functions} 'value': functions}
return NewLazyLoader(_module_dirs(opts, 'states', 'states'), return LazyLoader(_module_dirs(opts, 'states', 'states'),
opts, opts,
tag='states', tag='states',
pack=pack, pack=pack,
@ -317,7 +317,7 @@ def beacons(opts, context=None):
context = {} context = {}
pack = {'name': '__context__', pack = {'name': '__context__',
'value': context} 'value': context}
return NewLazyLoader(_module_dirs(opts, 'beacons', 'beacons'), return LazyLoader(_module_dirs(opts, 'beacons', 'beacons'),
opts, opts,
tag='beacons', tag='beacons',
pack=pack, pack=pack,
@ -330,7 +330,7 @@ def search(opts, returners, whitelist=None):
''' '''
pack = {'name': '__ret__', pack = {'name': '__ret__',
'value': returners} 'value': returners}
return NewLazyLoader(_module_dirs(opts, 'search', 'search'), return LazyLoader(_module_dirs(opts, 'search', 'search'),
opts, opts,
tag='search', tag='search',
whitelist=whitelist, whitelist=whitelist,
@ -342,7 +342,7 @@ def log_handlers(opts):
''' '''
Returns the custom logging handler modules Returns the custom logging handler modules
''' '''
ret = NewLazyLoader(_module_dirs(opts, ret = LazyLoader(_module_dirs(opts,
'log_handlers', 'log_handlers',
'log_handlers', 'log_handlers',
int_type='handlers', int_type='handlers',
@ -365,7 +365,7 @@ def ssh_wrapper(opts, functions=None, context=None):
'value': functions}, 'value': functions},
{'name': '__context__', {'name': '__context__',
'value': context}] 'value': context}]
return NewLazyLoader(_module_dirs(opts, return LazyLoader(_module_dirs(opts,
'wrapper', 'wrapper',
'wrapper', 'wrapper',
base_path=os.path.join(SALT_BASE_PATH, os.path.join('client', 'ssh'))), base_path=os.path.join(SALT_BASE_PATH, os.path.join('client', 'ssh'))),
@ -384,7 +384,7 @@ def render(opts, functions, states=None):
] ]
if states: if states:
pack.append({'name': '__states__', 'value': states}) pack.append({'name': '__states__', 'value': states})
ret = NewLazyLoader(_module_dirs(opts, ret = LazyLoader(_module_dirs(opts,
'renderers', 'renderers',
'render', 'render',
ext_type_dirs='render_dirs'), ext_type_dirs='render_dirs'),
@ -474,7 +474,7 @@ def grains(opts, force_refresh=False):
opts['grains'] = {} opts['grains'] = {}
grains_data = {} grains_data = {}
funcs = NewLazyLoader(_module_dirs(opts, 'grains', 'grain', ext_type_dirs='grains_dirs'), funcs = LazyLoader(_module_dirs(opts, 'grains', 'grain', ext_type_dirs='grains_dirs'),
opts, opts,
tag='grains', tag='grains',
) )
@ -539,7 +539,7 @@ def call(fun, **kwargs):
args = kwargs.get('args', []) args = kwargs.get('args', [])
dirs = kwargs.get('dirs', []) dirs = kwargs.get('dirs', [])
funcs = NewLazyLoader([os.path.join(SALT_BASE_PATH, 'modules')] + dirs, funcs = LazyLoader([os.path.join(SALT_BASE_PATH, 'modules')] + dirs,
None, None,
tag='modules', tag='modules',
virtual_enable=False, virtual_enable=False,
@ -553,7 +553,7 @@ def runner(opts):
''' '''
pack = {'name': '__salt__', pack = {'name': '__salt__',
'value': minion_mods(opts)} 'value': minion_mods(opts)}
return NewLazyLoader(_module_dirs(opts, 'runners', 'runner', ext_type_dirs='runner_dirs'), return LazyLoader(_module_dirs(opts, 'runners', 'runner', ext_type_dirs='runner_dirs'),
opts, opts,
tag='runners', tag='runners',
pack=pack pack=pack
@ -564,7 +564,7 @@ def queues(opts):
''' '''
Directly call a function inside a loader directory Directly call a function inside a loader directory
''' '''
return NewLazyLoader(_module_dirs(opts, 'queues', 'queue', ext_type_dirs='queue_dirs'), return LazyLoader(_module_dirs(opts, 'queues', 'queue', ext_type_dirs='queue_dirs'),
opts, opts,
tag='queues', tag='queues',
) )
@ -576,7 +576,7 @@ def sdb(opts, functions=None, whitelist=None):
''' '''
pack = {'name': '__sdb__', pack = {'name': '__sdb__',
'value': functions} 'value': functions}
return NewLazyLoader(_module_dirs(opts, 'sdb', 'sdb'), return LazyLoader(_module_dirs(opts, 'sdb', 'sdb'),
opts, opts,
tag='sdb', tag='sdb',
pack=pack, pack=pack,
@ -595,7 +595,7 @@ def clouds(opts):
'name': '__active_provider_name__', 'name': '__active_provider_name__',
'value': None 'value': None
} }
functions = NewLazyLoader(_module_dirs(opts, functions = LazyLoader(_module_dirs(opts,
'clouds', 'clouds',
'cloud', 'cloud',
base_path=os.path.join(SALT_BASE_PATH, 'cloud'), base_path=os.path.join(SALT_BASE_PATH, 'cloud'),
@ -619,7 +619,7 @@ def netapi(opts):
''' '''
Return the network api functions Return the network api functions
''' '''
return NewLazyLoader(_module_dirs(opts, 'netapi', 'netapi'), return LazyLoader(_module_dirs(opts, 'netapi', 'netapi'),
opts, opts,
tag='netapi', tag='netapi',
) )
@ -692,7 +692,7 @@ class FilterDictWrapper(MutableMapping):
yield key.replace(self.suffix, '') yield key.replace(self.suffix, '')
class NewLazyLoader(salt.utils.lazy.LazyDict): class LazyLoader(salt.utils.lazy.LazyDict):
''' '''
Goals here: Goals here:
- lazy loading - lazy loading
@ -739,12 +739,12 @@ class NewLazyLoader(salt.utils.lazy.LazyDict):
opts.get('id'), opts.get('id'),
) )
if key not in NewLazyLoader.instances: if key not in LazyLoader.instances:
log.debug('Initializing new NewLazyLoader for {0}'.format(key)) log.debug('Initializing new LazyLoader for {0}'.format(key))
NewLazyLoader.instances[key] = new_object() LazyLoader.instances[key] = new_object()
else: else:
log.debug('Re-using NewLazyLoader for {0}'.format(key)) log.debug('Re-using LazyLoader for {0}'.format(key))
return NewLazyLoader.instances[key] return LazyLoader.instances[key]
# has to remain empty for singletons, since __init__ will *always* be called # has to remain empty for singletons, since __init__ will *always* be called
def __init__(self, def __init__(self,
@ -772,7 +772,7 @@ class NewLazyLoader(salt.utils.lazy.LazyDict):
virtual_enable=True, virtual_enable=True,
singleton=True, singleton=True,
): ):
super(NewLazyLoader, self).__init__() # init the lazy loader super(LazyLoader, self).__init__() # init the lazy loader
self.opts = self.__prep_mod_opts(opts) self.opts = self.__prep_mod_opts(opts)
self.module_dirs = module_dirs self.module_dirs = module_dirs
@ -853,7 +853,7 @@ class NewLazyLoader(salt.utils.lazy.LazyDict):
''' '''
Clear the dict Clear the dict
''' '''
super(NewLazyLoader, self).clear() # clear the lazy loader super(LazyLoader, self).clear() # clear the lazy loader
self.loaded_files = [] self.loaded_files = []
self.missing_modules = [] self.missing_modules = []
self.initial_load = False self.initial_load = False
@ -885,7 +885,7 @@ class NewLazyLoader(salt.utils.lazy.LazyDict):
This might be problematic, since this means they change after __virtual__, This might be problematic, since this means they change after __virtual__,
but its been doing this for a while... so it must be fine :/ but its been doing this for a while... so it must be fine :/
''' '''
mod = super(NewLazyLoader, self).__getitem__(key) mod = super(LazyLoader, self).__getitem__(key)
if '__opts__' in mod.__globals__: if '__opts__' in mod.__globals__:
mod.__globals__['__opts__'].update(self.opts) mod.__globals__['__opts__'].update(self.opts)

View File

@ -298,7 +298,7 @@ def load_states():
# create our own loader that ignores __virtual__() # create our own loader that ignores __virtual__()
pack = {'name': '__salt__', pack = {'name': '__salt__',
'value': __salt__} 'value': __salt__}
lazy_states = salt.loader.NewLazyLoader( lazy_states = salt.loader.LazyLoader(
salt.loader._module_dirs(__opts__, 'states', 'states'), salt.loader._module_dirs(__opts__, 'states', 'states'),
__opts__, __opts__,
tag='states', tag='states',

View File

@ -11,6 +11,7 @@ class LazyDict(collections.MutableMapping):
TODO: negative caching? If you ask for 'foo' and it doesn't exist it will TODO: negative caching? If you ask for 'foo' and it doesn't exist it will
look EVERY time unless someone calls load_all() look EVERY time unless someone calls load_all()
As of now this is left to the class which inherits from this base
''' '''
def __init__(self): def __init__(self):
self.clear() self.clear()