tucuxi.org: software engineering, photography and troubleshooting

Attachments:
Dump in ~/bin:
  azstats shell script
 
Dump in ~/public_html:
  azstats.xsl html xsl
  azstats-text.xsl text xsl
 
 

Abstract

Setup Azureus to publish download statistics on the web, or view them on the console.

Introduction

Wow. That's all I can say about my experience with XSLT over the previous week or so. It's.. well.. it's a dream to work with. No need to write an application to parse a XML document tree; the language is defined well enough to avoid the need for writing your own parser. XSL does have its own quirks though when you're writing it.. you have to really get into the swing of coding XSL, which in my case, took a few days before I really understood it. XSL and XPath form a rather powerful language for parsing, transforming, and outputting documents in XML, or even plain text format. I've even seen a few mailing lists describing XSL output to PDF. Anyways, onto the Azureus-related stuff.

Azureus comes with a rather nice inbuilt XML exporter for the download list. I can only really pick two faults with it, firstly, it doesn't provide a DTD. This is a bit of a minor point to pick at, but it would make the file a bit easier to understand at first. Secondly, and more importantly, the file writes are not atomic.. if Azureus is updating regularly, you tend to get a broken file. This is especially noticable when loading the XML file in a web browser - you can get broken parse errors etc.

How to set things up in Azureus

First step, make sure you've got a recent copy of Azureus. I'm using 2.2 here.. the latest should suffice. Goto Tools -> Options, and click on the Statistics entry. Check the box to enable dumping stats. Now, select a directory for the XML output. If you want your stats to be web-accessible, I suggest putting the stats in a web-accessible folder (/var/www on most Unix systems, or in ~/public_html). Set the statistics filename to something unique in that directory - I'm using azstats.xml here. You'll have to modify the 'azstats' script with both directory and filename that you've chosen. Now we come to the important bit - XSL filename. If you want the HTML template that I've included (azstats.xsl), then enter azstats.xsl here. If you want the text template that I've included (azstats-text.xsl), use azstats-text.xsl here. I would strongly suggest using the web template here unless you have a good reason to use the text one.. firstly, it looks prettier, and secondly, I haven't tested the text one's usage with various browsers - specifically, the content type in the XSL. For save frequency, I've found 30 sec is a good balance between update time and lack of corruption. If you just want to look at your stats on the web, you're done. Point a webbrowser at the .xml file, and you'll see your download stats.

Looking at your stats over a SSH connection

This is also applicable over telnet etc., but you wouldn't really be using such an insecure method.. would you? I suggest dumping the attached shell script (azstats) into ~/bin, or whatever directory is in your path. Install xsltproc (apt-get install xsltproc, if you're using Debian), and edit the shell script to reflect whatever path structure and filename you have chosen locally. Do a chmod u+x on the shellscript, and once this is done, you can just run 'azstats' to look at the status of your downloads.

The HTML XSL

I really don't want to talk about this... except to say that it was my first attempt at XSL. Please, kids, don't try this at home. All warranties void. It works.. but it's not clean.

The text/plain XSL

Now this is a bit cleaner.. the use of multiple <xsl:template /> blocks.. calling templates, parameters.. it's all there. This is probably a decent enough example to look at to work out how to call templates. I'm not going to go into too much detail (mainly because I just realised it's 2:30am), except to say that <xsl:apply-templates /> works like using a <xsl:call-template> inside a for-each loop. Also, one thing that does shit me about XSL at times.. the poorly documented <xsl:variable> entity, especially with respect to scope. I'm not sure if it's just that I'm using a lousy XSLT processor, or if it's the spec.. but it's painful.

Credits

tucuxi.org content is copyright © 2001-2007.

social network