annotate Tools/scripts/pathfix.py @ 74006:88198b93ff2f

Issue #13560: Add PyUnicode_EncodeLocale() * Use PyUnicode_EncodeLocale() in time.strftime() if wcsftime() is not available * Document my last changes in Misc/NEWS
author Victor Stinner <victor.stinner@haypocalc.com>
date Sat, 17 Dec 2011 04:13:41 +0100
parents e3e6aa633f33
children c57d99a8fc42 6cfe2982de42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
1 #!/usr/bin/env python3
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # Change the #! line occurring in Python scripts. The new interpreter
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # pathname must be given with a -i option.
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 # Command line arguments are files or directories to be processed.
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # Directories are searched recursively for files whose name looks
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # like a python module.
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 # Symbolic links are always ignored (except as explicit directory
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 # arguments). Of course, the original file is kept as a back-up
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 # (with a "~" attached to its name).
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 # Undoubtedly you can do this using find and sed or perl, but this is
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 # a nice example of Python code that recurses down a directory tree
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 # and uses regular expressions. Also note several subtleties like
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 # preserving the file's mode and avoiding to even write a temp file
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 # when no changes are needed for a file.
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 # NB: by changing only the function fixfile() you can turn this
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 # into a program for a different change to Python programs...
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 import sys
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 33076
diff changeset
23 import re
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 import os
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 from stat import *
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 import getopt
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 err = sys.stderr.write
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 dbg = err
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 rep = sys.stdout.write
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 new_interpreter = None
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
33 preserve_timestamps = False
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 def main():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
36 global new_interpreter
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
37 global preserve_timestamps
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
38 usage = ('usage: %s -i /interpreter -p file-or-directory ...\n' %
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
39 sys.argv[0])
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
40 try:
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
41 opts, args = getopt.getopt(sys.argv[1:], 'i:p')
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 37879
diff changeset
42 except getopt.error as msg:
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
43 err(str(msg) + '\n')
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
44 err(usage)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
45 sys.exit(2)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
46 for o, a in opts:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
47 if o == '-i':
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
48 new_interpreter = a.encode()
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
49 if o == '-p':
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
50 preserve_timestamps = True
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
51 if not new_interpreter or not new_interpreter.startswith(b'/') or \
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
52 not args:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
53 err('-i option or file-or-directory missing\n')
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
54 err(usage)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
55 sys.exit(2)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
56 bad = 0
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
57 for arg in args:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
58 if os.path.isdir(arg):
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
59 if recursedown(arg): bad = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
60 elif os.path.islink(arg):
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
61 err(arg + ': will not process symbolic links\n')
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
62 bad = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
63 else:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
64 if fix(arg): bad = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
65 sys.exit(bad)
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
66
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents: 33076
diff changeset
67 ispythonprog = re.compile('^[a-zA-Z0-9_]+\.py$')
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 def ispython(name):
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
69 return bool(ispythonprog.match(name))
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 def recursedown(dirname):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
72 dbg('recursedown(%r)\n' % (dirname,))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
73 bad = 0
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
74 try:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
75 names = os.listdir(dirname)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 37879
diff changeset
76 except os.error as msg:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
77 err('%s: cannot list directory: %r\n' % (dirname, msg))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
78 return 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
79 names.sort()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
80 subdirs = []
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
81 for name in names:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
82 if name in (os.curdir, os.pardir): continue
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
83 fullname = os.path.join(dirname, name)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
84 if os.path.islink(fullname): pass
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
85 elif os.path.isdir(fullname):
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
86 subdirs.append(fullname)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
87 elif ispython(name):
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
88 if fix(fullname): bad = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
89 for fullname in subdirs:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
90 if recursedown(fullname): bad = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
91 return bad
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 def fix(filename):
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
94 ## dbg('fix(%r)\n' % (filename,))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
95 try:
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
96 f = open(filename, 'rb')
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 37879
diff changeset
97 except IOError as msg:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
98 err('%s: cannot open: %r\n' % (filename, msg))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
99 return 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
100 line = f.readline()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
101 fixed = fixline(line)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
102 if line == fixed:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
103 rep(filename+': no change\n')
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
104 f.close()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
105 return
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
106 head, tail = os.path.split(filename)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
107 tempname = os.path.join(head, '@' + tail)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
108 try:
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
109 g = open(tempname, 'wb')
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 37879
diff changeset
110 except IOError as msg:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
111 f.close()
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
112 err('%s: cannot create: %r\n' % (tempname, msg))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
113 return 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
114 rep(filename + ': updating\n')
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
115 g.write(fixed)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
116 BUFSIZE = 8*1024
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
117 while 1:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
118 buf = f.read(BUFSIZE)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
119 if not buf: break
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
120 g.write(buf)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
121 g.close()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
122 f.close()
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
124 # Finishing touch -- move files
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
126 mtime = None
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
127 atime = None
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
128 # First copy the file's mode to the temp file
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
129 try:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
130 statbuf = os.stat(filename)
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
131 mtime = statbuf.st_mtime
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
132 atime = statbuf.st_atime
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
133 os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 37879
diff changeset
134 except os.error as msg:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
135 err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
136 # Then make a backup of the original file as filename~
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
137 try:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
138 os.rename(filename, filename + '~')
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 37879
diff changeset
139 except os.error as msg:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
140 err('%s: warning: backup failed (%r)\n' % (filename, msg))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
141 # Now move the temp file to the original file
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
142 try:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
143 os.rename(tempname, filename)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 37879
diff changeset
144 except os.error as msg:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 25219
diff changeset
145 err('%s: rename failed (%r)\n' % (filename, msg))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
146 return 1
65538
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
147 if preserve_timestamps:
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
148 if atime and mtime:
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
149 try:
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
150 os.utime(filename, (atime, mtime))
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
151 except os.error as msg:
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
152 err('%s: reset of timestamp failed (%r)\n' % (filename, msg))
e3e6aa633f33 Fix Issue10140 - Tools/scripts/pathfix.py: add option to preserve timestamps
Senthil Kumaran <orsenthil@gmail.com>
parents: 56221
diff changeset
153 return 1
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
154 # Return succes
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
155 return 0
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 def fixline(line):
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
158 if not line.startswith(b'#!'):
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
159 return line
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
160 if b"python" not in line:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4568
diff changeset
161 return line
56221
2644f54e3676 Merged revisions 75061-75062 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 42084
diff changeset
162 return b'#! ' + new_interpreter + b'\n'
1799
60660341ee10 newslist.py: Added search for .newslistrc.py;
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
33074
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 31515
diff changeset
164 if __name__ == '__main__':
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 31515
diff changeset
165 main()