source: branches/2.2.10/mindi/mindi-get-perl-modules @ 2635

Last change on this file since 2635 was 2635, checked in by Bruno Cornec, 10 years ago

svn merge -r 2586:2634 svn+ssh://bruno@svn.mondorescue.org/mondo/svn/mondorescue/branches/2.2.9

  • Avoids error messages from stat in analyze-my-lvm
  • Avoid perl warning by removing non-exitent dirs from @INC in mindi-get-perl-modules r3744@localhost: bruno | 2010-03-16 01:44:33 +0100
    • Fix a bug on Mandriva modules analysis (at least) (Backport from mindi 2.1.0)
  • Try to improve exclusion of binded /proc mount with "none" fs type exclusion Cf: #397
  • Adds gmane mirror on the support page of the web site.
  • More website improvements based on Tom Metro feedbacks
  • Adds Nable ML archive
  • For gmane prefer the threaded view to the blog one.
  • Fix an initialization bug for network protocol in interactive mode (was NULL and not NFS by default)
  • Put an explicit notice of MondoRescue?'s license: GPLv2 or later (as per Hugo's notice in sources)
  • Adds tee to deplist
  • Fix #412 by supporting grub-install.unsupported for OpenSuSE and solving an issue with the parameter passed to grub for device which should be a device name, not a partition.
  • Fix #413 where list of devices was not re-initialized correctly in a loop (Michael Shapiro)
  • Fix #415 by avoiding integration of unknown devices report from pvscan (Mike Shapiro)
  • Fix #414 by adding a function GetPVsForLV to remove PVs from excluded LVs (Mike Shapiro)
  • Fixes for #414: remove comments from grub conf file if used and improve grub conf file generation
  • Fix a typo (Mike Shapiro)
  • Improved msg for USB device creation
  • Mondoarchive should not try to cerate a cmp binary if it doesn't exist.
  • Fix a bug on ia64 where the boot image generated was removed before use in mondo
  • Avoid to have multiple similar calls to mkisofs by using macros r3946@localhost: bruno | 2010-05-04 19:17:51 +0200
    • Solves an issue with usage of -V option in mkiofs wrongly placed
  • netfs_proto should be initialized in every case, not just in DR (should solve remaining NULL reports)
  • Integrate Michael Shapiro's patch on Xen Kernel support for RHEL 5 (only atm) and fixes #418 (Michael Shapiro)
  • Fox a typo in a Web page
  • Precise that GPL is v2+ (as per Hugo's wish)
  • Improve display of messages (removes extra \n) and replace a stract with "" with " ". trying to debug #421
  • Remove a wrong usage of mr_strcat with exclude_path in the 2.2.9 version (probably cause of #421)
  • Fix strcat call !
  • Property svn:executable set to *
File size: 6.1 KB
Line 
1#!/usr/bin/perl -w
2#
3# Get perl modules required by mindi and mondo and that should be on the restore media
4#
5use strict;
6
7use File::Find;
8
9my $file = get_perl_modules(@ARGV) if (defined $ARGV[0]);
10
11foreach my $f (sort keys %$file) {
12    print "$f\n";
13}
14
15sub get_perl_modules {
16
17my %files;
18
19#print "Searching in ";
20#print join "\n", @INC;
21
22my $require = process_file(@_);
23
24my @includes;
25
26# Remove non exiting directories from @INC
27# and thus avoid perl warnings
28#
29foreach my $d (@INC) {
30    push @includes,$d if (-d $d);
31}
32
33find(
34    sub {
35        if ((-f $File::Find::name) 
36            && (/\.pm$/) 
37            && (not defined $files{$File::Find::name})) {
38            foreach my $m (keys %$require,"warnings") {
39                (my $mod = $m) =~ s|::|/|g;
40                #print "Looking at $mod in $File::Find::name\n";
41                if (index($File::Find::name,"$mod.pm") ne -1) {
42                    $files{$File::Find::name} = $mod;
43                    #push @files, $File::Find::name;
44                    #print "Found $mod in $File::Find::name\n";
45                    last;
46                }
47            }
48        }
49    },
50    @includes);
51
52return(\%files);
53}
54
55# Adapted From /usr/lib/rpm/mandriva/perl.req
56# by Ken Estes Mail.com kestes@staff.mail.com
57
58sub process_file {
59 
60    my %line;
61    my %require;
62    my $current_line;
63    my $tag;
64
65    foreach my $file (@_) {
66 
67  open(FILE, "<$file") || return(\%require);
68 
69  while (<FILE>) {
70   
71    # skip the "= <<" block
72
73    if ( ( m/^\s*\$(.*)\s*=\s*<<\s*["'](.*)['"]/i) ||
74         ( m/^\s*\$(.*)\s*=\s*<<\s*(.*);/i) ) {
75      $tag = $2;
76      while (<FILE>) {
77        ( $_ =~ /^$tag/) && last;
78      }
79    }
80
81    # skip the documentation
82
83    # we should not need to have item in this if statement (it
84    # properly belongs in the over/back section) but people do not
85    # read the perldoc.
86
87    if ( (m/^=(head1|head2|pod|item)/) .. (m/^=(cut)/) ) {
88      next;
89    }
90
91    if ( (m/^=(over)/) .. (m/^=(back)/) ) {
92      next;
93    }
94   
95    # skip the data section
96    if (m/^__(DATA|END)__$/) {
97      last;
98    }
99
100    # Each keyword can appear multiple times.  Don't
101    #  bother with datastructures to store these strings,
102    #  if we need to print it print it now.
103   
104    if ( m/^\s*\$RPM_Requires\s*=\s*["'](.*)['"]/i) {
105      foreach $_ (split(/\s+/, $1)) {
106    print "$_\n";
107      }
108    }
109
110    if ( 
111
112# ouch could be in a eval, perhaps we do not want these since we catch
113# an exception they must not be required
114
115#   eval { require Term::ReadLine } or die $@;
116#   eval "require Term::Rendezvous;" or die $@;
117#   eval { require Carp } if defined $^S; # If error/warning during compilation,
118
119
120    (m/^(\s*)         # we hope the inclusion starts the line
121     (require|use)\s+(?!\{)     # do not want 'do {' loops
122     # quotes around name are always legal
123     [\'\"]?([^\;\ \'\"\t]*)[\'\"]?[\t\;\ ]
124     # the syntax for 'use' allows version requirements
125     \s*([.0-9]*)
126     /x)
127       ) {
128      my ($whitespace, $statement, $module, $version) = ($1, $2, $3,$4);
129      my $usebase;
130
131      # we only consider require statements that are flush against
132      # the left edge. any other require statements give too many
133      # false positives, as they are usually inside of an if statement
134      # as a fallback module or a rarely used option
135
136      ($whitespace ne "" && $statement eq "require") && next;
137
138      # if there is some interpolation of variables just skip this
139      # dependency, we do not want
140      #        do "$ENV{LOGDIR}/$rcfile";
141
142      ($module =~ m/\$/) && next;
143
144      # skip if the phrase was "use of" -- shows up in gimp-perl, et al
145      next if $module eq 'of';
146
147      # if the module ends in a comma we probaly caught some
148      # documentation of the form 'check stuff,\n do stuff, clean
149      # stuff.' there are several of these in the perl distribution
150
151      ($module  =~ m/[,>]$/) && next;
152
153      # if the module name starts in a dot it is not a module name.
154      # Is this necessary?  Please give me an example if you turn this
155      # back on.
156
157      #      ($module =~ m/^\./) && next;
158
159      # if the module ends with .pm strip it to leave only basename.
160      # starts with /, which means its an absolute path to a file
161      if ($module =~ m(^/)) {
162        print "$module\n";
163        next;
164      }
165
166      # as seen in some perl scripts
167      # use base qw(App::CLI Class::Accessor::Chained::Fast App::CLI::Command);
168      if ($module eq 'base') {
169      $require{$module} = $version;
170      $line{$module} = $current_line;
171      ($module = $_) =~ s/use\s*base\s*//;
172      $module =~ s/qw\((.*)\)\s*;/$1/;
173      $module =~ s/qw(.)(.*)\1\s*;/$2/;
174      $module =~ s/\s*;$//;
175      $module =~ s/#.*//;
176      $usebase = 1;
177      }
178      # sometimes people do use POSIX qw(foo), or use POSIX(qw(foo)) etc
179      # we can strip qw.*$, as well as (.*$:
180      $module =~ s/qw.*$//;
181      $module =~ s/\(.*$//;
182
183      $module =~ s/\.pm$//;
184
185      # some perl programmers write 'require URI/URL;' when
186      # they mean 'require URI::URL;'
187
188      $module =~ s/\//::/;
189
190      # trim off trailing parenthesis if any.  Sometimes people pass
191      # the module an empty list.
192
193      $module =~ s/\(\s*\)$//;
194
195      # if module is a number then both require and use interpret that
196      # to mean that a particular version of perl is specified. Don't
197      # add a dependency, though, since the rpm will already require
198      # perl-base at the build version (via find-requires)
199      next if $module =~ /^v?\d/;
200
201      # ph files do not use the package name inside the file.
202      # perlmodlib  documentation says:
203      #       the .ph files made by h2ph will probably end up as
204      #       extension modules made by h2xs.
205      # so do not spend much effort on these.
206
207      # there is no easy way to find out if a file named systeminfo.ph
208      # will be included with the name sys/systeminfo.ph so only use the
209      # basename of *.ph files
210
211      ($module  =~ m/\.ph$/) && next;
212
213      # if the module was loaded trough base, we need to split the list
214      if ($usebase) {
215          my $current_line = $_;
216          foreach (split(/\s+/, $module)) {
217              next unless $_;
218              $require{$_} = $version;
219              $line{$_} = $current_line;
220          }
221      } else {
222      $require{$module}=$version;
223      $line{$module}=$current_line;
224      }
225    }
226  }
227
228  close(FILE) ||
229    die("$0: Could not close file: '$file' : $!\n");
230    }
231
232  return(\%require);
233}
Note: See TracBrowser for help on using the repository browser.