mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
Clean up syntax for some scripts.
This commit is contained in:
parent
aba74bddd6
commit
e4a3380bb0
7 changed files with 115 additions and 87 deletions
|
@ -32,9 +32,12 @@ and for a file with a binary mime-type property:
|
|||
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
|
||||
def propfiles(root, fn):
|
||||
default = os.path.join(root, ".svn", "props", fn+".svn-work")
|
||||
default = os.path.join(root, ".svn", "props", fn + ".svn-work")
|
||||
try:
|
||||
format = int(open(os.path.join(root, ".svn", "format")).read().strip())
|
||||
except IOError:
|
||||
|
@ -42,12 +45,13 @@ def propfiles(root, fn):
|
|||
if format in (8, 9):
|
||||
# In version 8 and 9, committed props are stored in prop-base, local
|
||||
# modifications in props
|
||||
return [os.path.join(root, ".svn", "prop-base", fn+".svn-base"),
|
||||
os.path.join(root, ".svn", "props", fn+".svn-work")]
|
||||
raise ValueError, "Unknown repository format"
|
||||
return [os.path.join(root, ".svn", "prop-base", fn + ".svn-base"),
|
||||
os.path.join(root, ".svn", "props", fn + ".svn-work")]
|
||||
raise ValueError("Unknown repository format")
|
||||
|
||||
|
||||
def proplist(root, fn):
|
||||
"Return a list of property names for file fn in directory root"
|
||||
"""Return a list of property names for file fn in directory root."""
|
||||
result = []
|
||||
for path in propfiles(root, fn):
|
||||
try:
|
||||
|
@ -56,7 +60,7 @@ def proplist(root, fn):
|
|||
# no properties file: not under version control,
|
||||
# or no properties set
|
||||
continue
|
||||
while 1:
|
||||
while True:
|
||||
# key-value pairs, of the form
|
||||
# K <length>
|
||||
# <keyname>NL
|
||||
|
@ -79,13 +83,32 @@ def proplist(root, fn):
|
|||
f.close()
|
||||
return result
|
||||
|
||||
|
||||
def set_eol_native(path):
|
||||
cmd = 'svn propset svn:eol-style native "{}"'.format(path)
|
||||
propset = subprocess.Popen(cmd, shell=True)
|
||||
propset.wait()
|
||||
|
||||
|
||||
possible_text_file = re.compile(r"\.([hc]|py|txt|sln|vcproj)$").search
|
||||
|
||||
for root, dirs, files in os.walk('.'):
|
||||
if '.svn' in dirs:
|
||||
dirs.remove('.svn')
|
||||
for fn in files:
|
||||
if possible_text_file(fn):
|
||||
|
||||
def main():
|
||||
for arg in sys.argv[1:] or [os.curdir]:
|
||||
if os.path.isfile(arg):
|
||||
root, fn = os.path.split(arg)
|
||||
if 'svn:eol-style' not in proplist(root, fn):
|
||||
path = os.path.join(root, fn)
|
||||
os.system('svn propset svn:eol-style native "%s"' % path)
|
||||
set_eol_native(arg)
|
||||
elif os.path.isdir(arg):
|
||||
for root, dirs, files in os.walk(arg):
|
||||
if '.svn' in dirs:
|
||||
dirs.remove('.svn')
|
||||
for fn in files:
|
||||
if possible_text_file(fn):
|
||||
if 'svn:eol-style' not in proplist(root, fn):
|
||||
path = os.path.join(root, fn)
|
||||
set_eol_native(path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue