Index: trunk/jobarchived/jobarchived.py
===================================================================
--- trunk/jobarchived/jobarchived.py	(revision 455)
+++ trunk/jobarchived/jobarchived.py	(revision 466)
@@ -22,22 +22,26 @@
 #
 
-DEFAULT_SEARCH_PATH     = '/usr/share/jobarchived'
-
-import sys
-
-if DEFAULT_SEARCH_PATH not in sys.path:
-
-        sys.path.append( DEFAULT_SEARCH_PATH )
-
-import getopt, syslog, ConfigParser
-
-def usage():
+import getopt, syslog, ConfigParser, sys
+
+VERSION='0.3SVN'
+
+def usage( ver ):
+
+	print 'jobarchived %s' %VERSION
+
+	if ver:
+		return 0
 
 	print
-	print 'usage: jobarchived [options]'
-	print 'options:'
-	print '      --config, -c      configuration file'
-	print '      --pidfile, -p     pid file'
-	print '      --help, -h        help'
+	print 'Purpose:'
+	print '  The Job Archive Daemon (jobarchived) stores batch job information in a SQL database'
+	print '  and node statistics in a RRD archive'
+	print
+	print 'Usage:	jobarchived [OPTIONS]'
+	print
+	print '  -c, --config=FILE	The configuration file to use (default: /etc/jobarchived.conf)'
+	print '  -p, --pidfile=FILE	Use pid file to store the process id'
+	print '  -h, --help		Print help and exit'
+	print '  -v, --version		Print version and exit'
 	print
 
@@ -47,5 +51,5 @@
         LONG_L	= [ 'help', 'config=', 'pidfile=' ]
 
-        config_filename = None
+        config_filename = '/etc/jobarchived.conf'
 
 	global PIDFILE
@@ -74,10 +78,11 @@
 		if opt in [ '--help', '-h' ]:
 
-			usage()
+			usage( false )
 			sys.exit( 0 )
 
-        if not config_filename:
-
-                config_filename = '/etc/jobarchived.conf'
+		if opt in [ '--version', '-v' ]:
+
+			usage( true )
+			sys.exit( 0 )
 
 	try:
@@ -127,5 +132,7 @@
 	cfg.read( filename )
 
-	global DEBUG_LEVEL, USE_SYSLOG, SYSLOG_LEVEL, SYSLOG_FACILITY, GMETAD_CONF, ARCHIVE_XMLSOURCE, ARCHIVE_DATASOURCES, ARCHIVE_PATH, ARCHIVE_HOURS_PER_RRD, ARCHIVE_EXCLUDE_METRICS, JOB_SQL_DBASE, DAEMONIZE, RRDTOOL, JOB_TIMEOUT, MODRRDTOOL
+	global DEBUG_LEVEL, USE_SYSLOG, SYSLOG_LEVEL, SYSLOG_FACILITY, GMETAD_CONF, ARCHIVE_XMLSOURCE
+	global ARCHIVE_DATASOURCES, ARCHIVE_PATH, ARCHIVE_HOURS_PER_RRD, ARCHIVE_EXCLUDE_METRICS
+	global JOB_SQL_DBASE, DAEMONIZE, RRDTOOL, JOB_TIMEOUT, MODRRDTOOL
 
 	ARCHIVE_PATH		= cfg.get( 'DEFAULT', 'ARCHIVE_PATH' )
@@ -150,5 +157,5 @@
 		MODRRDTOOL		= False
 
-		debug_msg( 0, "ERROR: py-rrdtool import FAILED: failing back to DEPRECATED use of rrdtool binary. This will slow down jobmond significantly!" )
+		debug_msg( 0, "ERROR: py-rrdtool import FAILED: failing back to DEPRECATED use of rrdtool binary. This will slow down jobarchived significantly!" )
 
 		RRDTOOL			= cfg.get( 'DEFAULT', 'RRDTOOL' )
@@ -199,5 +206,4 @@
 
 import xml.sax, xml.sax.handler, socket, string, os, os.path, time, thread, threading, random, re
-import rrdtool
 from pyPgSQL import PgSQL
 
@@ -545,4 +551,6 @@
 	def checkStaleJobs( self ):
 
+		# Locate all jobs in the database that are not set to finished
+		#
 		q = "SELECT * from jobs WHERE job_status != 'F'"
 
@@ -566,4 +574,7 @@
 			job_start_timestamp	= row[8]
 
+			# If it was set to queued and we didn't see it started
+			# there's not point in keeping it around
+			#
 			if job_status == 'Q' or not job_start_timestamp:
 
@@ -574,4 +585,7 @@
 				start_timestamp = int( job_start_timestamp )
 
+				# If it was set to running longer than JOB_TIMEOUT 
+				# close the job: it probably finished while we were not running
+				#
 				if ( cur_time - start_timestamp ) > jobtimeout_sec:
 
@@ -586,4 +600,6 @@
 		debug_msg( 1, 'Found ' + str( len( cleanjobs ) ) + ' stale jobs in database: deleting entries' )
 
+		# Purge these from database
+		#
 		for j in cleanjobs:
 
@@ -593,4 +609,8 @@
 		debug_msg( 1, 'Found ' + str( len( timeoutjobs ) ) + ' timed out jobs in database: closing entries' )
 
+		# Close these jobs in the database
+		# update the stop_timestamp to: start_timestamp + requested wallclock
+		# and set state: finished
+		#
 		for j in timeoutjobs:
 
@@ -642,4 +662,6 @@
 		last_update = 0
 
+		# Use the py-rrdtool module if it's available on this system
+		#
 		if MODRRDTOOL:
 
@@ -658,4 +680,7 @@
 				return 0
 
+		# For backwards compatiblity: use the rrdtool binary if py-rrdtool is unavailable
+		# DEPRECATED (slow!)
+		#
 		else:
 			debug_msg( 8, self.binary + ' info ' + filename )
@@ -752,6 +777,4 @@
 		"""Setup initial XML connection and handlers"""
 
-		#self.myXMLGatherer	= XMLGatherer( ARCHIVE_XMLSOURCE.split( ':' )[0], ARCHIVE_XMLSOURCE.split( ':' )[1] ) 
-		#self.myXMLSource	= self.myXMLGatherer.getFileObject()
 		self.myXMLSource	= XMLSource
 		self.myXMLHandler	= TorqueXMLHandler( DataStore )
