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

Skip to content

Commit 207b4c2

Browse files
Merged revisions 70727 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r70727 | ronald.oussoren | 2009-03-30 12:15:29 -0500 (Mon, 30 Mar 2009) | 5 lines * Updates installed dependencies to latest releaases (bzip, zlib, ...) * Changes code for updating folder icons from Python code that uses the deprecated Carbon module to a much simpler Cocoa program in Objective-C ........
1 parent 7af4ef8 commit 207b4c2

2 files changed

Lines changed: 64 additions & 109 deletions

File tree

Mac/BuildScript/build-installer.py

Lines changed: 38 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python2.3
1+
#!/usr/bin/python
22
"""
33
This script is used to build the "official unofficial" universal build on
44
Mac OS X. It requires Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK to do its
@@ -18,11 +18,6 @@
1818
from plistlib import Plist
1919

2020
import MacOS
21-
import Carbon.File
22-
import Carbon.Icn
23-
import Carbon.Res
24-
from Carbon.Files import kCustomIconResource, fsRdWrPerm, kHasCustomIcon
25-
from Carbon.Files import kFSCatInfoFinderInfo
2621

2722
try:
2823
from plistlib import writePlist
@@ -94,8 +89,9 @@ def getFullVersion():
9489
# batteries included python.
9590
LIBRARY_RECIPES = [
9691
dict(
97-
name="Bzip2 1.0.3",
98-
url="http://www.bzip.org/1.0.3/bzip2-1.0.3.tar.gz",
92+
name="Bzip2 1.0.4",
93+
url="http://www.bzip.org/1.0.4/bzip2-1.0.4.tar.gz",
94+
checksum='fc310b254f6ba5fbb5da018f04533688',
9995
configure=None,
10096
install='make install PREFIX=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%(
10197
shellQuote(os.path.join(WORKDIR, 'libraries')),
@@ -106,6 +102,7 @@ def getFullVersion():
106102
dict(
107103
name="ZLib 1.2.3",
108104
url="http://www.gzip.org/zlib/zlib-1.2.3.tar.gz",
105+
checksum='debc62758716a169df9f62e6ab2bc634',
109106
configure=None,
110107
install='make install prefix=%s/usr/local/ CFLAGS="-arch %s -isysroot %s"'%(
111108
shellQuote(os.path.join(WORKDIR, 'libraries')),
@@ -117,6 +114,7 @@ def getFullVersion():
117114
# Note that GNU readline is GPL'd software
118115
name="GNU Readline 5.1.4",
119116
url="http://ftp.gnu.org/pub/gnu/readline/readline-5.1.tar.gz" ,
117+
checksum='7ee5a692db88b30ca48927a13fd60e46',
120118
patchlevel='0',
121119
patches=[
122120
# The readline maintainers don't do actual micro releases, but
@@ -129,9 +127,9 @@ def getFullVersion():
129127
),
130128

131129
dict(
132-
name="SQLite 3.6.3",
133-
url="http://www.sqlite.org/sqlite-3.6.3.tar.gz",
134-
checksum='93f742986e8bc2dfa34792e16df017a6feccf3a2',
130+
name="SQLite 3.6.11",
131+
url="http://www.sqlite.org/sqlite-3.6.11.tar.gz",
132+
checksum='7ebb099696ab76cc6ff65dd496d17858',
135133
configure_pre=[
136134
'--enable-threadsafe',
137135
'--enable-tempstore',
@@ -144,6 +142,7 @@ def getFullVersion():
144142
dict(
145143
name="NCurses 5.5",
146144
url="http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.5.tar.gz",
145+
checksum='e73c1ac10b4bfc46db43b2ddfd6244ef',
147146
configure_pre=[
148147
"--without-cxx",
149148
"--without-ada",
@@ -573,31 +572,21 @@ def buildLibraries():
573572

574573

575574
def buildPythonDocs():
576-
# This stores the documentation as Resources/English.lproj/Docuentation
575+
# This stores the documentation as Resources/English.lproj/Documentation
577576
# inside the framwork. pydoc and IDLE will pick it up there.
578577
print "Install python documentation"
579578
rootDir = os.path.join(WORKDIR, '_root')
580-
version = getVersion()
579+
buildDir = os.path.join('../../Doc')
581580
docdir = os.path.join(rootDir, 'pydocs')
582-
583-
novername = 'python-docs-html.tar.bz2'
584-
name = 'html-%s.tar.bz2'%(getFullVersion(),)
585-
sourceArchive = os.path.join(DEPSRC, name)
586-
if os.path.exists(sourceArchive):
587-
print "Using local copy of %s"%(name,)
588-
589-
else:
590-
print "Downloading %s"%(novername,)
591-
downloadURL('http://www.python.org/ftp/python/doc/%s/%s'%(
592-
getFullVersion(), novername), sourceArchive)
593-
print "Archive for %s stored as %s"%(name, sourceArchive)
594-
595-
extractArchive(os.path.dirname(docdir), sourceArchive)
596-
597-
os.rename(
598-
os.path.join(
599-
os.path.dirname(docdir), 'python-docs-html'),
600-
docdir)
581+
curDir = os.getcwd()
582+
os.chdir(buildDir)
583+
runCommand('make update')
584+
runCommand('make html')
585+
os.chdir(curDir)
586+
if not os.path.exists(docdir):
587+
os.mkdir(docdir)
588+
os.rename(os.path.join(buildDir, 'build', 'html'),
589+
os.path.join(docdir, 'python-docs-html'))
601590

602591

603592
def buildPython():
@@ -937,82 +926,20 @@ def buildDMG():
937926
def setIcon(filePath, icnsPath):
938927
"""
939928
Set the custom icon for the specified file or directory.
940-
941-
For a directory the icon data is written in a file named 'Icon\r' inside
942-
the directory. For both files and directories write the icon as an 'icns'
943-
resource. Furthermore set kHasCustomIcon in the finder flags for filePath.
944929
"""
945-
ref, isDirectory = Carbon.File.FSPathMakeRef(icnsPath)
946-
icon = Carbon.Icn.ReadIconFile(ref)
947-
del ref
948-
949-
#
950-
# Open the resource fork of the target, to add the icon later on.
951-
# For directories we use the file 'Icon\r' inside the directory.
952-
#
953-
954-
ref, isDirectory = Carbon.File.FSPathMakeRef(filePath)
955-
956-
if isDirectory:
957-
# There is a problem with getting this into the pax(1) archive,
958-
# just ignore directory icons for now.
959-
return
960-
961-
tmpPath = os.path.join(filePath, "Icon\r")
962-
if not os.path.exists(tmpPath):
963-
fp = open(tmpPath, 'w')
964-
fp.close()
965930

966-
tmpRef, _ = Carbon.File.FSPathMakeRef(tmpPath)
967-
spec = Carbon.File.FSSpec(tmpRef)
931+
toolPath = os.path.join(os.path.dirname(__file__), "seticon.app/Contents/MacOS/seticon")
932+
dirPath = os.path.dirname(__file__)
933+
if not os.path.exists(toolPath) or os.stat(toolPath).st_mtime < os.stat(dirPath + '/seticon.m').st_mtime:
934+
# NOTE: The tool is created inside an .app bundle, otherwise it won't work due
935+
# to connections to the window server.
936+
if not os.path.exists('seticon.app/Contents/MacOS'):
937+
os.makedirs('seticon.app/Contents/MacOS')
938+
runCommand("cc -o %s %s/seticon.m -framework Cocoa"%(
939+
shellQuote(toolPath), shellQuote(dirPath)))
968940

969-
else:
970-
spec = Carbon.File.FSSpec(ref)
971-
972-
try:
973-
Carbon.Res.HCreateResFile(*spec.as_tuple())
974-
except MacOS.Error:
975-
pass
976-
977-
# Try to create the resource fork again, this will avoid problems
978-
# when adding an icon to a directory. I have no idea why this helps,
979-
# but without this adding the icon to a directory will fail sometimes.
980-
try:
981-
Carbon.Res.HCreateResFile(*spec.as_tuple())
982-
except MacOS.Error:
983-
pass
984-
985-
refNum = Carbon.Res.FSpOpenResFile(spec, fsRdWrPerm)
986-
987-
Carbon.Res.UseResFile(refNum)
988-
989-
# Check if there already is an icon, remove it if there is.
990-
try:
991-
h = Carbon.Res.Get1Resource('icns', kCustomIconResource)
992-
except MacOS.Error:
993-
pass
994-
995-
else:
996-
h.RemoveResource()
997-
del h
998-
999-
# Add the icon to the resource for of the target
1000-
res = Carbon.Res.Resource(icon)
1001-
res.AddResource('icns', kCustomIconResource, '')
1002-
res.WriteResource()
1003-
res.DetachResource()
1004-
Carbon.Res.CloseResFile(refNum)
1005-
1006-
# And now set the kHasCustomIcon property for the target. Annoyingly,
1007-
# python doesn't seem to have bindings for the API that is needed for
1008-
# this. Cop out and call SetFile
1009-
os.system("/Developer/Tools/SetFile -a C %s"%(
1010-
shellQuote(filePath),))
1011-
1012-
if isDirectory:
1013-
os.system('/Developer/Tools/SetFile -a V %s'%(
1014-
shellQuote(tmpPath),
1015-
))
941+
runCommand("%s %s %s"%(shellQuote(os.path.abspath(toolPath)), shellQuote(icnsPath),
942+
shellQuote(filePath)))
1016943

1017944
def main():
1018945
# First parse options and check if we can perform our work
@@ -1056,10 +983,12 @@ def main():
1056983
fp.close()
1057984

1058985
# Custom icon for the DMG, shown when the DMG is mounted.
1059-
shutil.copy("../Icons/Disk Image.icns",
1060-
os.path.join(WORKDIR, "installer", ".VolumeIcon.icns"))
1061-
os.system("/Developer/Tools/SetFile -a C %s"%(
1062-
os.path.join(WORKDIR, "installer", ".VolumeIcon.icns")))
986+
# XXX: Code is diabled because it doesn't actually work :-(
987+
# shutil.copy("../Icons/Disk Image.icns",
988+
# os.path.join(WORKDIR, "installer", ".VolumeIcon.icns"))
989+
# os.system("/Developer/Tools/SetFile -a C %s"%(
990+
# os.path.join(WORKDIR, "installer", ".VolumeIcon.icns")))
991+
setIcon(os.path.join(WORKDIR, "installer"), "../Icons/Disk Image.icns")
1063992

1064993

1065994
# And copy it to a DMG

Mac/BuildScript/seticon.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Simple tool for setting an icon on a file.
3+
*/
4+
#import <Cocoa/Cocoa.h>
5+
#include <stdio.h>
6+
7+
int main(int argc, char** argv)
8+
{
9+
if (argc != 3) {
10+
fprintf(stderr, "Usage: seticon ICON TARGET");
11+
return 1;
12+
}
13+
14+
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
15+
NSString* iconPath = [NSString stringWithUTF8String:argv[1]];
16+
NSString* filePath = [NSString stringWithUTF8String:argv[2]];
17+
18+
[NSApplication sharedApplication];
19+
20+
[[NSWorkspace sharedWorkspace]
21+
setIcon: [[NSImage alloc] initWithContentsOfFile: iconPath]
22+
forFile: filePath
23+
options: 0];
24+
[pool release];
25+
return 0;
26+
}

0 commit comments

Comments
 (0)