Merge pull request #104 from douglasgscofield/master
[bioperl-live.git] / maintenance / deprecated.pl
blob880f4481bd393be659d59a3ef5a35b98485fe5d2
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use version;
7 use Bio::Root::Version;
8 use File::Find;
9 use Getopt::Long;
10 use Perl6::Form;
11 use Carp;
14 # command line options
17 my ($verbose, $dir, $depfile, $help, $new, $outfile, $write, $version) =
18 (0, undef, "../DEPRECATED", undef, [], '../DEPRECATED.NEW', 0, $Bio::Root::Version::VERSION);
19 GetOptions(
20 'v|verbose' => \$verbose,
21 'b|bp_version:s' => \$version,
22 'dir:s' => \$dir,
23 'depfile:s' => \$depfile,
24 'n|new=s@' => \$new,
25 'o|outfile:s' => \$outfile,
26 'w|write' => \$write,
27 'h|help|?' => sub{ exec('perldoc',$0); exit(0) }
30 # Default directories to check
31 my @dirs = qw(../Bio/ );
33 # use version to consolidate old vs new versioning schemes
34 my $base_version = version->new( $version );
36 print "Version: $base_version\n";
38 my %deprecated;
39 my %removed;
40 my @dep_data;
42 # parse DEPRECATED file
44 open my $DFILE, '<', $depfile or die "Could not read file '$depfile': $!\n";
45 my $seen_top;
46 while (my $data = <$DFILE>) {
47 if ($data =~ /^-+$/) {
48 $seen_top = 1;
49 next;
51 next unless $seen_top;
52 chomp $data;
53 my ($module, $dep, $rem, $note) = split(/\s+/,$data,4);
54 next unless $module;
55 my $d = version->new($dep);
56 my $r = version->new($rem);
57 print "$module Dep: $d Rem: $r\n" if $verbose;
58 if ($rem <= $base_version) {
59 $removed{$module}++;
60 } elsif ($dep <= $base_version) {
61 $deprecated{$module}++;
63 push @dep_data, {module => $module,
64 dep => $dep,
65 remove => $rem,
66 note => $note}
68 close $DFILE;
70 for my $new (@$new) {
71 my ($module, $dep, $rem, $note) = split(',',$new,4);
72 last if !$module || !$dep || !$rem;
73 if ($module !~ /Bio/) {
74 croak "Can only deprecate BioPerl modules, not $module"
76 push @dep_data, {module => $module,
77 dep => $dep,
78 remove => $rem,
79 note => $note}
82 # run through all files in core (checks to see if anything is still present)
84 if ($dir) {
85 find {wanted => \&parse_core, no_chdir => 1}, $dir;
86 } else {
87 find {wanted => \&parse_core, no_chdir => 1}, @dirs;
91 # results
94 # uses Perl6::Form
96 if ($write || @$new) {
98 open my $NEWDEP, '>', $outfile or croak "Could not write file '$outfile': $!\n";
100 print $NEWDEP <<HEAD;
101 # These are modules which are deprecated and later removed from the toolkit
102 # See http://www.bioperl.org/wiki/Deprecated_modules for the latest details
104 HEAD
106 # may replace with better formatting, but it needs to be round-tripped
108 print $NEWDEP form
109 "Deprecated Version Version ",
110 "Module Deprecated Removed Notes ",
111 "----------------------------------------------------------------------------------------------";
113 for my $datum (@dep_data) {
114 my ($mod, $dep, $rem, $note) = map {$datum->{$_}} qw (module dep remove note);
116 print $NEWDEP form
117 "{[[[[[[[[[[[[[[[[[[[[[[[[[[[[[} {|||||} {|||||} {[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[}",
118 $mod, $dep, $rem, $note;
125 ### end main
130 # this is where the action is
133 sub parse_core {
134 my $file = $_;
135 return unless $file =~ /\.PLS$/ || $file =~ /\.p[ml]$/ ;
136 return unless -e $file;
137 open my $F, '<', $file or die "Could not read file '$file': $!\n";
138 while (my $line = <$F>) {
139 if ($line =~ /(?:['"])?\b(use|require)\s+([A-Za-z0-9:_\.\(\)]+)\s*([^;'"]+)?(?:['"])?\s*;/) {
140 my ($use, $mod) = ($1, $2);
141 if (exists $removed{$mod}) {
142 print "$File::Find::name: Line $.: $mod is removed\n";
143 } elsif (exists $deprecated{$mod}) {
144 print "$File::Find::name: Line $.: $mod is deprecated\n";
148 close $F;
151 # $Id: deprecated.pl 10084 2006-07-04 22:23:29Z mauricio $
153 =head1 NAME
155 deprecated.pl - Check modules and scripts for use of deprecated modules and
156 methods, indicates presence in a file to STDERR. Optionally accepts new modules
157 and adds them to a newly formatted deprecation file.
159 =head1 SYNOPSIS
161 B<deprecated.pl> [B<-d|--dir> path ] [B<-v|--verbose>] [B<-a|--depfile>]
162 [B<-n|--new>] [B<-w|--write>] [B<-o|--outfile>]
163 [B<-?|-h|--help>]
165 =head1 OPTIONS
167 =over 3
169 =item B<-d | --dir> path
171 Overides the default directories to check by one directory 'path' and
172 all its subdirectories.
174 =item B<-a | --depfile>
176 path from working directory that contains the DEPRECATED file.
178 =item B<-n | --new>
180 New addition to the deprecation list; this should be in the form of
181 'Module,dep_release,remove_release,notes'. Notes should only be 40 chars long.
183 =item B<-b | --bp_version>
185 BioPerl version. This only appears to work correctly when using numerical
186 versions (1.5.2 instead of 1.005002)
188 =item B<-w | --write>
190 Write out new deprecation file to $outfile. If --new is used this is assumed.
192 =item B<-o | --outfile>
194 Name of output file to write deprecation table to. DEPRECATED.NEW is the default
195 name
197 =item B<-v | --verbose>
199 Show the progress through files during the checking.
201 =item B<-? | -h | --help>
203 This help text.
205 =back
207 =head1 FEEDBACK
209 =head2 Mailing Lists
211 User feedback is an integral part of the evolution of this and other
212 Bioperl modules. Send your comments and suggestions preferably to
213 the Bioperl mailing list. Your participation is much appreciated.
215 bioperl-l@bioperl.org - General discussion
216 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
218 =head2 Reporting Bugs
220 Report bugs to the Bioperl bug tracking system to help us keep track
221 of the bugs and their resolution. Bug reports can be submitted via the
222 web:
224 https://github.com/bioperl/bioperl-live/issues
226 =head1 AUTHOR - Chris Fields
228 Email cjfields-at-bioperl-dot-org
230 =cut