Monthly Archives: July 2013

Customizing ZeroConf scripts

As you may already know, ZeroConf scripts are bash scripts that ease the installation of a Pharo environment. A funny thing about these ZeroConf scripts is that they are seen as bash scripts by a bash terminal, and as simple and minimal html pages by a web browser. These scripts are extensively used to simplify the configuration of Pharo CI jobs. They allow you to easily download many versions of the Pharo image and VM.

As I’m working for my Phd, and have a custom version of my virtual machine and image, and also want to make use of the advantages our CI server provides, I wanted to build my own ZeroConf scripts specialized for my needs. I also heard recently on the pharo mailing list that there was some work on customizing ZeroConf scripts[1] for Moose[2]. So I wanted to do it as well for my project :).

[1] http://get.moosetechnology.org/
[2] http://www.moosetechnology.org/

Downloading the ZeroConf package

The ZeroConf scripts are generated automatically by the ZeroConf Pharo package. You can find this package in [2]. To download the current version, you just have to execute the following piece of code in a workspace:

Gofer it
	smalltalkhubUser: 'Pharo' project: 'ZeroConf';
	package: 'ZeroConf';
	loadVersion: '1.0'

This code snippet will install in your image the ZeroConf package for the 1.0 version, containing the script generator, and some tests that are not currently working :).
[2] http://www.smalltalkhub.com/#!/~Pharo/ZeroConf

Getting what’s inside ZeroConf

The ZeroConf package is pretty small and simple. There is an abstract class AbstractZeroConfBashScript implementing most of the script generation and bash writing utils. Its subclasses will implement the concrete script generation. Current implementation includes three main classes below the AbstractZeroConfBashScript hierarchy, implementing a composite pattern:

  • ZeroConfImageScript: Generates scripts in charge of downloading image files.
  • ZeroConfVMScript: Generates scripts in charge of downloading Virtual Machine files (and source files).
  • ZeroConfCombinedScript: Generates scripts that combine several scripts. It will point to its combined scripts and downloading it means to download them all.

zeroconf

Customizing our ZeroConf scripts

As you can see in the picture, in order to customize the ZeroConf scripts, you have to create your own subclasses and overriding the correct hooks.

Customizing an image script

A custom image script is defined by a subclass of ZeroConfImageScript. ZeroConfImageScript already defines some image common behavior, such as the release number, which we will use in our script.

ZeroConfImageScript subclass: #OzZeroConfImageScript
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'OurZeroConf'

Then we override the methods that tell some information about the files to download:

  • OzZeroConfImageScript>>imageName: The name of the image and changes files
  • OzZeroConfImageScript>>imageUrl: The url of the image zip, instance of ZnUrl
  • OzZeroConfImageScript>>defaultBaseName: The baseName of the script
  • OzZeroConfImageScript class>>baseUrl: The base url where the scripts are found, instance of ZnUrl
  • OzZeroConfImageScript class>>fileBaseUrl: The base url where the files the scripts will download are found, instance of ZnUrl

I implemented them in my class as follows

OzZeroConfImageScript>>imageName
	^'Oz'

OzZeroConfImageScript>>imageUrl
	^ self fileBaseUrl / 'image' / self release asString / self imageFileName / 'download'

OzZeroConfImageScript>>imageFileName
	^'Oz-image-', self release asString , '.zip'

OzZeroConfImageScript>>defaultBasename
	^ self imageName, self release

OzZeroConfImageScript class>>fileBaseUrl
	^ 'https://sourceforge.net/projects/ozobjectspaces/files' asZnUrl

OzZeroConfImageScript class>>baseUrl
	^ self fileBaseUrl / 'get'

I also extended my script so it generates a custom html title and uses my combining script when combining:

OzZeroConfImageScript>>htmlTitle
	^ self imageName, ' Zeroconf Script'

OzZeroConfImageScript>>defaultCombiningScript
	^ OzZeroConfCombinedScript

Finally, I created a convenience method for creating a script corresponding to the 1.0 version of my custom image.

OzZeroConfImageScript class>>oz10
	^self new
		release: '1.0';
		yourself

Now you can try generating your script in a workspace,

OzZeroConfImageScript oz10 generate

and see the generated results in your working directory!

Customizing a vm script

A custom vm script is defined by a subclass of ZeroConfVMScript. ZeroConfVMScript defines, as its image friend, some vm common behavior, such as the release number and virtual machine type(i.e., if it is a jitted vm or not), which we will use in our script.

ZeroConfVMScript subclass: #OzZeroConfVMScript
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'OurZeroConf'

Then we override the methods that tell some information about the files to download:

  • OzZeroConfVMScript>>binaryName: The name of the vm binary name
  • OzZeroConfVMScript>>binaryNameLinux: The name of the vm binary name in linux, which tends to be different
  • OzZeroConfVMScript>>vmUrl: The url of the vm zip, instance of ZnUrl
  • OzZeroConfVMScript>>defaultBaseName: The baseName of the script
  • OzZeroConfVMScript class>>baseUrl: The base url where the scripts are found, instance of ZnUrl
  • OzZeroConfVMScript class>>fileBaseUrl: The base url where the files the scripts will download are found, instance of ZnUrl

I implemented them in my class as follows

OzZeroConfVMScript>>binaryName
	^'ozstack'

OzZeroConfVMScript>>binaryNameLinux
	^self binaryName

OzZeroConfVMScript>>vmUrl
	^self fileBaseUrl asString, '/vm/', self release asString,'/', self vmFileName, '/download'

OzZeroConfVMScript>>vmFileName
	^'OzVm-${OS}-', self release asString , '.zip'

OzZeroConfVMScript class>>fileBaseUrl
	^ 'https://sourceforge.net/projects/ozobjectspaces/files' asZnUrl

OzZeroConfVMScript class>>baseUrl
	^ self fileBaseUrl / 'get'

I also extended my script so it uses my combining script when combining:

OzZeroConfVMScript>>defaultCombiningScript
	^ OzZeroConfCombinedScript

Finally, I created a convenience method for creating a script corresponding to the 1.0 version of my custom vm.

OzZeroConfVMScript class>>ozvm10
	^self new
		type: 'oz';
		release: '1.0';
		yourself

Now you can try generating your script in a workspace,

OzZeroConfVMScript ozvm10 generate

and see the generated results in your working directory!

Customizing a combined script

A combined script is the one we use to combine several scripts. It is defined by a subclass of ZeroConfCombinedScript.

ZeroConfCombinedScript subclass: #OzZeroConfCombinedScript
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'OurZeroConf'

Then we override the methods that tell some information about the files to download:

  • OzZeroConfCombinedScript class>>baseUrl: The base url where the scripts are found, instance of ZnUrl
  • OzZeroConfCombinedScript class>>fileBaseUrl: The base url where the files the scripts will download are found, instance of ZnUrl

I implemented them in my class as follows

OzZeroConfCombinedScript class>>fileBaseUrl
	^ 'https://sourceforge.net/projects/ozobjectspaces/files' asZnUrl

OzZeroConfCombinedScript class>>baseUrl
	^ self fileBaseUrl / 'get'

As you can see, my methods baseUrl and fileBaseUrl are always the same in all scripts. I extracted them into another class later, but keep the code here as is for clarity.

I also extended my script so it uses my combining script when combining and the html title:

OzZeroConfCombinedScript>>defaultCombiningScript
	^ OzZeroConfCombinedScript

OzZeroConfCombinedScript>>htmlTitle
	^ self scripts first htmlTitle

Integrating everything and automating generation

As I already showed you, every script understands the message #generate to generate itself. However, we may want to generate many scripts, and combine them. The ZeroConf infrastructure already provides for that the ZeroConfCommandLineHandler. The ZeroConfCommandLineHandler is a command line handler that knows which are the scripts we want to generate, combines them appropriately and generates them. So we will subclass from ZeroConfCommandLineHandler and specialize it to fulfill our needs.

ZeroConfCommandLineHandler subclass: #OzZeroConfCommandLineHandler
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'OzZeroConf'

Once we have it, we configure it as a command line handler specifying its command name and description:

OzZeroConfCommandLineHandler class>>commandName
	^ 'ozzeroconf'

OzZeroConfCommandLineHandler class>>description
	^ 'Generate Oz zeroconf bash scripts'

And finally we specialize it to tell it about our scripts:

OzZeroConfCommandLineHandler>>defaultScript
	^ self defaultImage, self defaultVM

OzZeroConfCommandLineHandler>>defaultImage
	^ OzZeroConfImageScript oz10

OzZeroConfCommandLineHandler>>defaultVM
	^ OzZeroConfVMScript ozvm10

OzZeroConfCommandLineHandler>>imageScripts
	^ { 
		OzZeroConfImageScript oz10.
	}

OzZeroConfCommandLineHandler>>vmScripts
	^ { 
		OzZeroConfVMScript ozvm10
	}

OzZeroConfCommandLineHandler>>indexScriptExamplesHtml
	^ ''

Now we have our command line handler, we can test it and make it generate our scripts:

OzZeroConfCommandLineHandler new
	commandLine: CommandLineArguments new;
	generateScripts

Finally, if you have all this code in your image, you can just activate it through the command line thanks to the command line handler!

./pharo PharoMyZeroConf.image ozzeroconf

And look at the results. Upload your files, archive them, and use them :).

Guille

Installing Pharo in many flavors

Buon giorno!

In the recent times, there appeared many many ways to leverage the installation and deploy of Pharo applications. These installation approaches enhance significantly the experience of using Pharo, by simplifying either dependency management with OS libraries, enabling to write deploy bash scripts or loading prebuilt images for any (and many) taste(s).

However, if you are not in the Pharo mailing lists, you probably have not heard about many of these installation mechanisms, and therefore, you cannot enjoy them. So, let’s summarize a bit some of these mechanisms, at least the ones I know. If you know some more, contact me so we can include it.

Manual download from the webpage

Downloading Pharo manually is the easiest but more primitive approach. Proceed to the download page [1] and download the flavor of Pharo you like the most. You will find in here the 1.3, 1.4 and 2.0 releases, plus the option to load the latest (still in development) version of Pharo 3.0.

Focusing on what is available for Pharo 2.0, you can either install

  • under the category “Pharo Installers”: a package specific for your operative system containing both virtual machine and the image with the runtime and development environment
  • under the category “Custom Downloads”: the possibility to download them by separate. This option is useful if you already have a virtual machine and only want a new image to play with.

[1] http://www.pharo-project.org/pharo-download

Manual download from the file server

In the Pharo file server[2] you will find available the virtual machine and image releases as well as other resources to download. You can use these urls to create your custom download scripts.

[2] http://files.pharo.org/

Virtual Machine PPA for Ubuntu linux

There is a PPA available for Ubuntu users (probably it works also for any distribution using apt-get package manager) which is in charge of downloading the virtual machine and its dependencies, simplifying its installation and deploy. We thank Damien Cassou for taking finally the initiative of creating the PPA!

#install the PPA repository
sudo add-apt-repository ppa:pharo/stable
sudo apt-get update

#install pharo vm core
sudo apt-get install pharo-vm-core

#install pharo vm for desktop (with graphical dependencies)
sudo apt-get install pharo-vm-desktop

ZeroConf scripts

The ZeroConf scripts[3] are already built bash scripts easing the download and installation of pharo. They are scripts served by get.pharo.org which can be parameterized for getting the pair vm/image you want.

Their usage, as written in the ZeroConf webpage can be resumed as

curl url | bash
#or if curl is not available:
wget -O- url | bash

where url is replaced by the formula vmVersion|imageVersion|vmVersion+imageVersion

For example, some valid usages of ZeroConf are

#downloading latest 3.0
curl get.pharo.org/alpha | bash

#downloading stable 2.0 + vm
curl get.pharo.org/20+vm | bash

#downloading latest non stable vm
curl get.pharo.org/vmLatest | bash

You can look for the valid values in the ZeroConf page [3]. These scripts are currently heavily used by the ci infrastructure of pharo. We thank Camillo Bruni for pushing this harder!

In fact, this is the way I download my own images right now, because the url is easy to memorize and using the terminal is pretty straightforward.

[3] http://get.pharo.org/

Pharo Launcher

The Pharo Launcher is an application to download and manage prebuilt and custom Pharo images. Below I paste the release notes from the first release:

“Erwan and I are proud to announce the first release of the Pharo
Launcher, a cross-platform application that

– lets you manage your Pharo images (launch, rename, copy and delete);
– lets you download image templates (i.e., zip archives) from many
different sources (Jenkins, files.pharo.org, and your local cache);
– lets you create new images from any template.

The idea behind the Pharo Launcher is that you should be able to
access it very rapidly from your OS application launcher. As a result,
launching any image is never more than 3 clicks away.

Download: https://ci.inria.fr/pharo-contribution/job/PharoLauncher/PHARO=30,VERSION=bleedingEdge,VM=vm/lastSuccessfulBuild/artifact/PharoLauncher.zip

Please report bugs on the ‘Launcher’ project at https://pharo.fogbugz.org

You can contribute to this project. All classes and most methods are
commented. There are unit tests. Please contribute!

Source code: http://www.smalltalkhub.com/#!/~Pharo/PharoLauncher
CI: https://ci.inria.fr/pharo-contribution/job/PharoLauncher

Pharo Launcher screenshot

Pharo Launcher screenshot

The Pharo launcher is an initiative of Erwan Douaille and Damien Cassou. And of course, you can contribute to it. In their release notes they added some points they would like to enhance in this project:

  • check if a template is already downloaded before downloading it
  • add a preference mechanism (for, e.g., quit after launch, definition of your own template groups, location of downloaded templates and images)
  • put the launcher in the Pharo Ubuntu package so that the launcher becomes a registered application of the system (https://launchpad.net/~pharo/+archive/stable)
  • make sure the pharo launcher does not load your personal scripts (like fonts and MC configuration)
  • add a toolbar to enhance the discoverability of the features (currently everything is in contextual menus)
  • make sure rename and copy actions propose default values
  • make sure no debugger pops up when a user press cancels or enter an invalid name
  • propose multiple kinds of sorting (last used, most frequently used, alphabetically on the name)
  • give some information about each template (build date, pharo version)

Conclusion

Pharo is growing, and getting sexy. And now you have easy deploy, and it will get only easier in the future. What are you waiting?

#Just do this!
curl get.pharo.org/20+vm | bash
./pharo-ui Pharo.image