]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.2/Tools/scripts/svneol.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / scripts / svneol.py
CommitLineData
4710c53d 1#! /usr/bin/env python\r
2\r
3"""\r
4SVN helper script.\r
5\r
6Try to set the svn:eol-style property to "native" on every .py, .txt, .c and\r
7.h file in the directory tree rooted at the current directory.\r
8\r
9Files with the svn:eol-style property already set (to anything) are skipped.\r
10\r
11svn will itself refuse to set this property on a file that's not under SVN\r
12control, or that has a binary mime-type property set. This script inherits\r
13that behavior, and passes on whatever warning message the failing "svn\r
14propset" command produces.\r
15\r
16In the Python project, it's safe to invoke this script from the root of\r
17a checkout.\r
18\r
19No output is produced for files that are ignored. For a file that gets\r
20svn:eol-style set, output looks like:\r
21\r
22 property 'svn:eol-style' set on 'Lib\ctypes\__init__.py'\r
23\r
24For a file not under version control:\r
25\r
26 svn: warning: 'patch-finalizer.txt' is not under version control\r
27\r
28and for a file with a binary mime-type property:\r
29\r
30 svn: File 'Lib\test\test_pep263.py' has binary mime type property\r
31"""\r
32\r
33import re\r
34import os\r
35\r
36def propfiles(root, fn):\r
37 default = os.path.join(root, ".svn", "props", fn+".svn-work")\r
38 try:\r
39 format = int(open(os.path.join(root, ".svn", "format")).read().strip())\r
40 except IOError:\r
41 return []\r
42 if format in (8, 9):\r
43 # In version 8 and 9, committed props are stored in prop-base, local\r
44 # modifications in props\r
45 return [os.path.join(root, ".svn", "prop-base", fn+".svn-base"),\r
46 os.path.join(root, ".svn", "props", fn+".svn-work")]\r
47 raise ValueError, "Unknown repository format"\r
48\r
49def proplist(root, fn):\r
50 "Return a list of property names for file fn in directory root"\r
51 result = []\r
52 for path in propfiles(root, fn):\r
53 try:\r
54 f = open(path)\r
55 except IOError:\r
56 # no properties file: not under version control,\r
57 # or no properties set\r
58 continue\r
59 while 1:\r
60 # key-value pairs, of the form\r
61 # K <length>\r
62 # <keyname>NL\r
63 # V length\r
64 # <value>NL\r
65 # END\r
66 line = f.readline()\r
67 if line.startswith("END"):\r
68 break\r
69 assert line.startswith("K ")\r
70 L = int(line.split()[1])\r
71 key = f.read(L)\r
72 result.append(key)\r
73 f.readline()\r
74 line = f.readline()\r
75 assert line.startswith("V ")\r
76 L = int(line.split()[1])\r
77 value = f.read(L)\r
78 f.readline()\r
79 f.close()\r
80 return result\r
81\r
82possible_text_file = re.compile(r"\.([hc]|py|txt|sln|vcproj)$").search\r
83\r
84for root, dirs, files in os.walk('.'):\r
85 if '.svn' in dirs:\r
86 dirs.remove('.svn')\r
87 for fn in files:\r
88 if possible_text_file(fn):\r
89 if 'svn:eol-style' not in proplist(root, fn):\r
90 path = os.path.join(root, fn)\r
91 os.system('svn propset svn:eol-style native "%s"' % path)\r