File: check-upstream-versions

package info (click to toggle)
libcgi-application-extra-plugin-bundle-perl 0.1%2Bnmu1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 376 kB
  • ctags: 7
  • sloc: perl: 166; sh: 54; makefile: 45
file content (178 lines) | stat: -rwxr-xr-x 6,231 bytes parent folder | download | duplicates (2)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/perl -w

use strict;
use File::Glob qw/:glob/;
use File::Basename;
use File::Copy;
use Data::Dump qw/pp dump/;
use LWP::Simple; 
use List::Util qw/maxstr max/;
use Config::General;
use Text::SimpleTable;
use Text::Wrap;

$Text::Wrap::columns = 78;
$Text::Wrap::separator = "\n ";
my %indexes  = ();

my %cfg = Config::General->new( -ConfigFile => 'packages.cfg' )->getall;

#--- switch off buffering
$|++;

#----------------------------------------------------------------------------
# add/update packages & numbers to debian/control file
#----------------------------------------------------------------------------
sub control($$) {    
    my ($files, $config) = @_;
    my $control = '../debian/control';
    my $output = '';
    my $copyright  = '../debian/copyright';
    my $coutput = $config->{'debcopystart'}."\n";
        
    open( FD, '<', $control ) or die "Cannot open $control\n";
    my @lines = <FD>;
    close( FD );
                        
    for my $line (@lines) {	
        $output .= $line;
        if ($line =~ /Currently the following modules are included/) {

            for my $file (@$files) {
                my ($dir, $base, $version, $suffix) = 
                    $file =~ m!(\d+)/(.+)\-([\d\.]+)(\.tar\.gz)!;
                my $key = $base;
                $base =~ s/\-/::/g;
                $output .= qq{ .\n $base\n };
                                
                #--- get data from config file and prepare output
                if (defined $config->{$key}->{'description'}) {
                    $output .= 
                        wrap("","",$config->{$key}->{'description'})."\n";
                }
                else {
                    print "$key not exist in config file or has not defined 'description' section\n";					
                    exit(1);
                }
                if (defined $config->{$key}->{'author'}) {
                    $coutput .= qq{\n* $base\n};
                    if (ref($config->{$key}->{'author'}) eq 'ARRAY') {
                        $coutput .= qq{\nAuthors:\n};
                        foreach  my $author (@{$config->{$key}->{'author'}}) {
                            $coutput .= qq{\t$author\n};
                        }
                    }
                    else {
                        $coutput .= 
                            qq{\nAuthor:\n\t$config->{$key}->{'author'}\n};
                    }
                }
                else {
                    print "$key not exist in config file or has not defined 'author' section\n";					
                    exit(1);
                }
                if (defined $config->{$key}->{'copyright'}) {
                    if (ref($config->{$key}->{'copyright'}) eq 'ARRAY') {
                        foreach  my $copyright (@{$config->{$key}->{'copyright'}}) {
                            $coutput .= qq{\t$copyright\n};
                        }
                    }
                    else {
                        $coutput .= "\n ".wrap("", "", $config->{$key}->{'copyright'})."\n";
                        $coutput .= "\n ".wrap("", "", $config->{'debcopyinfo'})."\n";
                    }
                }
            }
            last;
        }				
    }
    $coutput .= "\n".$config->{'debcopyright'};
    open( FD, '>', $control.".new" ) or die "Cannot open $control.new\n";
    print FD $output;
    close( FD );
    move($control.".new", $control);

    open( FD, '>', $copyright ) or die "Cannot open $copyright\n";
    print FD $coutput;
    close( FD );
}

#----------------------------------------------------------------------------
# check upstream versions
#----------------------------------------------------------------------------
sub check($$) {
    my ($files, $config) = @_;
    my @urls = ();
    my %seen;

    my $table = Text::SimpleTable->new([3, 'Dir'], [50, 'Module'], [10, 'Debian'], [10, 'Upstream'], [20, 'Comment']);

    for my $file (@$files) {
        my $current_version = 0;
        my $upstream_version = 'missing';
        my $upstream_link = "";		
        
        #--- check package's current version 
        my ($dir, $base, $version, $suffix) = $file =~ m!(\d+)/(.+)\-([\d\.]+)(\.tar\.gz)!;		
                
        $current_version = $version;
        #--- check if watch exist, read url	
        if (defined $config->{$base}->{'watch'}) {
            my $url = $config->{$base}->{'watch'};
                        
            #--- get "directory" part & "file" part
            my ($u_dir, $u_file) = $url =~ m!(.+/)(.+)$!;
                        
            #--- now take index file with directories
            unless (defined($indexes{$u_dir})) {
                #--- cache result
                print "Getting $u_dir...";
                $indexes{$u_dir} = get($u_dir);
                print "Done\n";
            }

            my @found = $indexes{$u_dir} =~ m!$u_file!g;
            $upstream_version = maxstr(@found);
            $upstream_link = qq{$u_dir/$base-$upstream_version.tar.gz}; 
        }
        else {
            print "$file not exist in config file or has not defined 'watch' section\n";
            exit(1);
        }
                
        my $comment;
        $comment = "up to date" if ($current_version == $upstream_version);
        $comment = "newer than upstream version!" if ($current_version > $upstream_version);
        if ($current_version < $upstream_version) {
            $comment =  "new upstream version!";
            push @urls,	qq{$dir $upstream_link};
        }
        $table->row($dir, $base, $current_version, $upstream_version, $comment);
        $seen{$base}++;
    }	

    print $table->draw;
    if (scalar@urls) {
        for my $url (@urls) {
            print $url."\n";
        }
    }
    foreach my $key (keys %seen) {
        if ($seen{$key} > 1) {
            print qq{$key is more than once in directory!\n}; 
        }
    }
}

if (defined($ARGV[0])) {
    if ($ARGV[0] eq 'control') {
        #--- add/update packages & numbers to debian/control file
        my @f = bsd_glob('??/*.tar.gz');
        control( \@f, \%cfg );
    }	
}
else {
    #--- check upstream versions
    my @f = bsd_glob('??/*.tar.gz');
    check( \@f, \%cfg );
}