Finds the base directory where repos are kept
 Checks the environment variable PRO_BASE and the
 file .proBase
179295
def find_base_dirs()
      bases = []
      # check environment first
      base = ENV['PRO_BASE']
      bases << base if base
      # next check proBase file
      path = ENV['HOME'] + "/.proBase"
      if File.exists?(path)
        # read lines of the pro base file
        bases += IO.read(path).split("\n").map {|p| File.expand_path(p.strip)}
      end
      # strip bases that do not exist
      # I know about select! but it doesn't exist in 1.8
      bases = bases.select {|b| File.exists?(b)}
      # if no bases then return home
      bases << ENV['HOME'] if bases.empty?
      bases
    end
134254
def find_find_repos(where, ignore_error=True):
    
    log.debug(('REPO_REGEX', REPO_REGEX))
    FIND_REPO_REGEXCMD = ("-regex", '.*(%s)$' % REPO_REGEX)
    if os.uname()[0] == 'Darwin':
        cmd = ("find",
               '-E',
               '-L',  # dereference symlinks
               where,
               FIND_REPO_REGEXCMD[0],
               FIND_REPO_REGEXCMD[1])
    else:
        cmd = ("find",
               '-O3',
               '-L',  # dereference symlinks
               where,  # " .",
               "-regextype","posix-egrep",
               FIND_REPO_REGEXCMD[0],
               FIND_REPO_REGEXCMD[1])
    _cmd = ' '.join(cmd)
    log.debug("find_find_repos(%r) = %s" % (where, _cmd))
    kwargs = {
        #'shell': True,
        'cwd': where,
        'stderr': sys.stderr,
        'stdout': subprocess.PIPE,}
    p = subprocess.Popen(cmd, universal_newlines=True, **kwargs)
    if p.returncode and not ignore_error:
        p_stdout = p.communicate()[0]
        raise Exception("Subprocess return code: %d\n%r\n%r" % (
            p.returncode, cmd, p_stdout))

    for l in iter(p.stdout.readline, ''):
        path = l.rstrip()
        _path, _prefix = os.path.dirname(path), os.path.basename(path)
        repo = REPO_PREFIXES.get(_prefix)
        if repo is None:
            log.error("repo for path %r and prefix %r is None" %
                      (path, _prefix))
        if repo:
            yield repo(_path)
77896
function findFilesToPackage(dir, callback) {
    var cwd = process.cwd();
    process.chdir(dir);

    var gitls = spawn('git', ['ls-files']),
        // This gets the full path to each file in each submodule
        subls = spawn('git', ['submodule', 'foreach', 'for file in `git ls-files`; do echo "$path/$file"; done']);
        // List all node_modules
        modls = spawn('find', ['node_modules']);


    var mainFileList = '';
    gitls.stdout.on('data', function (data) {
        mainFileList += data;
    });
    gitls.on('exit', returnFileList);

    var subFileList = '';
    subls.stdout.on('data', function (data) {
        subFileList += data;
    });
    subls.on('exit', returnFileList);
    
    var modFileList = '';
    modls.stdout.on('data', function (data) {
        modFileList += data;
    });
    modls.on('exit', returnFileList);

    var lsCount = 0;
    function returnFileList(code) {
        lsCount++;
        if (lsCount < 3) {
            return;
        }
        process.chdir(cwd);

        // Convert \n separated list of filenames into a sorted array
        var fileList = (mainFileList.trim() + '\n' + subFileList.trim() + '\n' + modFileList.trim()).split('\n').filter(function(file) {
            // Ignore entering submodule messages
            if (file.indexOf('Entering ') === 0) {
                return;
            }

            // Ignore hidden and backup files
            if (file.split('/').pop()[0] == '.' || file[file.length - 1] == '~') {
                return;
            }

            // Submodules appear in ls-files but aren't files. Skip them
            if (fs.statSync(path.join(dir, file)).isDirectory()) {
                return;
            }

            
            return file;
        }).sort();

        callback(fileList);
    }

}
1296205
def find_repo(name)
      return @index.base_dirs.first unless name
      match = FuzzyMatch.new(@index.to_a, :read => :name).find(name)
      match[1] unless match.nil?
    end
826830
function proccessFtpPath(env) {
    if (!env.__ftp_path__ && env.__ftp_base_path__) {
        env.__ftp_base_path__ = util.endsWithForwardSlash(env.__ftp_base_path__);
        env.__ftp_path__ = env.__ftp_base_path__ + (env.__dir__ || pkg.name);
    }

    if (env.__ftp_path__) {
        env.__ftp_path__ = util.endsWithForwardSlash(env.__ftp_path__);
    }

    return env;
}
237074
def _get_configured_repos(root=None):
    '''
    
    '''

    repos = os.path.join(root, os.path.relpath(REPOS, os.path.sep)) if root else REPOS
    repos_cfg = configparser.ConfigParser()
    if os.path.exists(repos):
        repos_cfg.read([repos + '/' + fname for fname in os.listdir(repos) if fname.endswith(".repo")])
    else:
        log.warning('Repositories not found in %s', repos)

    return repos_cfg
148242
def _get_specific_dir(dir_type):
    """"""
    if SNAP_BASEDIR_NAME in os.environ:
        logger.debug("Getting base dir information from SNAP_BASEDIR_NAME env var.")
        direct = os.path.join(os.environ[SNAP_BASEDIR_NAME], dir_type)
    else:
        try:
            basedirectory = _get_basedirectory()
        except ImportError:
            logger.debug("Using last resort base dir: ~/.fades")
            from os.path import expanduser
            direct = os.path.join(expanduser("~"), ".fades")
        else:
            xdg_attrib = 'xdg_{}_home'.format(dir_type)
            base = getattr(basedirectory, xdg_attrib)
            direct = os.path.join(base, 'fades')

    if not os.path.exists(direct):
        os.makedirs(direct)
    return direct
155221
def load_env_directory():
    
    for var in glob.glob(os.path.join(ENV_DIRECTORY, '*')):
        if os.path.isfile(var):
            os.environ[os.path.basename(var)] = os.path.expandvars(open(var, encoding='utf-8').read())
1233429
def find_repositories_by_walking_and_following_symlinks(path):
    """"""
    repos = []

    # This is for detecting symlink loops and escaping them. This is similar to
    # http://stackoverflow.com/questions/36977259/avoiding-infinite-recursion-with-os-walk/36977656#36977656
    def inode(path):
        stats = os.stat(path)
        return stats.st_dev, stats.st_ino
    seen_inodes = {inode(path)}

    for dirpath, dirnames, filenames in os.walk(path, followlinks=True):
        inodes = [inode(os.path.join(dirpath, p)) for p in dirnames]
        dirnames[:] = [p for p, i in zip(dirnames, inodes)
                       if not i in seen_inodes]
        seen_inodes.update(inodes)

        for dotdir in set(dirnames) & DOTDIRS:
            repos.append((dirpath, dotdir))
    return repos
113706
def get_env_dirs(self):
        """"""
        repo_dirs = next(os.walk(self.env_root))[1]
        if '.git' in repo_dirs:
            repo_dirs.remove('.git')  # not relevant for any repo operations
        return repo_dirs
446286
def find_cache_directory(remote):
    
    return os.path.join('/var/cache/vcs-repo-mgr' if os.access('/var/cache', os.W_OK) else tempfile.gettempdir(),
                        urlparse.quote(remote, safe=''))
1020486
def _get_subdirectory(cls, location):
        """"""
        # find the repo root
        git_dir = cls.run_command(['rev-parse', '--git-dir'],
                                  show_stdout=False, cwd=location).strip()
        if not os.path.isabs(git_dir):
            git_dir = os.path.join(location, git_dir)
        root_dir = os.path.join(git_dir, '..')
        # find setup.py
        orig_location = location
        while not os.path.exists(os.path.join(location, 'setup.py')):
            last_location = location
            location = os.path.dirname(location)
            if location == last_location:
                # We've traversed up to the root of the filesystem without
                # finding setup.py
                logger.warning(
                    "Could not find setup.py for directory %s (tried all "
                    "parent directories)",
                    orig_location,
                )
                return None
        # relative path of setup.py to repo root
        if samefile(root_dir, location):
            return None
        return os.path.relpath(location, root_dir)
241470
def check_for_local_repos(repo):
    
    repos_dict = Repo().default_repository()
    if repo in repos_dict:
        repo_url = repos_dict[repo]
        if repo_url.startswith("file:///"):
            return True
434965
def index_repos_slow(base)
      STDERR.puts "WARNING: pro is indexing slowly, please install the 'find' command."
      repos = []
      Find.find(base) do |path|
        target = path
        # additionally, index repos symlinked directly from a base root
        if FileTest.symlink?(path)
          next if File.dirname(path) != base
          target = File.readlink(path)
        end
        # dir must exist and be a git repo
        if FileTest.directory?(target) && File.exists?(path+"/.git")
          base_name = File.basename(path)
          repos << Repo.new(base_name,path)
          Find.prune
        end
      end
      repos
    end
191886
def get_env(working_directory=None):
    
    working = working_directory if working_directory else os.getcwd()
    dist_dirs = glob.glob(working + "/f5-*-dist")
    print(dist_dirs)
    dist_dir_re = re.compile('/([^/]+)-dist/?')
    if dist_dirs:
        dist_dir = dist_dirs[0]
        match = dist_dir_re.search(dist_dir)
        if match:
            project_name = match.group(1)
        else:
            print("Unrecognized run location:\n" + working)
            exit_cleanly(errnum=errno.EIO)
    elif '-dist/scripts' in working:
        match = dist_dir_re.search(working)
        if match:
            project_name = match.group(1)
    else:
        print("Unable to determine the *-dist directory from " + working)
        exit_cleanly(errnum=errno.ENOSYS)
    stdeb_cfg = dist_dir + "/deb_dist/stdeb.cfg"
    setup_cfg = working + "/setup.cfg"
    stp_reqs = working + "/setup_requirements.txt"
    scripts = dist_dir + "/scripts"
    env = {'working': working, 'dist_dir': dist_dir, 'stdeb_cfg': stdeb_cfg,
           'setup_requirements': stp_reqs, 'setup_cfg': setup_cfg,
           'scripts': scripts, 'project': project_name}
    return env
958079
function findFilesWithPlaceholders(packageDir) {
  const findCommand = buildPlaceholderFindCommand(packageDir);
  return spawnSync(findCommand.binary, findCommand.args).stdout
    .toString()
    .split(/[\n\r]/)
    .filter(String);
}
773758
def find_vcs_root(path, dirs=(".git",)):
    """"""
    prev, path = None, os.path.abspath(path)
    while prev != path:
        if any(os.path.exists(os.path.join(path, d)) for d in dirs):
            return path
        prev, path = path, os.path.abspath(os.path.join(path, os.pardir))
    return None