Expand a list of filenames using environment variables,
        followed by expansion of shell-style wildcards.
499312
def expand_filenames(self, filenames):
        
        results = []
        for filename in filenames:
            result = filename
            if "$" in filename:
                template = Template(filename)
                result = template.substitute(**self.environment)
                logging.debug(
                    "Expanding {} to {}.".format(filename, result))
            if any([pattern in result for pattern in "*[]?"]):
                expanded = glob.glob(result)
                if len(expanded) > 0:
                    result = expanded
                else:
                    result = "NONEXISTENT"
            if isinstance(result, list):
                results.extend(result)
            else:
                results.append(result)
        return sorted(list(set(results)))
373824
def expandvars(path):
    

    path = path2fsn(path)

    def repl_func(match):
        return environ.get(match.group(1), match.group(0))

    path = re.compile(r"\$(\w+)", flags=re.UNICODE).sub(repl_func, path)
    if os.name == "nt":
        path = re.sub(r"%([^%]+)%", repl_func, path)
    return re.sub(r"\$\{([^\}]+)\}", repl_func, path)
1258013
def expand(self, expand):
        '''
        
        '''
        self._expand = expand
        cmd = self._original_cmd
        if len(cmd) == 1:
            if not type(cmd[0]) in (str, unicode):
                cmd = cmd[0]
            else:
                cmd = shlex.split(cmd[0])
        cmd = [os.path.expanduser(os.path.expandvars(arg)) for arg in cmd]
        self._cmd, self._args = cmd[0], cmd[1:]
        return self
1334695
private List<File> asFiles(File srcDir, String[] files, FileNameMapper m) {
    List<File> newFiles = new ArrayList<>();
    for(String file : files) {
      boolean hasMatchingExtension = m.mapFileName(file) != null; //use mapFileName as a check to validate if the source file extension is recognized by the mapper or not
      if(hasMatchingExtension) {
        newFiles.add(new File(srcDir, file));
      }
    }
    return newFiles;
  }
1112720
def add_filename_pattern(self, dir_name, pattern):
        
        full_pattern = '{}{}{}'.format(dir_name, os.sep, pattern)
        filename_regex = fnmatch.translate(full_pattern)
        self.regex_list.append(re.compile(filename_regex))
457141
function globsToExcludeFromFileSet (dirname, fileset) {
  if (fileset.excludes && fileset.excludes.length) {
    return fileset.excludes.map(exclude => '!' + path.join(dirname, exclude));
  } else {
    return [];
  }
}
354607
function expandFiles(files, workingDirectory) {
  const promises = [];
  files.forEach((file) => {
    if (
      file.path !== './package.json' && file.path !== './npm-shrinkwrap.json'
    ) {
      promises.push(Promise.resolve(file));
      return;
    }
    findPackageDependencies(workingDirectory, true).forEach((dep) => {
      let resolvedPath;
      try {
        resolvedPath = forwardSlashes(path.relative(
          workingDirectory,
          requireRelative.resolve(dep, workingDirectory),
        ));
        if (!resolvedPath.startsWith('.')) {
          // path.relative won't add "./", but we need it further down the line
          resolvedPath = `./${resolvedPath}`;
        }
      } catch (e) {
        winston.error(`Failed to resolve "${dep}" relative to ${workingDirectory}`);
        return;
      }

      promises.push(lastUpdate.failSafe(resolvedPath, workingDirectory)
        .then(({ mtime }) =>
          Promise.resolve({
            path: resolvedPath,
            mtime,
            packageName: dep,
          })));
    });
  });
  return Promise.all(promises);
}
934431
def setFilenames( self, filenames ):
        
        mapped = []
        for filename in filenames:
            filename = nativestring(filename)
            if ( not filename ):
                continue
            
            mapped.append(filename)
            if ( len(mapped) == self.maximumLength() ):
                break
        
        self._filenames = mapped
        self.refresh()
1268577
def _expand_filename(self, line):
        """"""
        # expand .
        newline = line
        path = os.getcwd()
        if newline.startswith("."):
            newline = newline.replace(".", path, 1)
        # expand ~
        newline = os.path.expanduser(newline)
        return newline
67629
def expand_path(*paths):
    """"""
    return os.path.join(
        os.path.dirname(os.path.realpath(sys.argv[0])), *paths)
1338239
def expand_defaults(self, client=False, getenv=True, getshell=True):
        
        if not isinstance(self._default, six.string_types):
            self.expanded_default = self._default
        else:
            self.expanded_default = coerce(self.type, expand_defaults(
                self._default, client, getenv, getshell))
730892
def _expand_paths(self, paths):
        """"""
        paths = ninja_syntax.as_list(paths)
        return ' '.join(map(self._shell_escape, (map(self._expand, paths))))
1226873
function _expandNestedPaths(paths) {
  var expandedPaths = [];

  _pathsArray(paths).forEach(function (p) {
    if (p.indexOf('.') !== -1) {
      var pathsWithRoots = p.split('.').map(function (value, index, array) {
        return array.slice(0, index + 1).join('.');
      });

      expandedPaths = expandedPaths.concat(pathsWithRoots);
    } else {
      expandedPaths.push(p);
    }
  });

  return expandedPaths;
}
651533
function ExpandFiles(options) {
  if (!(this instanceof ExpandFiles)) {
    return new ExpandFiles(options);
  }

  Base.call(this, {}, options);
  this.use(utils.plugins());
  this.is('Files');

  this.options = options || {};
  if (util.isFiles(options) || arguments.length > 1) {
    this.options = {};
    this.expand.apply(this, arguments);
    return this;
  }
}
1287901
def path_expand(text):
    
    result = os.path.expandvars(os.path.expanduser(text))

    # template = Template(text)
    # result = template.substitute(os.environ)

    if result.startswith("."):
        result = result.replace(".", os.getcwd(), 1)

    return result
1126185
def glob(cls, files=None):
        '''
        
        '''
        files = files or []
        if isinstance(files, str):
            files = os.path.normpath(files)
            matches = lambda path: matches_patterns(path, [files])
            return [path for path in cls.get_static_files() if matches(path)]
        elif isinstance(files, (list, tuple)):
            all_files = cls.get_static_files()
            files = [os.path.normpath(f) for f in files]
            sorted_result = []
            for pattern in files:
                sorted_result.extend([f for f in all_files if matches_patterns(f, [pattern])])
            return sorted_result
1184861
def _expand_list(names):
  

  if names is None:
    names = []
  elif isinstance(names, basestring):
    names = [names]

  results = []  # The expanded list.
  objects = {}  # Cached contents of buckets; used for matching.
  for name in names:
    bucket, key = google.datalab.storage._bucket.parse_name(name)
    results_len = len(results)  # If we fail to add any we add name and let caller deal with it.
    if bucket:
      if not key:
        # Just a bucket; add it.
        results.append('gs://%s' % bucket)
      elif google.datalab.storage.Object(bucket, key).exists():
        results.append('gs://%s/%s' % (bucket, key))
      else:
        # Expand possible key values.
        if bucket not in objects and key[:1] == '*':
          # We need the full list; cache a copy for efficiency.
          objects[bucket] = [obj.metadata.name
                             for obj in list(google.datalab.storage.Bucket(bucket).objects())]
        # If we have a cached copy use it
        if bucket in objects:
          candidates = objects[bucket]
        # else we have no cached copy but can use prefix matching which is more efficient than
        # getting the full contents.
        else:
          # Get the non-wildchar prefix.
          match = re.search('\?|\*|\[', key)
          prefix = key
          if match:
            prefix = key[0:match.start()]

          candidates = [obj.metadata.name
                        for obj in google.datalab.storage.Bucket(bucket).objects(prefix=prefix)]

        for obj in candidates:
          if fnmatch.fnmatch(obj, key):
            results.append('gs://%s/%s' % (bucket, obj))

    # If we added no matches, add the original name and let caller deal with it.
    if len(results) == results_len:
      results.append(name)

  return results