Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 97063fbc

Von Sven Schöling vor etwa 14 Jahren hinzugefügt

  • ID 97063fbce421678c56dc6ba98663ccb6b11a2ab5
  • Vorgänger 3c73035d
  • Nachfolger 5f4e1aba

Mehrere Fehler behoben und Texte leichter lesbar gemacht.

- require kann keine Versionierung, also muss das mit use gemacht werden.
- eval + defined Bugs durch idiomatischere Konstrukte ersetzt.
- gefühlte 500 Zeilen IO::File Code durch ein idiomatisches slurp ersetzt.
- Die Meldungen wenn ein Paket nicht gefunden wurden sind jetzt mit einem
freundlichen Kasten umrahmt, und damit in der Textmasse einfacher
auszumachen.
- Es können jetzt mehrere Sourcen an die module Definition angehängt werden.

Unterschiede anzeigen:

SL/InstallationCheck.pm
7 7

  
8 8
use strict;
9 9

  
10
BEGIN {
10 11
@required_modules = (
11 12
  { name => "parent",                              url => "http://search.cpan.org/~corion/" },
12
  { name => "Archive::Zip",                        url => "http://search.cpan.org/~adamk/" },
13
  { name => "Archive::Zip",   version => 12,       url => "http://search.cpan.org/~adamk/" },
13 14
  { name => "Class::Accessor",                     url => "http://search.cpan.org/~kasei/" },
14 15
  { name => "CGI::Ajax",                           url => "http://search.cpan.org/~bct/" },
15 16
  { name => "DateTime",                            url => "http://search.cpan.org/~drolsky/" },
......
30 31

  
31 32
@optional_modules = ();
32 33

  
34
$_->{fullname} = join ' ', grep $_, @$_{qw(name version)}
35
  for @required_modules, @optional_modules;
36
}
37

  
33 38
sub module_available {
34 39
  my $module  = $_[0];
35 40
  my $version = $_[1] || '' ;
36 41

  
37
  if (!defined(eval("require $module $version;"))) {
38
    return 0;
39
  } else {
40
    return 1;
41
  }
42
  return eval "use $module $version; 1";
42 43
}
43 44

  
44 45
my %conditional_dependencies;
45 46

  
46 47
sub check_for_conditional_dependencies {
47
  if (!$conditional_dependencies{net_ldap}) {
48
    $conditional_dependencies{net_ldap} = 1;
49

  
50
    my $in = IO::File->new('config/authentication.pl', 'r');
51
    if ($in) {
52
      my $self = {};
53
      my $code;
54

  
55
      while (my $line = <$in>) {
56
        $code .= $line;
57
      }
58
      $in->close();
59

  
60
      eval $code;
48
  return if $conditional_dependencies{net_ldap}++;
61 49

  
62
      if (! $EVAL_ERROR) {
50
  my $self = {};
51
  eval do { local (@ARGV, $/) = 'config/authentication.pl'; <> } or return;
63 52

  
64
        if ($self->{module} && ($self->{module} eq 'LDAP')) {
65
          push @required_modules, { 'name' => 'Net::LDAP', 'url' => 'http://search.cpan.org/~gbarr/' };
66
        }
67
      }
68
    }
69
  }
53
  push @required_modules, { 'name' => 'Net::LDAP', 'url' => 'http://search.cpan.org/~gbarr/' }
54
    if $self->{module} && ($self->{module} eq 'LDAP');
70 55
}
71 56

  
72 57
sub test_all_modules {
scripts/installation_check.pl
1 1
#!/usr/bin/perl -w
2 2

  
3
use strict;
4

  
3 5
BEGIN {
4 6
  unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
5 7
  push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
......
9 11

  
10 12
$| = 1;
11 13

  
12
foreach my $module (@SL::InstallationCheck::required_modules) {
13
  if ($module->{version}) {
14
    print("Looking for $module->{name} $module->{version}...");
15
  } else {
16
    print("Looking for $module->{name}...");
17
  }
18
  if (!SL::InstallationCheck::module_available($module->{"name"})) {
19
    print(" NOT found\n" .
20
          "  The module '$module->{name}' is not available on your system.\n" .
21
          "  Please install it with the CPAN shell, e.g.\n" .
22
          "    perl -MCPAN -e \"install $module->{name}\"\n" .
23
          "  or download it from this URL and install it manually:\n" .
24
          "    $module->{url}\n\n");
25
  } else {
26
    print(" ok\n");
27
  }
14
check($_, 0) for @SL::InstallationCheck::required_modules;
15
check($_, 1) for @SL::InstallationCheck::optional_modules;
16

  
17
sub check {
18
  my ($module, $optional) = @_;
19

  
20
  print "Looking for $module->{fullname}...";
21
  my $res = SL::InstallationCheck::module_available($module->{"name"}, $module->{version});
22
  print $res ? '' : " NOT", " ok\n";
23

  
24
  return if $res;
25

  
26
  my $needed_text = $optional
27
    ? 'It is OPTIONAL for Lx-Office but recommended for improved functionality.'
28
    : 'It is NEEDED by Lx-Office and must be installed.';
29

  
30
  my @source_texts = source_texts($module);
31
  local $" = $/;
32
  print <<EOL;
33
+-----------------------------------------------------------------------------+
34
  $module->{fullname} could not be loaded.
35

  
36
  This module is either too old or not available on your system.
37
  $needed_text
38

  
39
  Here are some ideas how to get it:
40

  
41
@source_texts
42
+-----------------------------------------------------------------------------+
43
EOL
28 44
}
29 45

  
30
foreach my $module (@SL::InstallationCheck::optional_modules) {
31
  print("Looking for $module->{name} (optional)...");
32
  if (!SL::InstallationCheck::module_available($module->{"name"})) {
33
    print(" NOT found\n" .
34
          "  The module '$module->{name}' is not available on your system.\n" .
35
          "  While it is not strictly needed it provides extra functionality\n" .
36
          "  and should be installed.\n" .
37
          "  You can install it with the CPAN shell, e.g.\n" .
38
          "    perl -MCPAN -e \"install $module->{name}\"\n" .
39
          "  or download it from this URL and install it manually:\n" .
40
          "    $module->{url}\n\n");
41
  } else {
42
    print(" ok\n");
43
  }
46
sub source_texts {
47
  my ($module) = @_;
48
  my @texts;
49
  push @texts, <<EOL;
50
  - You can get it from CPAN:
51
      perl -MCPAN -e "install $module->{name}"
52
EOL
53
  push @texts, <<EOL if $module->{url};
54
  - You can download it from this URL and install it manually:
55
      $module->{url}
56
EOL
57
  push @texts, <<EOL if $module->{debian};
58
  - On Debian, Ubuntu and other distros you can install it with apt-get:
59
      sudo apt-get install $module->{debian}
60
    Note these may be out of date as well if you system is old.
61
EOL
62
 # TODO: SuSE and Fedora packaging. Windows packaging.
63

  
64
  return @texts;
44 65
}

Auch abrufbar als: Unified diff