Jun 23 2008

How to automatically version a Flex application

Tag: code, pythondenis @ 4:11 pm

I recently added automatic versioning to my Flex projects. This is quite useful when you want to know exactly which version of your application is currently running when it’s being debugged, deployed, tested, etc. This basic example will generate a version string containing a major version number, minor version number, svn revision number and a build number. The build number is incremented every time your application is built. It assumes you have python installed and use SVN as your version control system.

Storing your version information

We will use a simple text file to do that and we’ll call it .version. Its format will be:
major_no
minor_no
build_no
revision_no

Updating the version data

A small python script is used to do that. A build number is incremented each time and the revision number is retrieved from SVN. Here’s the versioner.py script (make sure it’s executable):

#!/usr/bin/python
v = open('.version')
major = int(v.readline().strip() or '2') # can change 2 for any major version number you'd like
minor = int(v.readline().strip() or '5') # idem
build = int(v.readline().strip() or '0') # idem
build += 1
import os, re
ri, ro = os.popen2("svn info", 'r')
rev = ro.read()
ri.close()
ro.close()
revre = re.compile('Revision: ([\d]+)')
revision = revre.search(rev).group(1)
o = open('.version', 'w')
o.write("%d\n%d\n%d\n%s\n" % (major, minor, build, revision))
o.close()

Running the version script

If you’re using Flex Builder, this is easily done:
Go to project properties.
Under the Builders tab, click New
Name it anything you like
Select the versioner.py script in location
Select the folder containing your .version file as the working directory
Check “During manual builds” and “During auto builds” in the Build Options
Once your builder is created, make sure it’s at the top.

Using the version information

You can embed it in your Flex application using the following code:

[Embed(source="../.version",mimeType="application/octet-stream")][Bindable]
 
public var version:Class;

and then you can access it at runtime using a function like this:

public function getVersion():String {var v:Array = String(new version).split('\n');
 
return v[0] + '.' + v[1] + '.' + v[3] + ' build ' + v[2];;
 
}

which will return something like ‘major.minor.revision build’.


Oct 24 2006

trying out google custom search engine

Tag: api, del.icio.us, google, python, rssdenis @ 3:07 am

I’m playing around with the latest Google product tonight, namely Custom Search Engine. I tried to import some del.icio.us accounts in it and the results are interesting: it can be a nice way to search through your bookmarked pages. To do so I created a little CSE Python API (ok, it’s not really an API since it only supports CSE creation) but maybe someone will improve it. You may use it from the command line to create a CSE from any RSS feed:

python rss2cse.py gaccount_username gaccount_passwd http://del.icio.us/rss/popular

or create a better del.icio.us integration (with tags as keywords, parsing each pages, etc) using the GCSE class.