mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
get creator from Owner resource; set attrs
This commit is contained in:
parent
2e1db7756f
commit
83c434b145
1 changed files with 24 additions and 7 deletions
|
|
@ -27,6 +27,9 @@ TEMPLATE = "PythonApplet"
|
||||||
RESTYPE = 'PYC '
|
RESTYPE = 'PYC '
|
||||||
RESNAME = '__main__'
|
RESNAME = '__main__'
|
||||||
|
|
||||||
|
# A resource with this name sets the "owner" (creator) of the destination
|
||||||
|
OWNERNAME = "owner resource"
|
||||||
|
|
||||||
# OpenResFile mode parameters
|
# OpenResFile mode parameters
|
||||||
READ = 1
|
READ = 1
|
||||||
WRITE = 2
|
WRITE = 2
|
||||||
|
|
@ -107,7 +110,6 @@ def process(template, filename):
|
||||||
ctor, type = MacOS.GetCreatorAndType(destname)
|
ctor, type = MacOS.GetCreatorAndType(destname)
|
||||||
if type in undefs: type = 'APPL'
|
if type in undefs: type = 'APPL'
|
||||||
if ctor in undefs: ctor = tctor
|
if ctor in undefs: ctor = tctor
|
||||||
MacOS.SetCreatorAndType(destname, ctor, type)
|
|
||||||
|
|
||||||
# Open the output resource fork
|
# Open the output resource fork
|
||||||
|
|
||||||
|
|
@ -121,8 +123,9 @@ def process(template, filename):
|
||||||
# Copy the resources from the template
|
# Copy the resources from the template
|
||||||
|
|
||||||
input = FSpOpenResFile(template, READ)
|
input = FSpOpenResFile(template, READ)
|
||||||
copyres(input, output)
|
newctor = copyres(input, output)
|
||||||
CloseResFile(input)
|
CloseResFile(input)
|
||||||
|
if newctor: ctor = newctor
|
||||||
|
|
||||||
# Copy the resources from the target specific resource template, if any
|
# Copy the resources from the target specific resource template, if any
|
||||||
|
|
||||||
|
|
@ -131,8 +134,13 @@ def process(template, filename):
|
||||||
except MacOS.Error:
|
except MacOS.Error:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
copyres(input, output)
|
newctor = copyres(input, output)
|
||||||
CloseResFile(input)
|
CloseResFile(input)
|
||||||
|
if newctor: ctor = newctor
|
||||||
|
|
||||||
|
# Now set the creator and type of the destination
|
||||||
|
|
||||||
|
MacOS.SetCreatorAndType(destname, ctor, type)
|
||||||
|
|
||||||
# Make sure we're manipulating the output resource file now
|
# Make sure we're manipulating the output resource file now
|
||||||
|
|
||||||
|
|
@ -171,10 +179,13 @@ def process(template, filename):
|
||||||
message("Applet %s created." % `destname`)
|
message("Applet %s created." % `destname`)
|
||||||
|
|
||||||
|
|
||||||
# Copy resources between two resource file descriptors
|
# Copy resources between two resource file descriptors.
|
||||||
# Exception: don't copy a __main__ resource
|
# Exception: don't copy a __main__ resource.
|
||||||
|
# If a resource's name is "owner resource", its type is returned
|
||||||
|
# (so the caller can use it to set the destination's creator)
|
||||||
|
|
||||||
def copyres(input, output):
|
def copyres(input, output):
|
||||||
|
ctor = None
|
||||||
UseResFile(input)
|
UseResFile(input)
|
||||||
ntypes = Count1Types()
|
ntypes = Count1Types()
|
||||||
for itype in range(1, 1+ntypes):
|
for itype in range(1, 1+ntypes):
|
||||||
|
|
@ -183,8 +194,10 @@ def copyres(input, output):
|
||||||
for ires in range(1, 1+nresources):
|
for ires in range(1, 1+nresources):
|
||||||
res = Get1IndResource(type, ires)
|
res = Get1IndResource(type, ires)
|
||||||
id, type, name = res.GetResInfo()
|
id, type, name = res.GetResInfo()
|
||||||
if (type, name) == (RESTYPE, RESNAME):
|
lcname = string.lower(name)
|
||||||
|
if (type, lcname) == (RESTYPE, RESNAME):
|
||||||
continue # Don't copy __main__ from template
|
continue # Don't copy __main__ from template
|
||||||
|
if lcname == OWNERNAME: ctor = type
|
||||||
size = res.SizeResource()
|
size = res.SizeResource()
|
||||||
attrs = res.GetResAttrs()
|
attrs = res.GetResAttrs()
|
||||||
print id, type, name, size, hex(attrs)
|
print id, type, name, size, hex(attrs)
|
||||||
|
|
@ -199,9 +212,12 @@ def copyres(input, output):
|
||||||
print "Overwriting..."
|
print "Overwriting..."
|
||||||
res2.RmveResource()
|
res2.RmveResource()
|
||||||
res.AddResource(type, id, name)
|
res.AddResource(type, id, name)
|
||||||
#res.SetResAttrs(attrs)
|
|
||||||
res.WriteResource()
|
res.WriteResource()
|
||||||
|
attrs = attrs | res.GetResAttrs()
|
||||||
|
print "New attrs =", hex(attrs)
|
||||||
|
res.SetResAttrs(attrs)
|
||||||
UseResFile(input)
|
UseResFile(input)
|
||||||
|
return ctor
|
||||||
|
|
||||||
|
|
||||||
# Show a message and exit
|
# Show a message and exit
|
||||||
|
|
@ -230,3 +246,4 @@ def message(str, id = 256):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue