Difference between revisions of "Python"

From AwkwardTV
Jump to: navigation, search
m (added missing space in cd after mount)
m (added instructions link to mount read write and that you require gunzip on your TV)
Line 2: Line 2:
 
Source: '''Michael Hanney'''  http://michaelhanney.com/blog/2008/03/27/how-to-install-python-on-apple-tv/
 
Source: '''Michael Hanney'''  http://michaelhanney.com/blog/2008/03/27/how-to-install-python-on-apple-tv/
  
 +
You will need to [[Mount ReadWrite]] the system disk /dev/disk0s4 to make this work and also requires that you have gunzip on your TV
  
 
Download the Universal Python 2.5 (Mac OS X 10.3.9 and later, Intel or PPC) package
 
Download the Universal Python 2.5 (Mac OS X 10.3.9 and later, Intel or PPC) package

Revision as of 02:35, 19 September 2008

How to Install Python 2.5 on Apple TV

Source: Michael Hanney http://michaelhanney.com/blog/2008/03/27/how-to-install-python-on-apple-tv/

You will need to Mount ReadWrite the system disk /dev/disk0s4 to make this work and also requires that you have gunzip on your TV

Download the Universal Python 2.5 (Mac OS X 10.3.9 and later, Intel or PPC) package

http://www.pythonmac.org/packages/py25-fat/dmg/python-2.5-macosx.dmg

Copy the dmg to the Apple TV that already has ssh enabled. Use the -1 (one) argument to scp to use SSH version 1.


 scp -1 http://www.pythonmac.org/packages/py25-fat/dmg/python-2.5-macosx.dmg frontrow@192.168.1.202:Documents/python-2.5-macosx.dmg  

Log in to the Apple TV over SSH, also uses the -1 argument to use SSH version 1. (The IP address of my Apple TV is 192.168.1.202, obviously your may be different).


 ssh -1 frontrow@192.168.1.202  


Change directory to Documents


 cd Documents  


Make a directory into which we will extract the Python.framework package files from the installer dmg


 mkdir Python.framework

Mount the disk image


 sudo hdiutil mount python-2.5-macosx.dmg  

We want to install just the Python.framework

“This package installs Python.framework, that is the python interpreter and the standard library. This also includes Python wrappers for lots of Mac OS X API’s.”

Change directory to the mount location and take a look around at the contents


 cd /Volumes/Univeral\ MacPython\ 2.5/MacPython.mpkg/Contents/Packages/PythonFramework-2.5.pkg/Contents  

Copy all of the Contents directory to our ~/Documents/Python.framework directory


 cp -r * ~/Documents/Python.framework/

Unmount the .dmg disk image


 sudo hdiutil unmount /Volumes/Univeral\ MacPython\ 2.5

Prepare to manually move (or copy) the contents of the installer to the default locations on the Apple TV


 cd ~/Documents/Python.framework/  

Unzip the entire gzipped archive


 gunzip Archive.pax.gz

Extract the contents of the pax archive. (I am not familiar with pax yet, but I guess it is like a tar)

 pax -r -f Archive.pax  

Delete the .pax file now that we have extracted everything from it.

 rm -rf Archive.pax  

So where do we install the archive contents? We see from the Info.plist that the default installation destination is /Library/Frameworks/Python.framework


 <key>IFPkgFlagDefaultLocation</key>   
 <string>/Library/Frameworks/Python.framework</string>  

Let’s manually create that directory and start moving files


 mkdir /Library/Frameworks/Python.framework   
 mv Versions /Library/Frameworks/Python.framework  

Let’s recreate those symbolic links in the installation directory


 cd /Library/Frameworks/Python.framework   
 
 ln -s Versions/Current/Headers Headers   
 ln -s Versions/Current/Python Python   
 ln -s Versions/Current/Resources Resources  

The python runtime executable is at /Library/Frameworks/Python.framework/Versions/Current/bin/python. We want to leave it there. All we need to do now is create the symbolic link in /usr/bin


 sudo ln -s /Library/Frameworks/Python.framework/Versions/Current/bin/python /usr/bin/python  


Testing it out

We haven’t visited the Resources directory yet. I’m not entirely sure how the OS X installer would have used this, if at all, but there is a shell script called postflight in /Resources/ that recompiles the .py files library we just installed. It looks important so I’m going to execute it. First I’m going to change to that directory.


 cd /Library/Frameworks/Python.framework/Versions/Current/Resources  


Before we run the postflight shell script, we’ll edit the lines that change the ownership of the installation to admin, to root:admin because there is no admin user on the Apple TV. Instead, we will chown the installation to ‘root:admin’

At this point I remember I have not yet found a text editor on the Apple TV. No problem, we can use sed, the stream editor to replace ‘admin’ to ‘root:admin’ and save the result to a new file called postflight.root. Isn’t it great that Apple TV is a unix system!

 cd ~/Documents/Python.framework/Resources
 sed s/admin/root:admin/ < postflight > postflight.root  


Now lets execute postflight.root and watch how quickly the AppleTV complies python source code.


 sudo sh ./postflight.root