Telling Gnu Arch the truth

Yet another problem (and solution) that I’ve stumbled across while using Gnu Arch. We have two branches in our archive: program--vendor--0.1 and program--local--0.1. Vendor’s version has all the source files in SomeDirectory, while our local version has all source files in somedir. Except for the name and few local changes, these two directories are practically identical.

But when we were creating branches and importing code, we weren’t very careful and ended up with these directories and files having different arch IDs. This makes comparing two source trees close to impossible, as arch thinks that directory SomeDirectory was removed together with all its content and directory somedir was added together with a bunch of files.

Telling Arch the truth is very simple. Basically, all that needs to be done is =id and *.id files under all .arch-ids/ directories in one source tree should be copied to the appropriate places in the other source tree. After that tla commit should be done.

In order to minimize the pain of manual labour, I wrote a tiny perl script to find all needed files and copy them appropriately. On the command line just specify two directories, which you know are the same, but which arch considers different. If any of the files weren’t copied, you’ll get their names in the warning. When script finishes, you’ll get the total count of copied files.

The script is here: fix_arch_ids.pl

Sending bulk HTML emails with perl

First of all, I have to warn you that using HTML in emails is almost always inappropriate. Use plain text. If you have to send HTML, than send it as an attachment.

For those cases, where HTML message has to be sent and there is no choice in the matter, here is a small perl script – send_html_mail.pl

Edit a few lines at the beginning of the file to suit your needs. From address and Subject line must be changed. Locactions of two files – list of recepients and the body of the message – can be either specified on the command line or will be taken from default values hardcoded in the script.

Run the script as:

send_html_mail.pl message.html recepients.txt

If you changed the location of data files or if you are using defaults, than you don’t have to pass any arguments to the script.

List of recepients is expected to be a comma separated list of names and emails. An example file could look like this:

You There,you@there.org
Him Somewhere,him@somewhere.net

Message body file should contain all your HTML, CSS, JavaScript and whatever else is that you want to send. Here is an example file for you:

<HTML>
<BODY>
<H1>Hi there!</H1>
<DIV>This is an HTML message.</DIV>
</BODY>
</HTML>

It is easy to change the script to send plain text messages instead of HTML. Just change the line that specifies Content-Type as “text/html” to “text/plain”.

rss2mail

Previously I have wrote lj2mail – a script which gets fresh posts from LiveJournal and emails them to the list of recepients. I have tried to avoid sending same items over and over again, but failed. The script was implemented with the help of LiveJournal API (LJ::Simple Perl module).

I got annoyed by that script repeating some items (mess with publishing date), so I wrote a different one. rss2mail simply gets the RSS feed, parses it and emails items as individual messages to the list of recepients. I guess that caching RSS item link is much better than LiveJournal’s publishing date. Also, rss2mail is much more flexible. It can be used with any RSS feed, not only LiveJournal’s. I have tried to make it as generic as possible. If it doesn’t work with other feeds, just check the fields of the RSS feed it uses.

rss2mail.pl

webby_m3u

Today I have found a really nice way to listen to my home mp3s at work. All I needed to do is share my music directory via web and generate an m3u playlist with URLs to files. m3u playlist than could be downloaded and fed to XMMS, where I could select songs to play. It is also nice to use random playback until I find something I am in the mood for and than switch to sequential mode.

Anyway, I wrote a small Perl script to generate an m3u playlist. It dives into some directory recursively and correctly escapes all the URLs. Check the few configuration variables in the beginning of the file.

webby_m3u.perl

Linkblogging with del.icio.us

I was thinking about syndicating my del.icio.us bookmarks into the blog, but never implemented it. Today I stumbled upon this post which explains how to syndicate del.icio.us into Movable Types. The Perl script used is a dirty hack. Of course, I had to immidiately correct and improve the situation.

My version of the script uses XML::RSS module for parsing the RSS feed and CGI module for generating the HTML. It also uses del.icio.us tags as a title of the link. Overall, the script is much smaller and cleaner. The results of its work can be seen in the right panel, below archives.

linkblog.pl