コード例 #1
0
ファイル: file_path.py プロジェクト: rmistry/luci-py
  def GetLongPathName(short_path):
    """Returns the Windows long path equivalent for a 'short' path."""
    path = fs.extend(short_path)
    chars = windll.kernel32.GetLongPathNameW(path, None, 0)
    if chars:
      p = create_unicode_buffer(chars)
      if windll.kernel32.GetLongPathNameW(path, p, chars):
        return fs.trim(p.value)

    err = GetLastError()
    if err:
      # pylint: disable=E0602
      msg = u'GetLongPathName(%s): %s (%d)' % (
            short_path, FormatError(err), err)
      raise WindowsError(err, msg.encode('utf-8'))
コード例 #2
0
 def QueryDosDevice(drive_letter):
     """Returns the Windows 'native' path for a DOS drive letter."""
     assert re.match(r'^[a-zA-Z]:$', drive_letter), drive_letter
     assert isinstance(drive_letter, unicode)
     # Guesswork. QueryDosDeviceW never returns the required number of bytes.
     chars = 1024
     drive_letter = drive_letter
     p = create_unicode_buffer(chars)
     if 0 == windll.kernel32.QueryDosDeviceW(drive_letter, p, chars):
         err = GetLastError()
         if err:
             # pylint: disable=E0602
             msg = u'QueryDosDevice(%s): %s (%d)' % (drive_letter,
                                                     FormatError(err), err)
             raise WindowsError(err, msg.encode('utf-8'))
     return p.value
コード例 #3
0
    def GetLongPathName(short_path):
        """Returns the Windows long path equivalent for a 'short' path."""
        assert isinstance(short_path, unicode)
        # Adds '\\\\?\\' when given an absolute path so the MAX_PATH (260) limit is
        # not enforced.
        if os.path.isabs(short_path) and not short_path.startswith('\\\\?\\'):
            short_path = '\\\\?\\' + short_path
        chars = windll.kernel32.GetLongPathNameW(short_path, None, 0)
        if chars:
            p = create_unicode_buffer(chars)
            if windll.kernel32.GetLongPathNameW(short_path, p, chars):
                return p.value

        err = GetLastError()
        if err:
            # pylint: disable=E0602
            msg = u'GetLongPathName(%s): %s (%d)' % (short_path,
                                                     FormatError(err), err)
            raise WindowsError(err, msg.encode('utf-8'))
コード例 #4
0
ファイル: trace_inputs.py プロジェクト: rosas/chromium-1
  def GetShortPathName(long_path):
    """Returns the Windows short path equivalent for a 'long' path."""
    long_path = unicode(long_path)
    # Adds '\\\\?\\' when given an absolute path so the MAX_PATH (260) limit is
    # not enforced.
    if os.path.isabs(long_path) and not long_path.startswith('\\\\?\\'):
      long_path = '\\\\?\\' + long_path
    chars = windll.kernel32.GetShortPathNameW(long_path, None, 0)
    if chars:
      p = create_unicode_buffer(chars)
      if windll.kernel32.GetShortPathNameW(long_path, p, chars):
        return p.value

    err = GetLastError()
    if err:
      # pylint: disable=E0602
      raise WindowsError(
          err,
          'GetShortPathName(%s): %s (%d)' % (
            str(long_path), FormatError(err), err))