Tutorial 2: Downloads (screencast with audio commentary)
Zero Install tutorial part 2: Downloads
In the first part of this tutorial we saw to how create launchers for Zero Install programs, such as a menu item in the GNOME Applications menu, or a shell command. A launcher turns a simple gesture, such as clicking on "Edit" or typing "rox" in a shell, into an invocation of 0launch, such as:
0launch http://rox.sourceforge.net/2005/interfaces/Edit
In this part we'll look at what happens next.
There are three steps to the process. First, we choose a version of the program, and a version of each library it requires (for example, Edit 2.0 and ROX-Lib 2.0.3). Next, we download each chosen version (if we don't have it already). Finally, we run the program.
Contents
Choosing versions
Where can we find out what versions are available? There are several possibilities, but by default 0launch tries using the program's name as a web address, downloading http://rox.sourceforge.net/2005/interfaces/Edit in our example.
If you view this page in your browser, you'll see what looks like a normal web-page. The page lists the available versions of Edit and provides download links. However, if you look at the source (right click and choose View Page Source in Firefox) you'll see that it's not the usual HTML. Instead, it's a dialect of XML specialised for describing software. Normally, a program author would describe their program using HTML, like this:
<p>Version 2.0 is the current stable version. It was released on 2005-09-21. Edit requires the <a href="http://rox.sourceforge.net/2005/interfaces/ROX-Lib">ROX-Lib</a> library.</p>
A Zero Install feed provides the same information, but in a machine-readable form, e.g.:
<implementation released="2005-09-21" stability="stable" version="2.0">... <requires interface="http://rox.sourceforge.net/2005/interfaces/ROX-Lib">...
0launch is therefore able to understand this information and choose appropriate versions:
To avoid having to re-download the Edit and ROX-Lib feeds every time you want to run Edit, 0launch stores copies of them in your ~/.cache/0install.net/interfaces directory. If you delete one of the cached feeds from this directory and try to run Edit again, it will have to download the feed again first.
Changing which versions are selected is covered in part three of this tutorial.
Downloading the chosen versions
Each implementation (version) listed in the feed file also says where it can be downloaded, and gives its identity (a secure checksum to verify that it hasn't been modified in any way). For example, ROX-Lib's feed contains these lines:
<implementation id="sha1new=9c116df3689d60df58925a7c634064ac2394f696" released="2007-11-09" version="2.0.5">
<archive extract="rox-lib2-2.0.5" href="http://osdn.dl.sourceforge.net/sourceforge/rox/rox-lib2-2.0.5.tar.bz2" size="139670"/>
</implementation>
When you click on the Download or Run button, 0launch downloads the selected versions. Each package is unpacked into its own directory. If you enabled sharing, they go in /var/cache/0install.net/implementations. Otherwise, you'll find them in your home directory, under ~/.cache/0install.net/implementations.
For example, if you downloaded ROX-Lib 2.0.5 when running Edit, then you'll find all its files in the directory .../0install.net/implementations/sha1new=9c116df3689d60df58925a7c634064ac2394f696.
No files are placed anywhere except in the cache during installation. As with the feed, if you delete this directory and then try to run Edit, you'll just be prompted to download it again.
Running the chosen versions
Traditional installation systems mix the files from all installed packages together in shared directories (e.g. /usr/lib). Programs look in these common directories to find their libraries. This can cause conflicts if different packages provide different files with the same name.
In Zero Install, programs don't get their libraries from fixed locations like /usr/lib. Instead, 0launch explicitly tells them where their libraries are. In our example, 0launch puts the location of the chosen version of ROX-Lib in the PYTHONPATH environment variable and then runs Edit. You can see this process by running 0launch in verbose mode like this:
$ 0launch --verbose http://rox.sourceforge.net/2005/interfaces/Edit INFO:root:PYTHONPATH=/var/cache/0install.net/implementations/sha1new=9c116df3689d60df58925a7c634064ac2394f696/ROX-Lib2/python INFO:root:Executing: /home/talex/.cache/0install.net/implementations/sha1=329e6c0191f65ef2996b49837d04c4cfe6934758/Edit/AppRun
You could also run this version of Edit with this version of ROX-Lib by setting PYTHONPATH and running the AppRun script manually.
Continue to part three |