Wanted: Migrating To a Newer Image Part 2

In the last post we migrated the Wanted source code to a newer image by using a local Monticello repository. That gave us a working Wanted application, but the WantedItems that we created in the old image weren't copied over. This post will focus on copying the data out of the old image and into the new one.

Write Out the Collection of WantedItems

Fire up the old Squeak image, open a workspace and execute the following:


| out |
out := DataStream newFileNamed:
'/path-to-your-directory-here/wanted-items.dat'.
out nextPutAll: WantedDatabase wantedItems.
out close

This creates the temp variable out to hold a DataStream object pointing to a new "wanted-items.dat" file. The nextPutAll method takes a collection of objects and writes it to the receiving stream before closing it.

Exit the old Squeak image--this will be the last time we need it. From now on, all things in these tutorials will be done in the new image.

Read In the Collection of WantedItems
Fire up the shiny new image, open a new workspace, and execute the following:

|in|
in := DataStream fileNamed:
'/path-to-your-directory-here/wanted-items.dat'.
[in atEnd] whileFalse:
[WantedDatabase wantedItems add: in next].
in close

The above creates a new DataStream off of the "wanted-items.dat" file (notice we're using the fileNamed message to create the DataStream instead of newFileNamed). The [in atEnd] block will return false until all objects have been read from the file. We pass that block another block that adds each object read in (using the next message) to the WantedDatabase wantedItems collection. Then we close the DataStream.

We now have our old WantedItems in the new image. Open up a browser and head to http://localhost:8080/seaside/wanted. You should see something like this:



Enable File Serving in Commanche

Our new image is not serving our css since Commanche is not enabled to serve files. Paste the following into a new workspace and "do it":

| ma seaside |
HttpService allInstancesDo:
[:each | each stop. each unregister].
WAKom stop.
seaside := WAKom default.
ma := ModuleAssembly core.
ma serverRoot: FileDirectory default fullName.
ma alias: '/seaside' to:
[ma addPlug: [:request | seaside process: request]].
ma documentRoot: FileDirectory default fullName.
ma directoryIndex: 'index.html index.htm'.
ma serveFiles.
(HttpService startOn: 8080 named: 'httpd') plug: ma rootModule

That should get you to this:


That Entered Date Format Has Been Bugging Me
Me too. We can solve that by adding a formatBlock to the WAReportColumn that handles the enteredDate in WantedList>>initialize:

add:
((WAReportColumn selector: #enteredDate title: 'Entered Date')
formatBlock:
[:enteredDate | enteredDate asDate mmddyyyy];
yourself);

We get the date to show up in mm/dd/yyyy format by sending the asDate message to the enteredDate of the WantedItem, then sending the mmddyyyy message to that date.

While we're there, let's modify the "Can Buy" WAReportColumn to show 'Yes' or 'No' instead of the robot-like 'true' or 'false':

add:
(WAReportColumn
renderBlock:
[:item | item isPurchasable
ifTrue: ['Yes'] ifFalse: ['No']]
title: 'Can Buy');

This is accomplished by sending the isPurchasable predicate the ifTrue:ifFalse: message with a "Yes" or "No" value respectively.

Those changes should give you something like this:


Saving Changes
Since we made source changes, we should commit them to our local Monticello repository. Open a Monticello Browser and select the Wanted-Item package in the left pane, and the local repository in the right pane:

Notice that an asterisk appears before the package name: this signifies that changes have occured in the package. Click the Save button and enter a version message describing the changes we made:


When you hit Accept, a version info window will display letting you know that the changes were successfully saved. At this point, save the image so that the WantedItems will be persisted. And that's it for this post--we are now fully migrated over to the new image. By now it feels like we've kinda worn out the simplicity of saving the WantedItems in a collection in the image. If we had had the data in a store somewhere, we could have just pointed the new image there instead of this file reading/writing stuff. Future posts will address this.

Posted in Labels: , , , , | 2 comments

Wanted: Migrating to a Newer Image

Damien Cassou recently announced the release of a new Squeak-Web image which can be found here. This post will focus on migrating the Wanted application from the image we've been using to his new one. Before this post, I was keeping my squeak stuff spread out all over the place, and since I'm migrating to a newer image I thought I'd get a little more organized and detail my setup here.

A More Disciplined Directory Structure
Instead of scattering everything all over the place, I created a proj directory with the following directory tree:


  • proj/squeak is where all Squeak-related stuff goes
  • each directory in apps contains a combination of an image plus a vm
  • doc is for all Squeak/Smalltalk related pdfs like free books
  • images and vms contain different versions of squeak images and vms
  • repository is for the local Monticello repository, which we'll get to in a bit
  • tmp should be obvious
The "apps/wanted" directory is a new directory created for the new squeak-web image. My old image that I've been using for the Wanted tutorial is sitting in a different location.

Setting Up a Local Monticello Repository
We're going to use Monticello to handle the versioning of Wanted (there's some overview info on Monticello here). Fire up the image you've been using for the Wanted tutorial, then click on the World and select open... -> Monticello Browser. You should see this window:


Click the "+Package" button. Enter "Wanted-Tutorial" (or the name of the package containing the Wanted tutorial objects in your image) in the "Name of package" dialog:


and click the Accept button. Then add a local repository by clicking the "+Repository" button, and choosing "directory" from the "Repository type" dialog:


The "Repository folder" dialog will then display:


Navigate to the folder you want to store the local Monticello repository in and hit the "ok" button. You should now be looking at the Monticello browser with the Wanted-Tutorial package selected in the left pane and the repository folder selected in the right pane. Click the "Save" button in the row of buttons in the Monticello browser. Enter you initials in the dialog that pops up and Accept. The "Edit Version Name and Message" dialog will pop up:


Enter a comment and Accept. If all went well you should end up with a window like this:


We now have a working versioning repository for our Wanted tutorial code. As you'll see, migrating it to newer images will be a snap. At this point, close the old image but keep it around--we'll need it later.

Setting Up the New Image
After downloading Damien's new image and unpacking it into the "images/squeak-web-95-2" directory (see the directory layout above), I copied the
  1. squeak-web-95-2.image
  2. squeak-web-95-2.changes
files into the "apps/wanted" directory. I then copied the
  1. Squeak3.8.xxx
  2. SqueakV39.sources
files from the current vm in the "vms" directory into the "apps/wanted" directory. I also copied the
  1. wanted.css
file from the old image directory into "apps/wanted". Once all 5 files are copied, in "apps/wanted", drag the squeak-web-95-2.image file over the Squeak executable to open Squeak with the new image. Collapse the Script Manager and Preference Browser windows to make some room.

Open a Monticello Browser and click the "+Repository" button. Choose "directory" from the "Repository type" and select the directory you created above. With the directory repository highlighted in the right pane in the Monticello Browser, click the "Open" button. You should see a window like this:

Highlight the "Wanted-Tutorial...1.mcz" file in the right pane (the version information will appear in the bottom pane when you do so), then click the "Load" button. After the progress dialogs go away, open a new Refactoring Browser and scroll to the bottom of the Packages list:

Well looky there! I'll wait for you if you want to get up and do a happy dance.

In this new image, Seaside doesn't know about our Wanted app yet because we haven't registered it. If you open a web browser to http://localhost:8080/seaside/wanted you will get a listing of the registered Seaside apps, and Wanted isn't one of them. Let's fix that. Open a Shout Workspace, enter the following, highlight and "do it":


WantedList registerAsApplication: 'wanted'


Now go to http://localhost:8080/seaside/wanted. Notice that our app shows up, but all of our WantedItems are missing! Stay tuned--we'll fix that in the next post. For now, save the new image. I'm just going to use the default "squeak-web-95-2.image" name instead of naming it "wanted.image" since it's already in the "wanted" directory. If you wanted you could name it "why-is-sanjaya-not-voted-off-yet.image" and the world would still turn and make bad decisions and watch bad TV.

Posted in Labels: , , , , | 2 comments