Packaging/Utilities

From openSUSE

< Packaging(Difference between revisions)
Revision as of 00:18, 1 November 2009
Computersalat (Talk | contribs)
Migration of %changelog data from ''.spec'' to a ''.changes'' file
� Previous diff
Current revision
Pbleser (Talk | contribs)

Line 2: Line 2:
== Migration of %changelog data from ''.spec'' to a ''.changes'' file == == Migration of %changelog data from ''.spec'' to a ''.changes'' file ==
 +
 +Simpler, better version: http://linux01.gwdg.de/~pbleser/files/rpm/spec2changes.pl
this could be done with a small script. this could be done with a small script.

Current revision

Utilities

Migration of %changelog data from .spec to a .changes file

Simpler, better version: http://linux01.gwdg.de/~pbleser/files/rpm/spec2changes.pl

this could be done with a small script. I tested with several spec files and got nearly all changes migrated to .changes file. use it on your own risk.


#!/usr/bin/perl -w
#
# Migrate .spec %changelog to .changes file
#
#BEGIN {
#  unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
#}
#
use strict;
#
if(!@ARGV) {
 print "need a filename as argument, otherwise I can't do anything ;)\n";
 print "all data will be printed to STDOUT\n\n";
 print "spec2changes.pl [path_to/file.spec]\nor\n";
 print "spec2changes.pl [path_to/file.spec] > ./new_file.changes\n";
 exit(1);
}
#
my $file=$ARGV[0];
#
my $wday;
my $mon;
my $day;
my $year;
my $who;
my $e_line="\n";
my $s_line="-------------------------------------------------------------------\n";
my @spec=();
my @changes=();
#
# spec has no time, so we generate some random ;)
my $h_range=24;
my $h_rand;
my $m_range=60;
my $m_rand;
my $s_range=$m_range;
my $s_rand;
#
sub rand_time {
 $h_rand = int(rand($h_range));
 if($h_rand < 10){ $h_rand="0$h_rand"; }
 $m_rand = int(rand($m_range));
 if($m_rand < 10){ $m_rand="0$m_rand"; }
 $s_rand = int(rand($s_range));
 if($s_rand < 10){ $s_rand="0$s_rand"; }
}
#
sub push_changes {
 rand_time;
 my $data="$1 $2 $3 $h_rand\:$m_rand\:$s_rand CET $4 - $5";
 # add empty line
 push(@changes, $e_line);
 # add separator
 push(@changes, $s_line);
 # add date line
 push(@changes, "$data");
 # add emty line
 push(@changes, $e_line);
}
#
open(FH, "$file") || die ("$file: $!\n");
while (<FH>) {
 chomp;
 next if ((/^#/) || (/^--/));
 next if ((!/^\*/) && (!/^\s+(\*|o|-)/) && (!/^-/));
 #print "$_\n";
 push(@spec, $_);
}
close(FH);
#
foreach(@spec){ 
 # match "* Sun Jan 13 2009 - <name-chris1.de@domain-name2.de.com.net> 1.14"
 if ( ($wday,$mon,$day,$year,$who) = m/^\*\s([A-Za-z]{3})\s([A-Za-z]{3})\s([0-9]{1,2})\s([0-9]{4})\s.?\s?[<({]?([A-Za-z0-9.-]{1,}\@[A-Za-z0-9.-]{1,})[>)}]?\s.+$/ ) {
   #print "$wday $mon $day $year $who,\n";
   push_changes($wday,$mon,$day,$year,$who);
   next;
 }
 # match "* Sun Jan 13 2009 - <name-chris1.de@domain-name2.de.com.net>"
 if ( ($wday,$mon,$day,$year,$who) = m/^\*\s([A-Za-z]{3})\s([A-Za-z]{3})\s([0-9]{1,2})\s([0-9]{4})\s.?\s?[<({]?([A-Za-z0-9.-]{1,}\@[A-Za-z0-9.-]{1,})[>)}]?\s?$/ ) {
   #print "$wday $mon $day $year $who,\n";
   push_changes($wday,$mon,$day,$year,$who);
   next;
 }
 # match "* Sun Nov 05 2006 Peter Neon <peter+rpmspam@domain.com.tr> - 1.6.8"
 if ( ($wday,$mon,$day,$year,$who) = m/^\*\s([A-Za-z]{3})\s([A-Za-z]{3})\s([0-9]{1,2})\s([0-9]{4})\s[A-Za-z-]{1,}\s[A-Za-z-]{1,}\s[<({]?([A-Za-z0-9.-]{1,}\+.*\@[A-Za-z0-9.-]{1,})[>)}]?\s.*$/ ) {
   #print "$wday $mon $day $year $who,\n";
   push_changes($wday,$mon,$day,$year,$who);
   next;
 }
 # match "* Wed Sep 14 2005 Lionel Dev <lionel-dev@domain.name> - 1.6.7"
 if ( ($wday,$mon,$day,$year,$who) = m/^\*\s([A-Za-z]{3})\s([A-Za-z]{3})\s([0-9]{1,2})\s([0-9]{4})\s[A-Za-z-]{1,}\s[A-Za-z-]{1,}\s[<({]?([A-Za-z0-9.-]{1,}\@[A-Za-z0-9.-]{1,})[>)}]?\s.*$/ ) {
   #print "$wday $mon $day $year $who,\n";
   push_changes($wday,$mon,$day,$year,$who);
   next;
 }
 # match "* Wed Sep 14 2005 Lionel Dev <lionel-dev@domain.name>"
 if ( ($wday,$mon,$day,$year,$who) = m/^\*\s([A-Za-z]{3})\s([A-Za-z]{3})\s([0-9]{1,2})\s([0-9]{4})\s[A-Za-z-]{1,}\s[A-Za-z-]{1,}\s[<({]?([A-Za-z0-9.-]{1,}\@[A-Za-z0-9.-]{1,})[>)}]?\s?$/ ) {
   #print "$wday $mon $day $year $who,\n";
   push_changes($wday,$mon,$day,$year,$who);
   next;
 }
 #print "$_\n";
 # add changes for this date
 push(@changes, "$_\n");
}
#
foreach(@changes){
 print $_;
}
exit(0);