Automatically download the newest daily build

Rinn

Developer
Edit: This broke again due to the turndown of ci.kolmafia.us. There are a couple of recent posts that may be reasonable alternatives.
-- heeheehee



I wrote a small console program that will automatically parse http://builds.kolmafia.us/ and download the latest daily build if it doesn't exist locally. You could set this as a scheduled task, but make sure you don't hammer the server looking for updates.

The program will also create (or modify) the file KoLMafiaUpdate.log so you can review previous attempts at updating. Some sample log output:
Code:
---------------
10/28/2009 11:56:41 PM
Checking http://builds.kolmafia.us/ for the latest version of KoLMafia...
KoLmafia-7772.jar is the latest version
Attempting to download http://builds.kolmafia.us/KoLmafia-7772.jar...
Successfully downloaded http://builds.kolmafia.us/KoLmafia-7772.jar
Copying KoLmafia-7772.jar to KoLmafia-latest.jar
---------------
---------------
10/29/2009 12:02:51 AM
Checking http://builds.kolmafia.us/ for the latest version of KoLMafia...
KoLmafia-7772.jar is the latest version
KoLmafia-7772.jar exists, you have the latest version
---------------
http://dl.getdropbox.com/u/220774/KoLMafiaUpdate.exe
http://dl.getdropbox.com/u/220774/KoLMafiaUpdate.cs


Version 1.8 - Fix for not being able to parse the revision number because the filename has an M at the end. Also fixed the -h typo.
Version 1.7 - Fix for the build links sorting by string instead of revision number.
Version 1.6 - Add some additional exception handling.
Version 1.5 - Only delete kolmafia jar files.
Version 1.4 - Delete old .jars after updating. Passing in -d as a command line argument will disable this functionality.
Version 1.3 - Open KoLmafia-latest.jar automatically. Passing in -o as a command line argument will disable this functionality.
Version 1.2 - Don't copy if the download fails
Version 1.1 - Automatically make a copy of the latest version as KoLmafia-latest.jar
Version 1.0 - Release
 
Last edited by a moderator:
Very nice! On my computer I have a cron job set up to run this script once a day. It uses ant to download the source and compile from svn, then copies the .jar to my working dir and runs it for me. The beauty of this is it only downloads the changes to kolmafia so server hits are always low. I use xterm to run the .jar because it is tough to get a cron script to start something graphical, plus it gives me a terminal where I can see any errors that mafia may spew.

Code:
#!/bin/bash
kol_dir=~/kol
mafia_src=$kol_dir/kolmafia

cd $mafia_src
ant daily

rm $kol_dir/daily.jar
mv $mafia_src/dist/KoLmafia* $kol_dir/daily.jar

xterm -display :0 -e "/usr/bin/java -jar $kol_dir/daily.jar"
 
Yeah that's also a good solution, but a lot of people probably don't want to have to set up everything necessary to compile the source.
 
I personally prefer to compile the .jar myself, but I can see an automated download process being very attractive to a lot of users.
 
Cool!

Any chance you could make this also run the newly downloaded mafia? Or in the case that it already exists, run that? It would be cool to have a single click automatically run the latest daily.
 
Yeah that's actually pretty easy to do. One sec.

Okay done, passing in -o as a command line argument will disable automatically starting the jar.
 
Last edited:
Thanks, this is awesome, I just ran it and it worked like a charm. A few things you should probably mention in your first post: 1) it's for Windows, 2) you need .NET 2.0, otherwise you get a "could not initialize properly" error, and 3) it should go in your mafia directory.

EDIT: Just one other thing, and then I think it would be perfect. It would be nice not to have to regularly delete old builds. Could you add an option for deleting all other jar files in the directory other than the current daily and KoLmafia-latest? Either that, or an option for auto-deleting kolmafia-buildnum after copying it to kolmafia-latest... in which case instead of checking file.exists, you'd have to parse the log to see if the latest is really the latest. I think the first option is probably easier.
 
Last edited:
Yeah I can do that. I'd rather keep the copy of the latest version downloaded so you can know at a quick glance what version the latest.jar is without opening up the log, but deleting other .jars should be simple enough.
 
Truly Awesome. You have saved me lots of clicking, and probably kolmafia.us server bandwidth (not fetching images/CSS, also avoiding cases of re-downloading because you're not sure if it's the latest or not).
 
I love the idea of deleting all the old programs, however it seems to do good of a job
Deleting old version AscensionLogVisualizer 2.1.0.jar

Is there anyway it can just del old versions of mafia and not all jar files?
 
Is there anyway it can just del old versions of mafia and not all jar files?

I haven't used this application so I don't know exactly how it functions, but would another directory help?

The AutoIt script that I wrote to compile my .jar also backs up and timestamps the previous .jar and puts it in another directory. (with the extension renamed to .bak) It then goes through and deletes all the backups that are older than 7 days. This makes it very easy to rollback to previous builds if necessary.

Perhaps something like this would work for this application? It may be making things a bit more complicated, but it seems more forgiving if the application was pointed to a directory that you can be assured only the files you want to would be removed.
 
The change for that should be easy.
Code:
FileInfo[] dirFiles = dir.GetFiles("*.jar");
should be
Code:
FileInfo[] dirFiles = dir.GetFiles("KoLmafia*.jar");
At least I think so, I can't exactly check on this computer, probably.
 
Yeah that's exactly it, I didn't expect anyone to have other jar files but here we are.

Okay new version up.
 
Last edited:
If KoLmafia-latest.jar exists it should run it regardless. If this is the first time you've run this program and you already have the latest daily build downloaded, it's not going to make a copy as KoLmafia-latest.jar until it actually downloads something.
 
Back
Top