Guess windows filenames from a commandline string.
517977
def _GetFilePaths(self, path, pathtype, kb):
    """"""

    environ_vars = artifact_utils.GetWindowsEnvironmentVariablesMap(kb)
    path_guesses = path_detection_windows.DetectExecutablePaths([path],
                                                                environ_vars)

    if not path_guesses:
      # TODO(user): yield a ParserAnomaly object
      return []

    return [
        rdf_paths.PathSpec(path=path, pathtype=pathtype)
        for path in path_guesses
    ]
854488
private static String getFileName(String[] args)
	{
		String fileName = null;
		for (int i=0; i<args.length; i++)
		{
			if (!args[i].startsWith("-"))
			{
				fileName = args[i];
				break;
			}
		}
		return fileName;
	}
314136
def pretty_filename(filename):
    ''''''
    try:
        a = os.path.abspath(filename)
        r = os.path.relpath(filename)
    except ValueError:
        # Catch relpath exception. Happens, because it can not produce relative path
        # if wroking directory is on different drive.
        a = r = filename
    return a if '..' in r else r
460276
def get_dl_dirname(url):
  """"""
  checksum = hashlib.sha256(tf.compat.as_bytes(url)).hexdigest()
  return get_dl_fname(url, checksum)
374351
def complete_filename(text):
    ''''''

    #ensure directories have trailing slashes:
    list = glob.glob(text+'*')
    for idx, val in enumerate(list):
        if os.path.isdir(val):
            list[idx] = (val + os.path.sep)

    return list
932640
def find_windows_executable(bin_path, exe_name):
    """"""
    requested_path = get_windows_path(bin_path, exe_name)
    if os.path.isfile(requested_path):
        return requested_path

    try:
        pathext = os.environ["PATHEXT"]
    except KeyError:
        pass
    else:
        for ext in pathext.split(os.pathsep):
            path = get_windows_path(bin_path, exe_name + ext.strip().lower())
            if os.path.isfile(path):
                return path

    return find_executable(exe_name)
1045313
def cli_program_names(self):
        
        """
        program_names = {}
        for cli_class in self.cli_classes:
            instance = cli_class()
            program_names[instance.program_name] = cli_class
        return program_names
53560
def _guess(self, filename):
        """"""

        encoding = None

        file_size = os.path.getsize(filename)
        # If the file is really big, lets just call it binary.
        # We don't have time to let Python chug through a massive file.
        if not self._is_very_large(file_size):
            with open(filename, "rb") as f:
                if file_size == 0:
                    encoding = 'ascii'
                else:
                    encoding = self._detect_buffer_encoding(f)
                    if encoding is None:
                        raise UnicodeDecodeError('None', b'', 0, 0, 'Unicode cannot be detected.')
                    if encoding != BINARY_ENCODE:
                        encoding = self._verify_encoding(encoding)
        else:  # pragma: no cover
            raise UnicodeDecodeError('None', b'', 0, 0, 'Unicode detection is not applied to very large files!')

        return encoding
651385
def get_single_outfilename(args):
    """"""
    for arg in args['query']:
        if arg in args['files']:
            return ('.'.join(arg.split('.')[:-1])).lower()
        for url in args['urls']:
            if arg.strip('/') in url:
                domain = get_domain(url)
                return get_outfilename(url, domain)
    sys.stderr.write('Failed to construct a single out filename.\n')
    return ''
112542
def _readfname(fname):
    """"""
    try:
        if isinstance(fname, (file, StringIO)):
            astr = fname.read()
        else:
            astr = open(fname, 'rb').read()
    except NameError:
        if isinstance(fname, (FileIO, StringIO)):
            astr = fname.read()
        else:
            astr = mylib2.readfile(fname)
    return astr
1092130
def xstrip(filename):
  
  while xisabs(filename):
    # strip windows drive with all slashes
    if re.match(b'\\w:[\\\\/]', filename):
      filename = re.sub(b'^\\w+:[\\\\/]+', b'', filename)
    # strip all slashes
    elif re.match(b'[\\\\/]', filename):
      filename = re.sub(b'^[\\\\/]+', b'', filename)
  return filename
1209133
def get_proc_name(cmd):
    
    if isinstance(cmd, Iterable) and not isinstance(cmd, str):
        cmd = " ".join(cmd)

    return cmd.split()[0].replace('(', '').replace(')', '')
1054817
def split_filename(pathname):
        
        filepart = win32.PathFindFileName(pathname)
        pathpart = win32.PathRemoveFileSpec(pathname)
        return (pathpart, filepart)
1031089
def get_filenames(is_training, data_dir):
  """"""
  if is_training:
    return [
        os.path.join(data_dir, 'train-%05d-of-01024' % i)
        for i in range(_NUM_TRAIN_FILES)]
  else:
    return [
        os.path.join(data_dir, 'validation-%05d-of-00128' % i)
        for i in range(128)]
413560
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
    

    if os.path.dirname(cmd):
        if os.path.isfile(cmd) and os.access(cmd, mode):
            return cmd

    if path is None:
        path = os.environ.get('PATH', defpath)
    if not path:
        return None

    paths = path.split(pathsep)

    if sys.platform == 'win32':
        # oh boy
        if curdir not in paths:
            paths = [curdir] + paths

        # also need to check the fileexts...
        pathext = os.environ.get('PATHEXT', '').split(pathsep)

        if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
            files = [cmd]
        else:
            files = [cmd + ext for ext in pathext]
    else:
        # sanity
        files = [cmd]

    seen = set()
    for p in paths:
        normpath = normcase(p)
        if normpath in seen:
            continue
        seen.add(normpath)
        for f in files:
            fn = os.path.join(p, f)
            if os.path.isfile(fn) and os.access(fn, mode):
                return fn

    return None
1347678
def Name(self):
    """"""
    return (self.name or self.device_path or self.windowsvolume.drive_letter or
            self.unixvolume.mount_point or None)
645859
def which(filename, env=None):
    ''''''

    # Special case where filename contains an explicit path.
    if os.path.dirname(filename) != '' and is_executable_file(filename):
        return filename
    if env is None:
        env = os.environ
    p = env.get('PATH')
    if not p:
        p = os.defpath
    pathlist = p.split(os.pathsep)
    for path in pathlist:
        ff = os.path.join(path, filename)
        if is_executable_file(ff):
            return ff
    return None