summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2008-10-02 13:48:16 +0000
committerNorbert Preining <preining@logic.at>2008-10-02 13:48:16 +0000
commit8e9247adbe2cc689db6eda8c7780ace47203ea90 (patch)
tree7da6fa8e2630f13bf92e5d4a4d57b0b8f97851cd
parentf66be25e3ce4def08bd172a640f3c5f584ad727b (diff)
logging package actions (install, remove, update, restore) to
TEXMFSYSVAR/web2c/tlmgr.log, or --package-logfile git-svn-id: svn://tug.org/texlive/trunk@10826 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-xMaster/texmf/scripts/texlive/tlmgr.pl62
1 files changed, 55 insertions, 7 deletions
diff --git a/Master/texmf/scripts/texlive/tlmgr.pl b/Master/texmf/scripts/texlive/tlmgr.pl
index 05c48a94656..c6a8318e7ab 100755
--- a/Master/texmf/scripts/texlive/tlmgr.pl
+++ b/Master/texmf/scripts/texlive/tlmgr.pl
@@ -6,8 +6,6 @@
# or any later version.
#
# TODO:
-# - tlmgr logging of package transactions (install, remove, update) into
-# tlmgr.log
# - tlmgr fileassoc ... on win32:
# tlmgr fileassoc dvi winout
# tlmgr fileassoc pdf psv
@@ -74,16 +72,34 @@ my $opt_help = 0;
my $opt_version = 0;
my $opt_gui = 0;
my $opt_gui_lang;
+my $opt_packagelogfile;
TeXLive::TLUtils::process_logging_options();
GetOptions("location=s" => \$opt_location,
"gui" => \$opt_gui,
"gui-lang=s" => \$opt_gui_lang,
+ "package-logfile=s" => \$opt_packagelogfile,
"version" => \$opt_version,
"h|help|?" => \$opt_help) or pod2usage(2);
my $action = shift;
+#
+# besides doing normal logging if -logfileis specified, we try to log all
+# package related actions (install, remove, update) to
+# the package-log file TEXMFSYSVAR/web2c/tlmgr.log
+my $texmfsysvar = `kpsewhich -var-value=TEXMFSYSVAR`;
+chomp($texmfsysvar);
+my $packagelogfile = ($opt_packagelogfile ? $opt_packagelogfile :
+ "$texmfsysvar/web2c/tlmgr.log");
+#
+# Try to open the packagelog file, but do NOT die when that does not work
+if (!open(PACKAGELOG, ">>$packagelogfile")) {
+ tlwarn("Cannot open package log file $packagelogfile for appending\n");
+ tlwarn("Will not log package installation/removal/update for that run\n");
+ $packagelogfile = "";
+}
+
if (!defined($action) && $opt_gui) {
$action = "gui";
}
@@ -182,6 +198,10 @@ if ($action =~ m/^_include_tlpobj$/) {
######################################
+# close the log file
+if ($packagelogfile) {
+ close(PACKAGELOG);
+}
#
# checking the %ret hash
if (defined($ret{'mktexlsr'})) {
@@ -383,6 +403,7 @@ sub action_remove {
if (keys %foo) {
# removal was successful, so the return is at least 0x0001 mktexlsr
# remove dependencies, too
+ logpackage("remove: $pkg");
merge_into(\%ret, \%foo);
$already_removed{$pkg} = 1;
}
@@ -403,6 +424,7 @@ sub action_remove {
merge_into(\%foo, &remove_package($pkg, $localtlpdb, $opt_force));
if (keys %foo) {
# removal was successful
+ logpackage("remove: $pkg");
merge_into(\%ret, \%foo);
$already_removed{$pkg} = 1;
}
@@ -572,6 +594,7 @@ sub action_restore {
$opt_backupdir = abs_path($opt_backupdir);
merge_into(\%ret, &remove_package($pkg, $localtlpdb, 1));
TeXLive::TLMedia->_install_package("$opt_backupdir/${pkg}.r${rev}.tar.lzma" , [] ,$localtlpdb);
+ logpackage("restore: $pkg ($rev)");
# now we have to read the .tlpobj file and add it to the DB
my $tlpobj = TeXLive::TLPOBJ->new;
$tlpobj->from_file($localtlpdb->root . "/tlpkg/tlpobj/$pkg.tlpobj");
@@ -760,7 +783,7 @@ sub action_update {
if ($rev < $mediarev) {
$nrupdated++;
if ($opt_list) {
- print "$pkg: local: $rev, source: $mediarev\n";
+ info("$pkg: local: $rev, source: $mediarev\n");
} else {
# first remove the package, then reinstall it
# this way we get rid of useless files
@@ -768,7 +791,7 @@ sub action_update {
if ($opt_backupdir && !$opt_dry) {
$opt_backupdir = abs_path($opt_backupdir);
if (! -d $opt_backupdir) {
- printf STDERR "backupdir argument must be an existing directory!\n";
+ tlwarn("backupdir argument must be an existing directory!\n");
} else {
my $tlp = $localtlpdb->get_package($pkg);
$tlp->make_container("lzma", $root,
@@ -834,6 +857,7 @@ EOF
info("done\n");
next;
}
+
if (!$unwind_package) {
# no backup was made, so let us create a temporary .tar file
# of the package
@@ -856,12 +880,14 @@ EOF
if (ref $foo) {
# installation succeeded because we got a reference
merge_into (\%ret, $foo);
+ logpackage("update: $pkg ($rev -> $mediarev)");
unlink($unwind_package) if $remove_unwind_container;
} else {
# install_package returned a scalare, so error!
# now in fact we should do some cleanup, removing files and
# dirs from the new package before re-installing the old one!!!
# TODO
+ logpackage("failed update: $pkg ($rev -> $mediarev)");
tlwarn("\n\nInstallation of new version of $pkg did fail, trying to unwind!\n");
if (win32()) {
# win32 is notorious for not releasing a file immediately
@@ -882,8 +908,10 @@ EOF
$tlpobj->from_file($root . "/tlpkg/tlpobj/$pkg.tlpobj");
$localtlpdb->add_tlpobj($tlpobj);
$localtlpdb->save;
+ logpackage("restore: $pkg ($rev)");
tlwarn("Restoring old package state succeeded.\n");
} else {
+ logpackage("restore failed: $pkg ($rev)");
tlwarn("Restoring of old package did NOT succeed!\n");
tlwarn("Best is to call tlmgr install $pkg and hope to get it right!\n");
}
@@ -904,8 +932,10 @@ EOF
} else {
info("remove $p (removed on server)\n");
}
- merge_into(\%ret, &remove_package($p, $localtlpdb, 1)) unless
- ($opt_dry or $opt_list or $opt_noremove);
+ if (!($opt_dry or $opt_list or $opt_noremove)) {
+ merge_into(\%ret, &remove_package($p, $localtlpdb, 1));
+ logpackage("remove: $p");
+ }
}
if ($updater_started) {
print UPDATER "del tlpkg\\installer\\tarsave.exe\n";
@@ -1002,8 +1032,8 @@ sub action_install {
}
info("install: $pkg\n");
if (!$opt_dry) {
- info("install: $pkg\n");
merge_into(\%ret, $tlmediasrc->install_package($pkg, $localtlpdb));
+ logpackage("install: $pkg");
}
}
if ($opt_dry) {
@@ -1611,6 +1641,16 @@ sub init_tlmedia {
die($loadmediasrcerror . $location) unless defined($tlmediasrc);
}
+#
+# the packagelog function
+# if the packagelog variable is set then write to PACKAGELOG filehandle
+#
+sub logpackage {
+ if ($packagelogfile) {
+ my $tim = localtime();
+ print PACKAGELOG "[$tim] @_\n";
+ }
+}
#
# return all the directories from which all content will be removed
@@ -1733,6 +1773,14 @@ Windows via the registry, on Unix via C<LC_MESSAGES>). If that fails you
can select a different language by giving this option a two-letter
language code.
+=item B<-package-logfile> I<file>
+
+B<tlmgr> logs all package actions (install, remove, update, failed updates
+and failed restores) to a separate log file. This is by default
+TEXMFSYSVAR/web2c/tlmgr.log. This option allows you to select a different
+file for that. Note that this is different from normal logging, for that
+see the option C<-v> below, and TeXLive::TLUtils.
+
=back
The standard options are also accepted: C<--help/-h/-?>, C<--version>,