summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/tl-dump-for-ctan
blob: 4975767c89e2217ebfb816d5e233ba1fdb79a9ec (plain)
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
#!/usr/bin/env perl
# Copyright 2010 Norbert Preining
# This file is licensed under the GNU General Public License version 2
# or any later version.
# 
# From an email from Karl:
# Jim Hefferon could use a dump of TL packages for CTAN with one line per
# package, showing the package name, collection it belongs to, and all its
# schemes.

my $mydir;

BEGIN {
  $vc_id = '$Id$';
  $^W = 1;
  ($mydir = $0) =~ s,/[^/]*$,,;
  unshift (@INC, "$mydir/..");
}

use strict;
use TeXLive::TLPOBJ;
use TeXLive::TLPDB;
use TeXLive::TLUtils;

exit (&main());


sub main
{
  chomp(my $Master = `cd $mydir/../.. && pwd`);
  my $tlpdb = TeXLive::TLPDB->new("root" => $Master);
  die "Cannot init tlpdb from $Master ..." unless defined($tlpdb);

  # first collect for each collection the set of schemes it is contained in
  my @schemes = $tlpdb->schemes;
  my %col_to_schemes;
  foreach my $c ($tlpdb->collections) {
    @{$col_to_schemes{$c}} = ();
    for my $s ($tlpdb->needed_by($c)) {
      if ($s =~ m/^scheme-/) {
        push @{$col_to_schemes{$c}}, $s;
      }
    }
  }
  foreach my $pkg ($tlpdb->list_packages) {
    next if ($pkg =~ m/^00texlive/);
    # ignore *all* arch dep pacakges (also tlpsv etc etc)
    next if ($pkg =~ m/\./);
    my $tlp = $tlpdb->get_package($pkg);
    if (!defined($tlp)) {
      printf STDERR "strange, $pkg not found but listed, continuing anyway.\n";
      next;
    }
    next if ($tlp->category eq "Scheme");
    next if ($tlp->category eq "Collection");
    # TODO ??? What to do with TLCore???
    # get the list of packages that depend on that one:
    my @deps = $tlpdb->needed_by($pkg);
    my @schemes;
    my $collection = undef;
    for my $p (@deps) {
      my $tlpo = $tlpdb->get_package($p);
      if (!defined($tlpo)) {
        printf STDERR "$p seems to depend on $pkg, but $p cannot be found?\n";
        next;
      }
      if ($tlpo->category eq "Scheme") {
        push @schemes, $p;
      } elsif ($tlpo->category eq "Collection") {
        if (defined($collection)) {
          printf STDERR "$pkg is asked for in more than one collection: $collection, $p\n";
          next;
        } else {
          $collection = $p;
        }
      }
    }
    if (!defined($collection)) {
      # should not happen
      $collection = "(undefined)";
    } else {
      push @schemes, @{$col_to_schemes{$collection}};
    }
    @schemes = TeXLive::TLUtils::sort_uniq(@schemes);
    print "$pkg $collection @schemes\n";
  }
}


__END__

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2 expandtab: #