]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Common/LongFilePathSupport.py
BaseTools/ECC: Fix some issues of ECC tool
[mirror_edk2.git] / BaseTools / Source / Python / Common / LongFilePathSupport.py
CommitLineData
1be2ed90
HC
1## @file\r
2# Override built in function file.open to provide support for long file path\r
3#\r
4# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14import os\r
15import platform\r
16import shutil\r
17\r
18##\r
19# OpenLongPath\r
20# Convert a file path to a long file path\r
21#\r
22def LongFilePath(FileName):\r
23 FileName = os.path.normpath(FileName)\r
24 if platform.system() == 'Windows':\r
25 if FileName.startswith('\\\\?\\'):\r
26 return FileName\r
27 if FileName.startswith('\\\\'):\r
28 return '\\\\?\\UNC\\' + FileName[2:]\r
29 if os.path.isabs(FileName):\r
30 return '\\\\?\\' + FileName\r
31 return FileName\r
32\r
33##\r
34# OpenLongFilePath\r
35# wrap open to support opening a long file path\r
36#\r
37def OpenLongFilePath(FileName, Mode='r', Buffer= -1):\r
38 return open(LongFilePath(FileName), Mode, Buffer)\r
39\r
40##\r
41# CopyLongFilePath\r
42# wrap copyfile to support copy a long file path\r
43#\r
44def CopyLongFilePath(src, dst):\r
45 with open(LongFilePath(src), 'rb') as fsrc:\r
46 with open(LongFilePath(dst), 'wb') as fdst:\r
47 shutil.copyfileobj(fsrc, fdst)\r
48\r
49## Convert a python unicode string to a normal string\r
50#\r
51# Convert a python unicode string to a normal string\r
52# UniToStr(u'I am a string') is 'I am a string'\r
53#\r
54# @param Uni: The python unicode string\r
55#\r
56# @retval: The formatted normal string\r
57#\r
58def UniToStr(Uni):\r
59 return repr(Uni)[2:-1]\r