FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Tools/scripts/update_file.py at tkinter_docs · native-api/cpython · GitHub
native-api
cpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Tools
/
scripts
/
update_file.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (22 loc) · 762 Bytes
Breadcrumbs
cpython
/
Tools
/
scripts
/
update_file.py
Copy path
File metadata and controls
28 lines (22 loc) · 762 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
A script that replaces an old file with a new one, only if the contents
actually changed. If not, the new file is simply deleted.
This avoids wholesale rebuilds when a code (re)generation phase does not
actually change the in-tree generated code.
"""
import
os
import
sys
def
main
(
old_path
,
new_path
):
with
open
(
old_path
,
'rb'
)
as
f
:
old_contents
=
f
.
read
()
with
open
(
new_path
,
'rb'
)
as
f
:
new_contents
=
f
.
read
()
if
old_contents
!=
new_contents
:
os
.
replace
(
new_path
,
old_path
)
else
:
os
.
unlink
(
new_path
)
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
!=
3
:
print
(
"Usage: %s <path to be updated> <path with new contents>"
%
(
sys
.
argv
[
0
],))
sys
.
exit
(
1
)
main
(
sys
.
argv
[
1
],
sys
.
argv
[
2
])
Back
|
FazBrowse Home
|
New Git URL