Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 92 lines (75 sloc) 2.721 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple qw(mirror);
use RDF::NS;
use File::Temp;
use Text::Wrap;
$Text::Wrap::unexpand=0; # don't insert tabs

# make sure, git repository is clean
my $dirty = `git status --porcelain`;
die "git repository is dirty\n" if $dirty;

# get current version distribution
my $dist = do { local( @ARGV, $/ ) = 'dist.ini'; <> };
my $cur_version = $1 if $dist =~ /^\s*version\s*=\s*([^\s]+)/m;
$cur_version or die 'current version not found in dist.ini';

# get current prefixes
my $cur = RDF::NS->LOAD( "share/prefix.cc", warn => 1 );
die "share/prefix.cc is empty" unless %$cur;

# get new current datestamp
my @t = gmtime;
my $new_version = sprintf '%4d%02d%02d', $t[5]+1900, $t[4]+1, $t[3];
my $new_date = sprintf '%4d-%02d%-02d', $t[5]+1900, $t[4]+1, $t[3];
die "$new_version is not new" if $new_version eq $cur_version;

# download new prefixes
my $tmp = File::Temp->new->filename;
my $url = "http://prefix.cc/popular/all.file.txt";
mirror($url,$tmp) or die "Failed to load $url";
my $new = RDF::NS->LOAD( $tmp, warn => 1 );

my $diff = $new->UPDATE( "share/prefix.cc", $new_version );

foreach my $change (qw(create delete update)) {
    my $prefixes = $diff->{$change} or next;
    foreach my $prefix (@$prefixes) {
        if ($change eq 'create') {
            printf "+ $prefix %s\n", $new->URI($prefix);
        } elsif ($change eq 'delete') {
            printf "- $prefix %s\n", $cur->URI($prefix);
        } else {
            printf "- $prefix %s\n", $cur->URI($prefix);
            printf "+ $prefix %s\n", $new->URI($prefix);
        }
    }
}

my (@log) = "$new_version $new_date (" . $new->COUNT . " prefixes)";

sub prefix_list {
    my ($label, $list) = @_;
    return wrap(" - $label "," " x 12, join ' ', @$list);
}

push @log, prefix_list("added: ",$diff->{create}) if @{$diff->{create}};
push @log, prefix_list("removed:",$diff->{delete}) if @{$diff->{delete}};
push @log, prefix_list("changed:",$diff->{update}) if @{$diff->{update}};

foreach my $file (qw(dist.ini lib/RDF/NS.pm lib/RDF/NS/Trine.pm lib/RDF/NS/URIS.pm README.md)) {
    print "$cur_version => $new_version in $file\n";
    local ($^I,@ARGV)=('.bak',$file);
    while(<>) {
        s/$cur_version/$new_version/ig;
        print;
    }
}

my $msg = `git log --pretty=format:" - %s" $cur_version..`;

do {
    print "prepend modifications to Changes\n";
    local ($^I,@ARGV)=('.bak','Changes');
    my $line=0;
    while (<>) {
        if (!$line++) { # prepend
            print join '', map { "$_\n" } @log;
            print "\n$msg" if $msg;
            print "\n\n";
        }
        print;
    }
};

print `git add -u`;
print `git commit -m "update to $new_version"`;

1;
Something went wrong with that request. Please try again.