Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 92 lines (75 sloc) 2.721 kb
#!/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;
Jump to Line
Something went wrong with that request. Please try again.