Set up 'os' module replacement functions for use during import bootstrap.
345227
def _os_bootstrap():
    

    global _os_stat, _os_getcwd, _os_environ, _os_listdir
    global _os_path_join, _os_path_dirname, _os_path_basename
    global _os_sep

    names = sys.builtin_module_names

    join = dirname = environ = listdir = basename = None
    mindirlen = 0
    # Only 'posix' and 'nt' os specific modules are supported.
    # 'dos', 'os2' and 'mac' (MacOS 9) are not supported.
    if 'posix' in names:
        from posix import stat, getcwd, environ, listdir
        sep = _os_sep = '/'
        mindirlen = 1
    elif 'nt' in names:
        from nt import stat, getcwd, environ, listdir
        sep = _os_sep = '\\'
        mindirlen = 3
    else:
        raise ImportError('no os specific module found')

    if join is None:
        def join(a, b, sep=sep):
            if a == '':
                return b
            lastchar = a[-1:]
            if lastchar == '/' or lastchar == sep:
                return a + b
            return a + sep + b

    if dirname is None:
        def dirname(a, sep=sep, mindirlen=mindirlen):
            for i in range(len(a) - 1, -1, -1):
                c = a[i]
                if c == '/' or c == sep:
                    if i < mindirlen:
                        return a[:i + 1]
                    return a[:i]
            return ''

    if basename is None:
        def basename(p):
            i = p.rfind(sep)
            if i == -1:
                return p
            else:
                return p[i + len(sep):]

    def _listdir(dir, cache={}):
        # since this function is only used by caseOk, it's fine to cache the
        # results and avoid reading the whole contents of a directory each time
        # we just want to check the case of a filename.
        if not dir in cache:
            cache[dir] = listdir(dir)
        return cache[dir]

    _os_stat = stat
    _os_getcwd = getcwd
    _os_path_join = join
    _os_path_dirname = dirname
    _os_environ = environ
    _os_listdir = _listdir
    _os_path_basename = basename
1301211
def _copy_module(old):
    """"""
    saved = sys.modules.pop(old.__name__, None)
    new = __import__(old.__name__)
    sys.modules[old.__name__] = saved
    return new
42061
def bootstrap(command, conf, vars):
    """"""

    # <websetup.bootstrap.before.auth
    from sqlalchemy.exc import IntegrityError
    try:
        u = model.User()
        u.user_name = 'manager'
        u.display_name = 'Example manager'
        u.email_address = 'manager@somedomain.com'
        u.password = 'managepass'
    
        model.DBSession.add(u)
    
        g = model.Group()
        g.group_name = 'managers'
        g.display_name = 'Managers Group'
    
        g.users.append(u)
    
        model.DBSession.add(g)
    
        p = model.Permission()
        p.permission_name = 'manage'
        p.description = 'This permission give an administrative right to the bearer'
        p.groups.append(g)
    
        model.DBSession.add(p)
    
        u1 = model.User()
        u1.user_name = 'editor'
        u1.display_name = 'Example editor'
        u1.email_address = 'editor@somedomain.com'
        u1.password = 'editpass'
    
        model.DBSession.add(u1)
        model.DBSession.flush()
        transaction.commit()
    except IntegrityError:
        print('Warning, there was a problem adding your auth data, it may have already been added:')
        import traceback
        print(traceback.format_exc())
        transaction.abort()
        print('Continuing with bootstrapping...')
73621
def op_bootstrap(self):
        """"""
        self.logger.info('Bootstrapping django-dev directory structure in current directory ...')
        self.make_venv(DJANGO_DEFAULT_VERSION)
        venv_path = self.make_venv('1.6.5')
        self.venv_install('south==1.0.1', venv_path)
        apps_dir = self.make_apps_dir()
        self.logger.info('Now you may symlink (ln -s) your apps '
                         '(and other apps that you apps depend upon) into %s' % apps_dir)
371498
def main(unused_argv):
    """"""
    utils.ensure_dir_exists(os.path.dirname(FLAGS.export_path))
    if FLAGS.create_bootstrap:
        dual_net.bootstrap()
    dual_net.export_model(FLAGS.export_path)
1357096
function optimizeBootModules () {
			grunt.log.writeln('OK'.green);
			if (!options.dirs || !options.dirs.length) {
				finalize();
				return;
			}
			grunt.util.async.forEachSeries(options.dirs, function(dir, next) {
				if (typeof dir === 'string') {
					dir = {
						combine: false,
						name: dir
					}
				}
				optimizeDir(dir, next);
			}, function () {
				finalize();
			});
		}
573473
def install_import_hook():
    """"""
    saved_import = builtins.__import__
    @functools.wraps(saved_import)
    def import_hook(name, *args, **kwargs):
        if name == 'end':
            process_import()
        end
        return saved_import(name, *args, **kwargs)
    end
    builtins.__import__ = import_hook
648406
def update_bootstrap(config, url=None):
    '''
    
    '''
    default_url = config.get('bootstrap_script_url',
                             'https://bootstrap.saltstack.com')
    if not url:
        url = default_url
    if not url:
        raise ValueError('Cant get any source to update')
    if url.startswith('http') or '://' in url:
        log.debug('Updating the bootstrap-salt.sh script to latest stable')
        try:
            import requests
        except ImportError:
            return {'error': (
                'Updating the bootstrap-salt.sh script requires the '
                'Python requests library to be installed'
            )}
        req = requests.get(url)
        if req.status_code != 200:
            return {'error': (
                'Failed to download the latest stable version of the '
                'bootstrap-salt.sh script from {0}. HTTP error: '
                '{1}'.format(
                    url, req.status_code
                )
            )}
        script_content = req.text
        if url == default_url:
            script_name = 'bootstrap-salt.sh'
        else:
            script_name = os.path.basename(url)
    elif os.path.exists(url):
        with salt.utils.files.fopen(url) as fic:
            script_content = salt.utils.stringutils.to_unicode(fic.read())
        script_name = os.path.basename(url)
    # in last case, assuming we got a script content
    else:
        script_content = url
        script_name = '{0}.sh'.format(
            hashlib.sha1(script_content).hexdigest()
        )

    if not script_content:
        raise ValueError('No content in bootstrap script !')

    # Get the path to the built-in deploy scripts directory
    builtin_deploy_dir = os.path.join(
        os.path.dirname(__file__),
        'deploy'
    )

    # Compute the search path from the current loaded opts conf_file
    # value
    deploy_d_from_conf_file = os.path.join(
        os.path.dirname(config['conf_file']),
        'cloud.deploy.d'
    )

    # Compute the search path using the install time defined
    # syspaths.CONF_DIR
    deploy_d_from_syspaths = os.path.join(
        config['config_dir'],
        'cloud.deploy.d'
    )

    # Get a copy of any defined search paths, flagging them not to
    # create parent
    deploy_scripts_search_paths = []
    for entry in config.get('deploy_scripts_search_path', []):
        if entry.startswith(builtin_deploy_dir):
            # We won't write the updated script to the built-in deploy
            # directory
            continue

        if entry in (deploy_d_from_conf_file, deploy_d_from_syspaths):
            # Allow parent directories to be made
            deploy_scripts_search_paths.append((entry, True))
        else:
            deploy_scripts_search_paths.append((entry, False))

    # In case the user is not using defaults and the computed
    # 'cloud.deploy.d' from conf_file and syspaths is not included, add
    # them
    if deploy_d_from_conf_file not in deploy_scripts_search_paths:
        deploy_scripts_search_paths.append(
            (deploy_d_from_conf_file, True)
        )
    if deploy_d_from_syspaths not in deploy_scripts_search_paths:
        deploy_scripts_search_paths.append(
            (deploy_d_from_syspaths, True)
        )

    finished = []
    finished_full = []
    for entry, makedirs in deploy_scripts_search_paths:
        # This handles duplicate entries, which are likely to appear
        if entry in finished:
            continue
        else:
            finished.append(entry)

        if makedirs and not os.path.isdir(entry):
            try:
                os.makedirs(entry)
            except (OSError, IOError) as err:
                log.info('Failed to create directory \'%s\'', entry)
                continue

        if not is_writeable(entry):
            log.debug('The \'%s\' is not writeable. Continuing...', entry)
            continue

        deploy_path = os.path.join(entry, script_name)
        try:
            finished_full.append(deploy_path)
            with salt.utils.files.fopen(deploy_path, 'w') as fp_:
                fp_.write(salt.utils.stringutils.to_str(script_content))
        except (OSError, IOError) as err:
            log.debug('Failed to write the updated script: %s', err)
            continue

    return {'Success': {'Files updated': finished_full}}
153658
def load_default_templates(self):
        """"""
        for importer, modname, is_pkg in pkgutil.iter_modules(templates.__path__):
            self.register_template('.'.join((templates.__name__, modname)))
1259557
def load_module(self, name):
        """"""
        if name in sys.modules:
            return sys.modules[name]
        # load the actual import hook module
        module_name = self.mount2name(name)
        __import__(module_name)
        # alias the import hook module to the mount, so both can be used interchangeably
        module = sys.modules[name] = sys.modules[module_name]
        module.install()
        return module
1049131
def _init():
    
    global finder

    if finder is None:
        finder = ModuleFinder()

    if finder not in sys.meta_path:
        sys.meta_path.insert(0, finder)
1004729
def force_lazy_import(name):
  
  obj = import_object(name)
  module_items = list(getattr(obj, '__dict__', {}).items())
  for key, value in module_items:
    if getattr(value, '__module__', None):
        import_object(name + '.' + key)
920589
private function bootModules()
    {
        foreach ($this->app['modules']->enabled() as $module) {
            $this->registerViewNamespace($module);
            $this->registerLanguageNamespace($module);
            $this->registerConfigNamespace($module);
        }
    }
88272
function bootstrapLessFilenames() {
    var IMPORT_REGEX = /^@import \"(.*?)\";$/
    var bootstrapLessLines = __less['bootstrap.less'].split('\n')

    for (var i = 0, imports = []; i < bootstrapLessLines.length; i++) {
      var match = IMPORT_REGEX.exec(bootstrapLessLines[i])
      if (match) imports.push(match[1])
    }

    return imports
  }
6076
def my_import(name, path=None):
    """"""

    # Documentation for importlib says this may be needed to pick up
    # modules created after the program has started
    if hasattr(importlib, 'invalidate_caches'):
        # python 3.3+
        importlib.invalidate_caches()

    if path is not None:
        directory, src_file = os.path.split(path)

        # TODO: use the importlib.util machinery
        sys.path.insert(0, directory)
        try:
            mod = importlib.import_module(name)
        finally:
            sys.path.pop(0)

    else:
        mod = importlib.import_module(name)

    return mod
276030
def create_module(self, spec):
        """"""
        mod = sys.modules.setdefault(spec.name, types.ModuleType(spec.name))
        # we are using setdefault to satisfy https://docs.python.org/3/reference/import.html#loaders
        return mod
913118
def load_model_from_package(name, **overrides):
    """"""
    cls = importlib.import_module(name)
    return cls.load(**overrides)