Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8554e30

Browse files
committed
BuildApplet will now also update old applets
1 parent ebe914a commit 8554e30

2 files changed

Lines changed: 96 additions & 68 deletions

File tree

Mac/scripts/BuildApplet.py

Lines changed: 60 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,32 @@ def main():
6767
# Ask for source text if not specified in sys.argv[1:]
6868

6969
if not sys.argv[1:]:
70-
srcfss, ok = macfs.PromptGetFile('Select Python source file:', 'TEXT')
70+
srcfss, ok = macfs.PromptGetFile('Select Python source or applet:', 'TEXT', 'APPL')
7171
if not ok:
7272
return
7373
filename = srcfss.as_pathname()
7474
tp, tf = os.path.split(filename)
7575
if tf[-3:] == '.py':
7676
tf = tf[:-3]
7777
else:
78-
tf = tf + '.applet'
78+
tf = tf + '.out'
7979
dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
8080
if not ok: return
81-
process(template, filename, dstfss.as_pathname())
81+
dstfilename = dstfss.as_pathname()
82+
cr, tp = MacOS.GetCreatorAndType(filename)
83+
if tp == 'APPL':
84+
update(template, filename, dstfilename)
85+
else:
86+
process(template, filename, dstfilename)
8287
else:
8388

8489
# Loop over all files to be processed
8590
for filename in sys.argv[1:]:
86-
process(template, filename, '')
91+
cr, tp = MacOS.GetCreatorAndType(filename)
92+
if tp == 'APPL':
93+
update(template, filename, '')
94+
else:
95+
process(template, filename, '')
8796

8897
def process(template, filename, output):
8998

@@ -116,10 +125,23 @@ def process(template, filename, output):
116125

117126
if output:
118127
destname = output
128+
129+
process_common(template, progress, code, rsrcname, destname, 0)
130+
131+
def update(template, filename, output):
132+
if DEBUG:
133+
progress = EasyDialogs.ProgressBar("Updating %s..."%os.path.split(filename)[1], 120)
134+
else:
135+
progress = None
136+
if not output:
137+
output = filename + ' (updated)'
138+
process_common(template, progress, None, filename, output, 1)
139+
119140

141+
def process_common(template, progress, code, rsrcname, destname, is_update):
120142
# Try removing the output file
121143
try:
122-
os.unlink(output)
144+
os.unlink(destname)
123145
except os.error:
124146
pass
125147

@@ -163,7 +185,11 @@ def process(template, filename, output):
163185
if DEBUG:
164186
progress.inc(50)
165187
else:
166-
typesfound, ownertype = copyres(input, output, [], 0, progress)
188+
if is_update:
189+
skip_oldfile = ['cfrg']
190+
else:
191+
skip_oldfile = []
192+
typesfound, ownertype = copyres(input, output, skip_oldfile, 0, progress)
167193
CloseResFile(input)
168194

169195
# Check which resource-types we should not copy from the template
@@ -195,32 +221,33 @@ def process(template, filename, output):
195221

196222
UseResFile(output)
197223

198-
# Delete any existing 'PYC ' resource named __main__
199-
200-
try:
201-
res = Get1NamedResource(RESTYPE, RESNAME)
202-
res.RemoveResource()
203-
except Error:
204-
pass
205-
206-
# Create the raw data for the resource from the code object
207-
if DEBUG:
208-
progress.label("Write PYC resource...")
209-
progress.set(120)
210-
211-
data = marshal.dumps(code)
212-
del code
213-
data = (MAGIC + '\0\0\0\0') + data
214-
215-
# Create the resource and write it
224+
if code:
225+
# Delete any existing 'PYC ' resource named __main__
226+
227+
try:
228+
res = Get1NamedResource(RESTYPE, RESNAME)
229+
res.RemoveResource()
230+
except Error:
231+
pass
216232

217-
id = 0
218-
while id < 128:
219-
id = Unique1ID(RESTYPE)
220-
res = Resource(data)
221-
res.AddResource(RESTYPE, id, RESNAME)
222-
res.WriteResource()
223-
res.ReleaseResource()
233+
# Create the raw data for the resource from the code object
234+
if DEBUG:
235+
progress.label("Write PYC resource...")
236+
progress.set(120)
237+
238+
data = marshal.dumps(code)
239+
del code
240+
data = (MAGIC + '\0\0\0\0') + data
241+
242+
# Create the resource and write it
243+
244+
id = 0
245+
while id < 128:
246+
id = Unique1ID(RESTYPE)
247+
res = Resource(data)
248+
res.AddResource(RESTYPE, id, RESNAME)
249+
res.WriteResource()
250+
res.ReleaseResource()
224251

225252
# Close the output file
226253

@@ -252,8 +279,8 @@ def copyres(input, output, skiptypes, skipowner, progress=None):
252279
res = Get1IndResource(type, ires)
253280
id, type, name = res.GetResInfo()
254281
lcname = string.lower(name)
255-
if (type, lcname) == (RESTYPE, RESNAME):
256-
continue # Don't copy __main__ from template
282+
## if (type, lcname) == (RESTYPE, RESNAME):
283+
## continue # Don't copy __main__ from template
257284
# XXXX should look for id=0
258285
if lcname == OWNERNAME:
259286
if skipowner:

Mac/scripts/BuildApplet.rsrc.hqx

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
(This file must be converted with BinHex 4.0)
22

3-
:%%*eD@aN3A"`E'9d,R*cFQ-!FR0bBe*6483"!*!(#bSMM`#3"!%!!!!++3!!#5N
4-
!!!%"0K3J9#"S!"3J8(d4X'J4!$S"CbB5,`a1ZJ)-$$S!@RN0E@YKF("XCA3ZFR0
5-
bB`)!!!!rN!J!N!JrN!J!N"L`(eFK!*!'#bVr%F#SD3%G3"(rma0`!"!Zrr1pdK&
6-
Q%&%f[P9V!3&#4,fK[P9V!3%`86)"Caj%&3`!!"aP%R!!%#j$&3`!!"pL"R!"B!!
7-
"!3)X@P3Y,N5p!3!E2!&Q-#G92KT+J#"6!LJ![`!Z)J$Y#3)"!%#$+0Xd%kRA,`a
8-
1ZJ%*5QGV!3#Q9d-k!!!"!*!,3!!!!+!!!!&3!!!#U!!!"&3!!!NN!!!5P!!$rrm
9-
!"!!!J!2rr`!"!!)!!3!#!!%!!`!"!!2J!3!$)!%!!L!"!!)J!rrr,J3!!,i$rrm
10-
1!+`%!!'Z#!!"rK!!!"!J!!!)3!!!")!!!!-!N"K!!!!!i!!!!I!!!!2i!!!(r!!
11-
!$r`!!"rm!!2rr`!(rrq!!rrr!!(rrJ!"rri!!Irr!!(rrq!"rrmJ!Irq)!(rrL!
12-
$rrmZ"rrr[J2rr`i!rr`!!Iri!!(rm!!!(q!!!!r!!!!(J!!!!`#3%3T3i!!HK)!
13-
!"k%J!!!!"d&38%`!N!C!!!!"!!+!"8!)3$ri%"!3(K!5%"-rq`iJ$N!#J!%!N!8
14-
"!!1!"m!2`$ri(r!IrKrb(r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