diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-01-17 08:48:39 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-01-17 08:48:39 (GMT) |
commit | 70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7 (patch) | |
tree | cf47b67db3753288cfd9fa2adc45e7c5cd2f8741 /Tools/scripts/pathfix.py | |
parent | a88854059309667092000da55d4d5a5804267e9f (diff) | |
download | cpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.zip cpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.tar.gz cpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.tar.bz2 |
Whitespace normalization.
Diffstat (limited to 'Tools/scripts/pathfix.py')
-rwxr-xr-x | Tools/scripts/pathfix.py | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py index be04b21..d4e3071 100755 --- a/Tools/scripts/pathfix.py +++ b/Tools/scripts/pathfix.py @@ -33,117 +33,117 @@ rep = sys.stdout.write new_interpreter = None def main(): - global new_interpreter - usage = ('usage: %s -i /interpreter file-or-directory ...\n' % - sys.argv[0]) - try: - opts, args = getopt.getopt(sys.argv[1:], 'i:') - except getopt.error, msg: - err(msg + '\n') - err(usage) - sys.exit(2) - for o, a in opts: - if o == '-i': - new_interpreter = a - if not new_interpreter or new_interpreter[0] != '/' or not args: - err('-i option or file-or-directory missing\n') - err(usage) - sys.exit(2) - bad = 0 - for arg in args: - if os.path.isdir(arg): - if recursedown(arg): bad = 1 - elif os.path.islink(arg): - err(arg + ': will not process symbolic links\n') - bad = 1 - else: - if fix(arg): bad = 1 - sys.exit(bad) + global new_interpreter + usage = ('usage: %s -i /interpreter file-or-directory ...\n' % + sys.argv[0]) + try: + opts, args = getopt.getopt(sys.argv[1:], 'i:') + except getopt.error, msg: + err(msg + '\n') + err(usage) + sys.exit(2) + for o, a in opts: + if o == '-i': + new_interpreter = a + if not new_interpreter or new_interpreter[0] != '/' or not args: + err('-i option or file-or-directory missing\n') + err(usage) + sys.exit(2) + bad = 0 + for arg in args: + if os.path.isdir(arg): + if recursedown(arg): bad = 1 + elif os.path.islink(arg): + err(arg + ': will not process symbolic links\n') + bad = 1 + else: + if fix(arg): bad = 1 + sys.exit(bad) ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$') def ispython(name): - return ispythonprog.match(name) >= 0 + return ispythonprog.match(name) >= 0 def recursedown(dirname): - dbg('recursedown(' + `dirname` + ')\n') - bad = 0 - try: - names = os.listdir(dirname) - except os.error, msg: - err(dirname + ': cannot list directory: ' + `msg` + '\n') - return 1 - names.sort() - subdirs = [] - for name in names: - if name in (os.curdir, os.pardir): continue - fullname = os.path.join(dirname, name) - if os.path.islink(fullname): pass - elif os.path.isdir(fullname): - subdirs.append(fullname) - elif ispython(name): - if fix(fullname): bad = 1 - for fullname in subdirs: - if recursedown(fullname): bad = 1 - return bad + dbg('recursedown(' + `dirname` + ')\n') + bad = 0 + try: + names = os.listdir(dirname) + except os.error, msg: + err(dirname + ': cannot list directory: ' + `msg` + '\n') + return 1 + names.sort() + subdirs = [] + for name in names: + if name in (os.curdir, os.pardir): continue + fullname = os.path.join(dirname, name) + if os.path.islink(fullname): pass + elif os.path.isdir(fullname): + subdirs.append(fullname) + elif ispython(name): + if fix(fullname): bad = 1 + for fullname in subdirs: + if recursedown(fullname): bad = 1 + return bad def fix(filename): -## dbg('fix(' + `filename` + ')\n') - try: - f = open(filename, 'r') - except IOError, msg: - err(filename + ': cannot open: ' + `msg` + '\n') - return 1 - line = f.readline() - fixed = fixline(line) - if line == fixed: - rep(filename+': no change\n') - f.close() - return - head, tail = os.path.split(filename) - tempname = os.path.join(head, '@' + tail) - try: - g = open(tempname, 'w') - except IOError, msg: - f.close() - err(tempname+': cannot create: '+`msg`+'\n') - return 1 - rep(filename + ': updating\n') - g.write(fixed) - BUFSIZE = 8*1024 - while 1: - buf = f.read(BUFSIZE) - if not buf: break - g.write(buf) - g.close() - f.close() +## dbg('fix(' + `filename` + ')\n') + try: + f = open(filename, 'r') + except IOError, msg: + err(filename + ': cannot open: ' + `msg` + '\n') + return 1 + line = f.readline() + fixed = fixline(line) + if line == fixed: + rep(filename+': no change\n') + f.close() + return + head, tail = os.path.split(filename) + tempname = os.path.join(head, '@' + tail) + try: + g = open(tempname, 'w') + except IOError, msg: + f.close() + err(tempname+': cannot create: '+`msg`+'\n') + return 1 + rep(filename + ': updating\n') + g.write(fixed) + BUFSIZE = 8*1024 + while 1: + buf = f.read(BUFSIZE) + if not buf: break + g.write(buf) + g.close() + f.close() - # Finishing touch -- move files + # Finishing touch -- move files - # First copy the file's mode to the temp file - try: - statbuf = os.stat(filename) - os.chmod(tempname, statbuf[ST_MODE] & 07777) - except os.error, msg: - err(tempname + ': warning: chmod failed (' + `msg` + ')\n') - # Then make a backup of the original file as filename~ - try: - os.rename(filename, filename + '~') - except os.error, msg: - err(filename + ': warning: backup failed (' + `msg` + ')\n') - # Now move the temp file to the original file - try: - os.rename(tempname, filename) - except os.error, msg: - err(filename + ': rename failed (' + `msg` + ')\n') - return 1 - # Return succes - return 0 + # First copy the file's mode to the temp file + try: + statbuf = os.stat(filename) + os.chmod(tempname, statbuf[ST_MODE] & 07777) + except os.error, msg: + err(tempname + ': warning: chmod failed (' + `msg` + ')\n') + # Then make a backup of the original file as filename~ + try: + os.rename(filename, filename + '~') + except os.error, msg: + err(filename + ': warning: backup failed (' + `msg` + ')\n') + # Now move the temp file to the original file + try: + os.rename(tempname, filename) + except os.error, msg: + err(filename + ': rename failed (' + `msg` + ')\n') + return 1 + # Return succes + return 0 def fixline(line): - if line[:2] != '#!': - return line - if string.find(line, "python") < 0: - return line - return '#! %s\n' % new_interpreter + if line[:2] != '#!': + return line + if string.find(line, "python") < 0: + return line + return '#! %s\n' % new_interpreter main() |