def XXXall(): #ret = [] cache = [] for env in saltenv: log.info('Syncing {0} for environment {1!r}'.format(form, env)) log.info('Loading cache from {0}, for {1})'.format(source, env)) # Grab only the desired files (.py, .pyx, .so) cache.extend(__salt__['cp.cache_dir'](source, env, include_pat=r'E@\.(pyx?|so)$')) local_cache_base_dir = os.path.join(__opts__['cachedir'], 'files', env) log.debug('Local cache base dir: {0!r}'.format(local_cache_base_dir)) local_cache_dir = os.path.join(local_cache_base_dir, '_{0}'.format(form)) log.debug('Local cache dir: {0!r}'.format(local_cache_dir)) client = salt.fileclient.get_file_client(__opts__) fileserver = salt.fileserver.Fileserver(__opts__) for fn_ in cache: relpath = os.path.relpath(fn_, local_cache_dir) relname = os.path.splitext(relpath)[0].replace(os.sep, '.') saltpath = os.path.relpath(fn_, local_cache_base_dir) filenamed = fileserver.find_file(saltpath, env) remote.add(relpath) dest = os.path.join(mod_dir, relpath)
def XXXall(): #ret = [] cache = [] for env in saltenv: log.info('Syncing {0} for environment {1!r}'.format(form, env)) log.info('Loading cache from {0}, for {1})'.format(source, env)) # Grab only the desired files (.py, .pyx, .so) cache.extend( __salt__['cp.cache_dir']( source, env, include_pat=r'E@\.(pyx?|so)$' ) ) local_cache_base_dir = os.path.join( __opts__['cachedir'], 'files', env ) log.debug('Local cache base dir: {0!r}'.format(local_cache_base_dir)) local_cache_dir = os.path.join(local_cache_base_dir, '_{0}'.format(form)) log.debug('Local cache dir: {0!r}'.format(local_cache_dir)) client = salt.fileclient.get_file_client(__opts__) fileserver = salt.fileserver.Fileserver(__opts__) for fn_ in cache: relpath = os.path.relpath(fn_, local_cache_dir) relname = os.path.splitext(relpath)[0].replace(os.sep, '.') saltpath = os.path.relpath(fn_, local_cache_base_dir) filenamed = fileserver.find_file(saltpath, env) remote.add(relpath) dest = os.path.join(mod_dir, relpath)
def _bind(form, saltenv=None, umount=False): ''' Bind the files in salt extmods directory within the given environment ''' if saltenv is None: saltenv = _get_top_file_envs() if isinstance(saltenv, string_types): saltenv = saltenv.split(',') ret = [] remote = set() source = os.path.join('salt://_{0}'.format(form)) mod_dir = os.path.join(__opts__['extension_modules'], '{0}'.format(form)) if not os.path.isdir(mod_dir): log.info('Creating module dir {0!r}'.format(mod_dir)) try: os.makedirs(mod_dir) except (IOError, OSError): msg = 'Cannot create cache module directory {0}. Check permissions.' log.error(msg.format(mod_dir)) for sub_env in saltenv: log.info('Syncing {0} for environment {1!r}'.format(form, sub_env)) cache = [] log.info('Loading cache from {0}, for {1})'.format(source, sub_env)) # Grab only the desired files (.py, .pyx, .so) cache.extend( __salt__['cp.cache_dir']( source, sub_env, include_pat=r'E@\.(pyx?|so)$' ) ) local_cache_base_dir = os.path.join( __opts__['cachedir'], 'files', sub_env ) log.debug('Local cache base dir: {0!r}'.format(local_cache_base_dir)) local_cache_dir = os.path.join(local_cache_base_dir, '_{0}'.format(form)) log.debug('Local cache dir: {0!r}'.format(local_cache_dir)) client = salt.fileclient.get_file_client(__opts__) fileserver = salt.fileserver.Fileserver(__opts__) for fn_ in cache: relpath = os.path.relpath(fn_, local_cache_dir) relname = os.path.splitext(relpath)[0].replace(os.sep, '.') saltpath = os.path.relpath(fn_, local_cache_base_dir) filenamed = fileserver.find_file(saltpath, sub_env) remote.add(relpath) dest = os.path.join(mod_dir, relpath) if not os.path.isfile(dest): dest_dir = os.path.dirname(dest) if not os.path.isdir(dest_dir): os.makedirs(dest_dir) shutil.copyfile(fn_, dest) ret.append('{0}.{1}'.format(form, relname)) # Test to see if already mounted (bound) cmd = ['findmnt', dest] proc = subprocess.Popen(cmd, stdout=DEVNULL, stderr=subprocess.STDOUT) proc.wait() if proc.returncode: cmd = ['mount', '--bind', filenamed['path'], dest] proc = subprocess.Popen(cmd, stdout=DEVNULL, stderr=subprocess.STDOUT) proc.wait() elif umount: cmd = ['umount', dest] proc = subprocess.Popen(cmd, stdout=DEVNULL, stderr=subprocess.STDOUT) proc.wait() touched = bool(ret) if __opts__.get('clean_dynamic_modules', True): current = set(_listdir_recursively(mod_dir)) for fn_ in current - remote: full = os.path.join(mod_dir, fn_) if os.path.ismount(full): proc = subprocess.Popen(['umount', full]) proc.wait() if os.path.isfile(full): touched = True try: os.remove(full) except OSError: pass # Cleanup empty dirs while True: emptydirs = _list_emptydirs(mod_dir) if not emptydirs: break for emptydir in emptydirs: touched = True shutil.rmtree(emptydir, ignore_errors=True) # Dest mod_dir is touched? trigger reload if requested if touched: mod_file = os.path.join(__opts__['cachedir'], 'module_refresh') with salt.utils.fopen(mod_file, 'a+') as ofile: ofile.write('') return ret