Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9abfc457
Commit
9abfc457
authored
Sep 25, 2009
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct the fixpath.py script to work in Python 3 #6999
parent
8fb00bef
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
Tools/scripts/pathfix.py
Tools/scripts/pathfix.py
+10
-9
No files found.
Tools/scripts/pathfix.py
View file @
9abfc457
#!
/usr/bin/env python
#!
/usr/bin/env python3
# Change the #! line occurring in Python scripts. The new interpreter
# Change the #! line occurring in Python scripts. The new interpreter
# pathname must be given with a -i option.
# pathname must be given with a -i option.
...
@@ -43,8 +43,9 @@ def main():
...
@@ -43,8 +43,9 @@ def main():
sys
.
exit
(
2
)
sys
.
exit
(
2
)
for
o
,
a
in
opts
:
for
o
,
a
in
opts
:
if
o
==
'-i'
:
if
o
==
'-i'
:
new_interpreter
=
a
new_interpreter
=
a
.
encode
()
if
not
new_interpreter
or
new_interpreter
[
0
]
!=
'/'
or
not
args
:
if
not
new_interpreter
or
not
new_interpreter
.
startswith
(
b'/'
)
or
\
not
args
:
err
(
'-i option or file-or-directory missing
\
n
'
)
err
(
'-i option or file-or-directory missing
\
n
'
)
err
(
usage
)
err
(
usage
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
...
@@ -61,7 +62,7 @@ def main():
...
@@ -61,7 +62,7 @@ def main():
ispythonprog
=
re
.
compile
(
'^[a-zA-Z0-9_]+
\
.py$
'
)
ispythonprog
=
re
.
compile
(
'^[a-zA-Z0-9_]+
\
.py$
'
)
def ispython(name):
def ispython(name):
return
ispythonprog.match(name) >= 0
return
bool(ispythonprog.match(name))
def recursedown(dirname):
def recursedown(dirname):
dbg('
recursedown
(
%
r
)
\
n
' % (dirname,))
dbg('
recursedown
(
%
r
)
\
n
' % (dirname,))
...
@@ -88,7 +89,7 @@ def recursedown(dirname):
...
@@ -88,7 +89,7 @@ def recursedown(dirname):
def fix(filename):
def fix(filename):
## dbg('
fix
(
%
r
)
\
n
' % (filename,))
## dbg('
fix
(
%
r
)
\
n
' % (filename,))
try:
try:
f = open(filename, 'r')
f = open(filename, 'r
b
')
except IOError as msg:
except IOError as msg:
err('
%
s
:
cannot
open
:
%
r
\
n
' % (filename, msg))
err('
%
s
:
cannot
open
:
%
r
\
n
' % (filename, msg))
return 1
return 1
...
@@ -101,7 +102,7 @@ def fix(filename):
...
@@ -101,7 +102,7 @@ def fix(filename):
head, tail = os.path.split(filename)
head, tail = os.path.split(filename)
tempname = os.path.join(head, '
@
' + tail)
tempname = os.path.join(head, '
@
' + tail)
try:
try:
g = open(tempname, '
w
')
g = open(tempname, '
w
b
')
except IOError as msg:
except IOError as msg:
f.close()
f.close()
err('
%
s
:
cannot
create
:
%
r
\
n
' % (tempname, msg))
err('
%
s
:
cannot
create
:
%
r
\
n
' % (tempname, msg))
...
@@ -139,11 +140,11 @@ def fix(filename):
...
@@ -139,11 +140,11 @@ def fix(filename):
return
0
return
0
def
fixline
(
line
):
def
fixline
(
line
):
if
not
line
.
startswith
(
'#!'
):
if
not
line
.
startswith
(
b
'#!'
):
return
line
return
line
if
"python"
not
in
line
:
if
b
"python"
not
in
line
:
return
line
return
line
return
'#! %s
\
n
'
%
new_interpreter
return
b'#! '
+
new_interpreter
+
b'
\
n
'
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment