]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/LongFilePathSupport.py
2 # Override built in function file.open to provide support for long file path
4 # Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 # Convert a file path to a long file path
23 def LongFilePath(FileName
):
24 FileName
= os
.path
.normpath(FileName
)
25 if platform
.system() == 'Windows':
26 if FileName
.startswith('\\\\?\\'):
28 if FileName
.startswith('\\\\'):
29 return '\\\\?\\UNC\\' + FileName
[2:]
30 if os
.path
.isabs(FileName
):
31 return '\\\\?\\' + FileName
36 # wrap open to support opening a long file path
38 def OpenLongFilePath(FileName
, Mode
='r', Buffer
= -1):
39 return open(LongFilePath(FileName
), Mode
, Buffer
)
41 def CodecOpenLongFilePath(Filename
, Mode
='rb', Encoding
=None, Errors
='strict', Buffering
=1):
42 return codecs
.open(LongFilePath(Filename
), Mode
, Encoding
, Errors
, Buffering
)
46 # wrap copyfile to support copy a long file path
48 def CopyLongFilePath(src
, dst
):
49 with
open(LongFilePath(src
), 'rb') as fsrc
:
50 with
open(LongFilePath(dst
), 'wb') as fdst
:
51 shutil
.copyfileobj(fsrc
, fdst
)
53 ## Convert a python unicode string to a normal string
55 # Convert a python unicode string to a normal string
56 # UniToStr(u'I am a string') is 'I am a string'
58 # @param Uni: The python unicode string
60 # @retval: The formatted normal string
63 return repr(Uni
)[2:-1]