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
eaa1959c
Commit
eaa1959c
authored
May 31, 1996
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use py_resource module
parent
0acb7f7a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
46 deletions
+10
-46
Mac/scripts/PackLibDir.py
Mac/scripts/PackLibDir.py
+10
-46
No files found.
Mac/scripts/PackLibDir.py
View file @
eaa1959c
...
...
@@ -6,69 +6,33 @@ from Resources import *
import
os
import
macfs
import
sys
READ
=
1
WRITE
=
2
smAllScripts
=
-
3
import
py_resource
error
=
'mkpycresourcefile.error'
def
Pstring
(
str
):
if
len
(
str
)
>
255
:
raise
ValueError
,
'String too large'
return
chr
(
len
(
str
))
+
str
def
createoutput
(
dst
):
"""Create output file. Return handle and first id to use."""
FSpCreateResFile
(
dst
,
'Pyth'
,
'rsrc'
,
smAllScripts
)
output
=
FSpOpenResFile
(
dst
,
WRITE
)
UseResFile
(
output
)
num
=
128
return
output
,
num
def
writemodule
(
name
,
id
,
data
):
"""Write pyc code to a PYC resource with given name and id."""
# XXXX Check that it doesn't exist
res
=
Resource
(
data
)
res
.
AddResource
(
'PYC '
,
id
,
name
)
res
.
WriteResource
()
res
.
ReleaseResource
()
def
mkpycresourcefile
(
src
,
dst
):
"""Copy pyc file/dir src to resource file dst."""
if
not
os
.
path
.
isdir
(
src
)
and
src
[
-
4
:]
<>
'.pyc'
:
raise
error
,
'I can only handle .pyc files or directories'
handle
,
oid
=
createoutput
(
dst
)
fsid
=
py_resource
.
create
(
dst
)
if
os
.
path
.
isdir
(
src
):
id
=
handlesubdir
(
handle
,
oid
,
src
)
handlesubdir
(
src
)
else
:
id
=
handleonepycfile
(
handle
,
oid
,
src
)
print
'Wrote'
,
id
-
oid
,
'PYC resources to'
,
dst
CloseResFile
(
handle
)
id
,
name
=
py_resource
.
frompycfile
(
src
)
print
'Wrote %d: %s %s'
%
(
id
,
name
,
src
)
CloseResFile
(
fsid
)
def
handleonepycfile
(
handle
,
id
,
file
):
"""Copy one pyc file to the open resource file"""
d
,
name
=
os
.
path
.
split
(
file
)
name
=
name
[:
-
4
]
print
' module'
,
name
writemodule
(
name
,
id
,
open
(
file
,
'rb'
).
read
())
return
id
+
1
def
handlesubdir
(
handle
,
id
,
srcdir
):
def
handlesubdir
(
srcdir
):
"""Recursively scan a directory for pyc files and copy to resources"""
print
'Directory'
,
srcdir
src
=
os
.
listdir
(
srcdir
)
for
file
in
src
:
file
=
os
.
path
.
join
(
srcdir
,
file
)
if
os
.
path
.
isdir
(
file
):
id
=
handlesubdir
(
handle
,
id
,
file
)
handlesubdir
(
file
)
elif
file
[
-
4
:]
==
'.pyc'
:
id
=
handleonepycfile
(
handle
,
id
,
file
)
return
id
id
,
name
=
py_resource
.
frompycfile
(
file
)
print
'Wrote %d: %s %s'
%
(
id
,
name
,
file
)
if
__name__
==
'__main__'
:
args
=
sys
.
argv
[
1
:]
...
...
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