summaryrefslogtreecommitdiff
path: root/Master/tlpkg/etc/multi-source-support.diff
blob: ae2be97257933120339b8a3bd60739af776e0d92 (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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
--- /src/TeX/texlive-svn/Master/texmf/scripts/texlive/tlmgr.pl	2008-08-21 18:50:32.000000000 +0200
+++ texmf/scripts/texlive/tlmgr.pl	2008-08-29 12:21:45.000000000 +0200
@@ -37,7 +37,7 @@
 use TeXLive::TLUtils;
 use TeXLive::TLWinGoo;
 use TeXLive::TLPostActions;
-TeXLive::TLUtils->import( qw(kpsewhich member win32 merge_into copy log) );
+TeXLive::TLUtils->import( qw(kpsewhich member info give_ctan_mirror win32 merge_into copy log debug) );
 use Cwd qw/abs_path/;
 use Pod::Usage;
 use Getopt::Long qw(:config no_autoabbrev require_order);
@@ -45,15 +45,17 @@
 
 # used variables
 # the TLMedia from which we install/update
-my $tlmediasrc;
+my %tlmediasrc;
 # the tlpdb of the install media
-my $tlpdb;
+my %tlmediatlpdb;
+# flag indicating that the tlmedia has been loaded
+my $tlmedia_loaded = 0;
 # the local tlpdb
 my $localtlpdb;
 # a hash for saving the options saved into the local tlpdb
 my %options;
 # the location from where we install
-my $location;
+my @locations;
 
 # option handling
 my $opt_location;
@@ -411,16 +413,14 @@
   }
   init_local_db();
   foreach my $pkg (@ARGV) {
-    my $tlmediatlpdb;
     my $tlp = $localtlpdb->get_package($pkg);
     my $installed = 0;
     if (!$tlp) {
-      if (!$tlmediatlpdb) {
-        $tlmediasrc = TeXLive::TLMedia->new($location);
-        die($loadmediasrcerror . $location) unless defined($tlmediasrc);
-        $tlmediatlpdb = $tlmediasrc->tlpdb;
+      init_tlmedia();
+      for my $tlpdb (values(%tlmediatlpdb)) {
+        $tlp = $tlpdb->get_package($pkg);
+        last if ($tlp);
       }
-      $tlp = $tlmediatlpdb->get_package($pkg);
     } else {
       $installed = 1;
     }
@@ -446,32 +446,33 @@
              "file"   => \$opt_file) or pod2usage(2);
   my $r = shift @ARGV;
   my $ret = "";
-  my $tlpdb;
+  my @tlpdbs;
   init_local_db();
   if ($opt_global) {
-    $tlmediasrc =  TeXLive::TLMedia->new($location);
-    die($loadmediasrcerror . $location) unless defined($tlmediasrc);
-    $tlpdb = $tlmediasrc->tlpdb;
+    init_tlmedia();
+    @tlpdbs = values(%tlmediatlpdb);
   } else {
-    $tlpdb = $localtlpdb;
+    push @tlpdbs, $localtlpdb;
   }
-  foreach my $pkg ($tlpdb->list_packages) {
-    if ($opt_file) {
-      my @ret = grep(m;$r;, $tlpdb->get_package($pkg)->all_files);
-      if (@ret) {
-        print "$pkg:\n";
-        foreach (@ret) {
-          print "\t$_\n";
+  for my $tlpdb (@tlpdbs) {
+    for my $pkg ($tlpdb->list_packages) {
+      if ($opt_file) {
+        my @ret = grep(m;$r;, $tlpdb->get_package($pkg)->all_files);
+        if (@ret) {
+          print "$pkg:\n";
+          foreach (@ret) {
+            print "\t$_\n";
+          }
+        }
+      } else {
+        next if ($pkg =~ m/\./);
+        my $t = $tlpdb->get_package($pkg)->shortdesc;
+        $t |= "";
+        my $lt = $tlpdb->get_package($pkg)->longdesc;
+        $lt |= "";
+        if (($pkg =~ m/$r/) || ($t =~ m/$r/) || ($lt =~ m/$r/)) {
+          $ret .= " $pkg - $t\n";
         }
-      }
-    } else {
-      next if ($pkg =~ m/\./);
-      my $t = $tlpdb->get_package($pkg)->shortdesc;
-      $t |= "";
-      my $lt = $tlpdb->get_package($pkg)->longdesc;
-      $lt |= "";
-      if (($pkg =~ m/$r/) || ($t =~ m/$r/) || ($lt =~ m/$r/)) {
-        $ret .= " $pkg - $t\n";
       }
     }
   }
@@ -612,9 +613,7 @@
              "backupdir=s" => \$opt_backupdir,
              "dry-run" => \$opt_dry) or pod2usage(2);
   my %ret;
-  $tlmediasrc = TeXLive::TLMedia->new($location);
-  die($loadmediasrcerror . $location) unless defined($tlmediasrc);
-  my $mediatlpdb = $tlmediasrc->tlpdb;
+  init_tlmedia();
   my @todo;
   if ($opt_all || $opt_list) {
     @todo = $localtlpdb->list_packages;
@@ -634,18 +633,26 @@
       next;
     }
     my $rev = $tlp->revision;
-    my $mediatlp = $mediatlpdb->get_package($pkg);
-    if (!defined($mediatlp)) {
-      print "$pkg cannot be found in $location\n";
+    my ($maxsrc, $maxrev) = install_candidate($pkg);
+    if (!defined($maxsrc)) {
+      debug("$pkg cannot be found in any of @locations\n");
       next;
     }
-    my $mediarev = $mediatlp->revision;
-    if ($rev < $mediarev) {
+    if (!$maxsrc) {
+      print "$pkg: no installation candidate found!\n";
+      next;
+    }
+    # if $maxsrc is defined then there is an installation candidate with
+    # an higher revision number
+    if ($rev < $maxrev) {
+      my $tlmediasrc = $tlmediasrc{$maxsrc};
+      my $tlmediatlpdb = $tlmediatlpdb{$maxsrc};
+      my $mediarev = $maxrev;
       $nrupdated++;
       if ($opt_list) {
-        print "$pkg: local: $rev, source: $mediarev\n";
+        print "$pkg: local: $rev, source: $mediarev ($maxsrc)\n";
       } elsif ($opt_dry) {
-        print "Installing $pkg\n";
+        print "Installing $pkg ($maxsrc)\n";
       } else {
         # first remove the package, then reinstall it
         # this way we get rid of useless files
@@ -685,7 +692,7 @@
           # these packages cannot be upgrade on win32
           # so we have to create a update program
           my $media = $tlmediasrc->media;
-          my $remoteroot = $mediatlpdb->root;
+          my $remoteroot = $tlmediatlpdb->root;
           my $root = $localtlpdb->root;
           my $temp = "$root/temp";
           TeXLive::TLUtils::mkdirhier($temp);
@@ -719,8 +726,8 @@
           print "update: $pkg done\n";
         }
       }
-    } elsif ($rev > $mediarev) {
-      print "$pkg: revision in $location is less then local revision, not updating!\n";
+    } else {
+      debug("$pkg: no installation candidate with higher rev found!\n");
       next;
     }
   }
@@ -740,13 +747,23 @@
     );
     tlwarn("UPDATER has been created, please execute tlpkg\\installer\\updater.bat\n");
   }
-  if (($nrupdated == 0) && ($tlmediasrc->media ne "NET") && $opt_all) {
-    # for all but net updates we warn if nothing is updated
-    tlwarn("\nYour installation is set up to look on the disk for updates.\n");
-    tlwarn("If you want to install from the Internet for this one time only, run\n");
-    tlwarn("  tlmgr -location $TeXLiveURL\n");
-    tlwarn("\nIf you want to change the default for all future updates, run\n");
-    tlwarn("   tlmgr option location $TeXLiveURL\n\n");
+  if (($nrupdated == 0) && $opt_all) {
+    my $any_net = 0;
+    for my $tm (values(%tlmediasrc)) {
+      if ($tm->media eq "NET") {
+        $any_net = 1;
+        last;
+      }
+    }
+    if (!$any_net) {
+      # for all but net updates we warn if nothing is updated
+      tlwarn("\nTEXT OUTDATED NEEDS REMARK FOR MULTIPLE LOCATIONS!!!\n");
+      tlwarn("\nYour installation is set up to look on the disk for updates.\n");
+      tlwarn("If you want to install from the Internet for this one time only, run\n");
+      tlwarn("  tlmgr -location $TeXLiveURL\n");
+      tlwarn("\nIf you want to change the default for all future updates, run\n");
+      tlwarn("   tlmgr option location $TeXLiveURL\n\n");
+    }
   }
   return(\%ret);
 }
@@ -763,14 +780,18 @@
   GetOptions("no-depends" => \$opt_nodepends,
              "dry-run" => \$opt_dry) or pod2usage(2);
   my %ret;
-  $tlmediasrc = TeXLive::TLMedia->new($location);
-  die($loadmediasrcerror . $location) unless defined($tlmediasrc);
+  init_tlmedia();
   foreach my $pkg (@ARGV) {
     if ($opt_dry) {
       print "install: $pkg\n";
     } else {
       # install the packages and run postinstall actions (that is the 0)
-      merge_into(\%ret, $tlmediasrc->install_package($pkg, $localtlpdb, $opt_nodepends, 0));
+      my ($maxsrc, $maxrev) = install_candidate($pkg);
+      if (defined($maxsrc)) {
+        merge_into(\%ret, $tlmediasrc{$maxsrc}->install_package($pkg, $localtlpdb, $opt_nodepends, 0));
+      } else {
+        tlwarn("No installation candidate for $pkg found!\n");
+      }
     }
   }
   if ($opt_dry) {
@@ -780,12 +801,17 @@
   return(\%ret);
 }
 
+#
+# TODO 
+# needs to be fixed for multi source support!!!
+
 sub action_list {
   init_local_db();
   my $what = shift @ARGV;
   $what || ($what = "");
-  $tlmediasrc = TeXLive::TLMedia->new($location);
-  die($loadmediasrcerror . $location) unless defined($tlmediasrc);
+  init_tlmedia();
+  # check an *ARBITRARY* TLPDB at the moment
+  my $tlmediasrc = (values %tlmediasrc)[0];
   my @whattolist;
   if ($what =~ m/^collection/i) {
     @whattolist = $tlmediasrc->tlpdb->collections;
@@ -814,6 +840,8 @@
   $what = "show" unless defined($what);
   init_local_db();
   if ($what =~ m/^location$/i) {
+    # TODO
+    # needs to be fixed for multi source locations!!!
     # changes the default location
     my $loc = shift @ARGV;
     if ($loc) {
@@ -881,8 +909,11 @@
   if ($what =~ m/^list$/i) {
     # list the available architectures
     # initialize the TLMedia from $location
-    $tlmediasrc = TeXLive::TLMedia->new($location);
-    die($loadmediasrcerror . $location) unless defined($tlmediasrc);
+    init_tlmedia();
+    # TODO
+    # needs to be fixed for multi source support
+    # currently we are checking an arbitrary source!!!
+    my $tlmediasrc = (values %tlmediasrc)[0];
     my $mediatlpdb = $tlmediasrc->tlpdb;
     my @already_installed_arch = $localtlpdb->available_architectures;
     print "Available architectures:\n";
@@ -897,8 +928,11 @@
     print "You can add new architectures with tlmgr arch add arch1 arch2\n";
     exit(0);
   } elsif ($what =~ m/^add$/i) {
-    $tlmediasrc = TeXLive::TLMedia->new($location);
-    die($loadmediasrcerror . $location) unless defined($tlmediasrc);
+    init_tlmedia();
+    # TODO
+    # needs to be fixed for multi source support
+    # currently we are checking an arbitrary source!!!
+    my $tlmediasrc = (values %tlmediasrc)[0];
     my $mediatlpdb = $tlmediasrc->tlpdb;
     my @already_installed_arch = $localtlpdb->available_architectures;
     my @available_arch = $mediatlpdb->available_architectures;
@@ -1007,14 +1041,11 @@
     }
   }
   # let cmd line options override the settings in localtlpdb
-  my $loc = $localtlpdb->option_location;
-  if (defined($loc)) {
-    $location = $loc;
-  }
+  @locations = $localtlpdb->option_locations;
   if (defined($opt_location)) {
-    $location = $opt_location;
+    @locations = split /,/, $opt_location;
   }
-  if (!defined($location)) {
+  if (!@locations) {
     die("No installation source found, nor in the texlive.tlpdb nor on the cmd line.\nPlease specify one!");
   }
 }
@@ -1183,6 +1214,59 @@
   system("rmdir", "--ignore-fail-on-non-empty", "$texdir");
 }
 
+#
+# init_tlmedia
+# initialize a tlmedia object and returns it, or dies
+#
+sub init_tlmedia {
+  return if $tlmedia_loaded;
+  my $found = 0;
+  for my $l (@locations) {
+    my $location = $l;
+    if (($location =~ m/$TeXLiveServerURL/) ||
+        ($location =~ m/^ctan$/i)) {
+      $location = give_ctan_mirror();
+      info("Using mirror $location\n");
+    }
+    # $tlmediasrc is a global function
+    $tlmediasrc{$l} = TeXLive::TLMedia->new($location);
+    if (defined($tlmediasrc{$l})) {
+      $found++;
+      $tlmediatlpdb{$l} = $tlmediasrc{$l}->tlpdb;
+    } else {
+      info($loadmediasrcerror . $location);
+    }
+  }
+  if (!$found) {
+    # we didn't find any useable installation media, die here!
+    die("Cannot find any useable installation source in one of the following locations:\n@locations\nStopping here!");
+  }
+  $tlmedia_loaded = 1;
+}
+
+  
+#
+#
+sub install_candidate {
+  my $pkg = shift;
+  my $maxrev = -1;
+  my $maxsrc;
+  for my $s (keys %tlmediasrc) {
+    my $tlp = $tlmediatlpdb{$s}->get_package($pkg);
+    if ($tlp) {
+      my $r = $tlp->revision;
+      if ($maxrev < $r) {
+        $maxrev = $r;
+        $maxsrc = $s;
+      }
+    }
+  }
+  if ($maxsrc) {
+    # something was found ($maxsrc, $maxrev, $maxtlp, $maxtlmedia)
+    return ($maxsrc, $maxrev, $tlmediatlpdb{$maxsrc}->get_package($pkg), $tlmediasrc{$maxsrc});
+  }
+  return;
+}
 
 #
 # return all the directories from which all content will be removed
--- /src/TeX/texlive-svn/Master/tlpkg/TeXLive/TLPDB.pm	2008-08-22 14:52:11.000000000 +0200
+++ tlpkg/TeXLive/TLPDB.pm	2008-08-29 12:17:40.000000000 +0200
@@ -889,14 +889,28 @@
   if (@_) { $self->_set_option_value("opt_paper", shift); }
   return $self->_option_value("opt_paper"); 
 }
+sub option_locations {
+  my $self = shift;
+  my @locs = ();
+  if (defined($self->{'tlps'}{'00texlive-installation.config'})) {
+    foreach my $d ($self->{'tlps'}{'00texlive-installation.config'}->depends) {
+      if ($d =~ m!^location:(.*)$!) {
+        push @locs, "$1";
+      }
+    }
+  }
+  return(@locs);
+}
+
 sub option_location { 
   my $self = shift; 
-  if (@_) { $self->_set_option_value("location", shift); }
-  my $loc = $self->_option_value("location");
+  if (@_) { tlwarn("Ignoring the setting of location, that has to be fixed for multi source support!\n"); }
+  my @locs = $self->option_locations;
+  my $loc = $locs[0];
   if ($loc eq "__MASTER__") {
     return $self->root;
   }
-  return $self->_option_value("location");
+  return $loc;
 }
 sub option_sys_bin {
   my $self = shift;