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
f88a077f
Commit
f88a077f
authored
Feb 17, 2008
by
Facundo Batista
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now we handle different the backup copy, because of security
issues regarding user/group and permissions. Fixes 1050828.
parent
27cca3cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
16 deletions
+29
-16
Misc/NEWS
Misc/NEWS
+5
-0
Tools/scripts/reindent.py
Tools/scripts/reindent.py
+24
-16
No files found.
Misc/NEWS
View file @
f88a077f
...
@@ -1378,6 +1378,11 @@ Tests
...
@@ -1378,6 +1378,11 @@ Tests
Tools
Tools
-----
-----
- Tools/scripts/reindent.py now creates the backup file using shutil.copy
to preserve user/group and permissions. Added also a --nobackup option
to not create the backup if the user is concerned regarding this. Check
issue 1050828 for more details.
- Tools/scripts/win_add2path.py was added. The simple script modifes the
- Tools/scripts/win_add2path.py was added. The simple script modifes the
PATH environment var of the HKCU tree and adds the python bin and script
PATH environment var of the HKCU tree and adds the python bin and script
directory.
directory.
...
...
Tools/scripts/reindent.py
View file @
f88a077f
...
@@ -4,10 +4,11 @@
...
@@ -4,10 +4,11 @@
"""reindent [-d][-r][-v] [ path ... ]
"""reindent [-d][-r][-v] [ path ... ]
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
-r (--recurse) Recurse. Search for all .py files in subdirectories too.
-r (--recurse) Recurse. Search for all .py files in subdirectories too.
-v (--verbose) Verbose. Print informative msgs; else no output.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-h (--help) Help. Print this usage information and exit.
-v (--verbose) Verbose. Print informative msgs; else no output.
-h (--help) Help. Print this usage information and exit.
Change Python (.py) files to use 4-space indents and no hard tab characters.
Change Python (.py) files to use 4-space indents and no hard tab characters.
Also trim excess spaces and tabs from ends of lines, and remove empty lines
Also trim excess spaces and tabs from ends of lines, and remove empty lines
...
@@ -31,17 +32,23 @@ resulting .py file won't change it again).
...
@@ -31,17 +32,23 @@ resulting .py file won't change it again).
The hard part of reindenting is figuring out what to do with comment
The hard part of reindenting is figuring out what to do with comment
lines. So long as the input files get a clean bill of health from
lines. So long as the input files get a clean bill of health from
tabnanny.py, reindent should do a good job.
tabnanny.py, reindent should do a good job.
The backup file is a copy of the one that is being reindented. The ".bak"
file is generated with shutil.copy(), but some corner cases regarding
user/group and permissions could leave the backup file more readable that
you'd prefer. You can always use the --nobackup option to prevent this.
"""
"""
__version__
=
"1"
__version__
=
"1"
import
tokenize
import
tokenize
import
os
import
os
,
shutil
import
sys
import
sys
verbose
=
0
verbose
=
0
recurse
=
0
recurse
=
0
dryrun
=
0
dryrun
=
0
makebackup
=
True
def
usage
(
msg
=
None
):
def
usage
(
msg
=
None
):
if
msg
is
not
None
:
if
msg
is
not
None
:
...
@@ -57,10 +64,10 @@ def errprint(*args):
...
@@ -57,10 +64,10 @@ def errprint(*args):
def
main
():
def
main
():
import
getopt
import
getopt
global
verbose
,
recurse
,
dryrun
global
verbose
,
recurse
,
dryrun
,
makebackup
try
:
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"drvh"
,
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"dr
n
vh"
,
[
"dryrun"
,
"recurse
"
,
"verbose"
,
"help"
])
[
"dryrun"
,
"recurse"
,
"nobackup
"
,
"verbose"
,
"help"
])
except
getopt
.
error
,
msg
:
except
getopt
.
error
,
msg
:
usage
(
msg
)
usage
(
msg
)
return
return
...
@@ -69,6 +76,8 @@ def main():
...
@@ -69,6 +76,8 @@ def main():
dryrun
+=
1
dryrun
+=
1
elif
o
in
(
'-r'
,
'--recurse'
):
elif
o
in
(
'-r'
,
'--recurse'
):
recurse
+=
1
recurse
+=
1
elif
o
in
(
'-n'
,
'--nobackup'
):
makebackup
=
False
elif
o
in
(
'-v'
,
'--verbose'
):
elif
o
in
(
'-v'
,
'--verbose'
):
verbose
+=
1
verbose
+=
1
elif
o
in
(
'-h'
,
'--help'
):
elif
o
in
(
'-h'
,
'--help'
):
...
@@ -112,11 +121,10 @@ def check(file):
...
@@ -112,11 +121,10 @@ def check(file):
print
"But this is a dry run, so leaving it alone."
print
"But this is a dry run, so leaving it alone."
if
not
dryrun
:
if
not
dryrun
:
bak
=
file
+
".bak"
bak
=
file
+
".bak"
if
os
.
path
.
exists
(
bak
):
if
makebackup
:
os
.
remove
(
bak
)
shutil
.
copyfile
(
file
,
bak
)
os
.
rename
(
file
,
bak
)
if
verbose
:
if
verbose
:
print
"backed up"
,
file
,
"to"
,
bak
print
"renamed"
,
file
,
"to"
,
bak
f
=
open
(
file
,
"w"
)
f
=
open
(
file
,
"w"
)
r
.
write
(
f
)
r
.
write
(
f
)
f
.
close
()
f
.
close
()
...
...
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