?

Log in

No account? Create an account

Wed, Oct. 12th, 2005, 01:00 pm
Subverting my code

I've been really bad about putting my personal code in a version control system. When I've been working other projects like Siesta or the Bot stuff then I'm fine but my stuff has largely been archived by, err, CPAN. NORTY Simon! No Cookie!

So clearly the right thing was to grab everything from BackPAN and sling it in as tags. It's not perfect but it's better than nothing. Fortunately somebody has already thought of the hard part of getting stuff into Subversion for us and Leon has done Parse::BACKPAN::Packages so it's fairly trivial.

I made sure that svn_load_dirs was installed. If not you can get it here and manually change the path to your svn binary.

Then I wrote this script.

    use strict;
    use Date::Parse;
    use LWP::Simple;
    use File::Remove qw(remove);
    use Parse::BACKPAN::Packages;
    my $p = Parse::BACKPAN::Packages->new();
    my $user = shift || die "You must pass a pause id\n";  $user = uc($user);
    my %dists;
    foreach my $dname ($p->distributions_by($user)) {
        foreach my $dist ($p->distributions($dname)) {
            push @{$dists{$dname}}, { version=>$dist->version, time=>$dist->date };        
        }
    }
    foreach my $key (sort keys %dists) {
        my @versions = map { $_->{version} } 
                       sort { $a->{time}<=>$b->{time} } 
                       @{$dists{$key}};
        print "$key - ";
        print join(", ", @versions)."\n";
            my @dirs;
    
        for my $version (@versions) {
            my $name = "$key-$version";
            mirror("http://backpan.perl.org/authors/id/".
                                            substr($user,0,1)."/".
                                            substr($user,0,2)."/".
                                            $user.
                                            "/$name.tar.gz".
                                            "$name.tar.gz");        
            # should really use Archive::Tar here
            `tar -xvzf $name.tar.gz`;
            push @dirs, "$name";
        }
        my $dir = join " ", @dirs;
        # at some point in the future I should turn this into a module
        `svn_load_dirs --no_user_input https://example.com/svn simon/$key \
                              -t 'simon-releases/$key/\@\\d+\\.\\w+\@' $dir`;
        remove map { "$_.tar.gz" } @dirs;
        remove \1, @dirs;
    }

Several minutes later I had a shiny new RichardC hosted subversion repository which can be found at https://unixbeard.net/svn/simon with releases in simon-releases. Shiny!