FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Tools/scripts/mkreal.py at master · python-emscripten/cpython · GitHub
python-emscripten
cpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Tools
/
scripts
/
mkreal.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
65 lines (56 loc) · 1.59 KB
Breadcrumbs
cpython
/
Tools
/
scripts
/
mkreal.py
Copy path
File metadata and controls
executable file
·
65 lines (56 loc) · 1.59 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env python3
# mkreal
#
# turn a symlink to a directory into a real directory
import
sys
import
os
from
stat
import
*
join
=
os
.
path
.
join
error
=
'mkreal error'
BUFSIZE
=
32
*
1024
def
mkrealfile
(
name
):
st
=
os
.
stat
(
name
)
# Get the mode
mode
=
S_IMODE
(
st
[
ST_MODE
])
linkto
=
os
.
readlink
(
name
)
# Make sure again it's a symlink
with
open
(
name
,
'rb'
)
as
f_in
:
# This ensures it's a file
os
.
unlink
(
name
)
with
open
(
name
,
'wb'
)
as
f_out
:
while
1
:
buf
=
f_in
.
read
(
BUFSIZE
)
if
not
buf
:
break
f_out
.
write
(
buf
)
os
.
chmod
(
name
,
mode
)
def
mkrealdir
(
name
):
st
=
os
.
stat
(
name
)
# Get the mode
mode
=
S_IMODE
(
st
[
ST_MODE
])
linkto
=
os
.
readlink
(
name
)
files
=
os
.
listdir
(
name
)
os
.
unlink
(
name
)
os
.
mkdir
(
name
,
mode
)
os
.
chmod
(
name
,
mode
)
linkto
=
join
(
os
.
pardir
,
linkto
)
#
for
filename
in
files
:
if
filename
not
in
(
os
.
curdir
,
os
.
pardir
):
os
.
symlink
(
join
(
linkto
,
filename
),
join
(
name
,
filename
))
def
main
():
sys
.
stdout
=
sys
.
stderr
progname
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
if
progname
==
'-c'
:
progname
=
'mkreal'
args
=
sys
.
argv
[
1
:]
if
not
args
:
print
(
'usage:'
,
progname
,
'path ...'
)
sys
.
exit
(
2
)
status
=
0
for
name
in
args
:
if
not
os
.
path
.
islink
(
name
):
print
(
progname
+
':'
,
name
+
':'
,
'not a symlink'
)
status
=
1
else
:
if
os
.
path
.
isdir
(
name
):
mkrealdir
(
name
)
else
:
mkrealfile
(
name
)
sys
.
exit
(
status
)
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL