texlive[44376] Master/tlpkg/tlpostcode/ptex2pdf-tlpost.pl: update

commits+preining at tug.org commits+preining at tug.org
Tue May 16 06:00:04 CEST 2017


Revision: 44376
          http://tug.org/svn/texlive?view=revision&revision=44376
Author:   preining
Date:     2017-05-16 06:00:03 +0200 (Tue, 16 May 2017)
Log Message:
-----------
update ptex2pdf-tlpost from main repo

Modified Paths:
--------------
    trunk/Master/tlpkg/tlpostcode/ptex2pdf-tlpost.pl

Modified: trunk/Master/tlpkg/tlpostcode/ptex2pdf-tlpost.pl
===================================================================
--- trunk/Master/tlpkg/tlpostcode/ptex2pdf-tlpost.pl	2017-05-16 00:21:53 UTC (rev 44375)
+++ trunk/Master/tlpkg/tlpostcode/ptex2pdf-tlpost.pl	2017-05-16 04:00:03 UTC (rev 44376)
@@ -3,12 +3,17 @@
 # post action for ptex2pdf in TeX Live
 # action carried out:
 # - if the environment is Japanese or the installer is running in Japanese, then...
-# - check for TeXworks tools.ini in
-#   TW_INIPATH/configuration/tools.ini
-# - if *not* available, initialize from the default plus Japanese stuff
-# - if       available, read and try to add Japanese entries if not already there
+#   - check for TeXworks tools.ini in
+#     TW_INIPATH/configuration/tools.ini
+#     - if *not* available, initialize from the default plus Japanese stuff
+#     - if       available, read and try to add Japanese entries if not already there
+#   - check for TeXworks.ini in
+#     TW_INIPATH/TUG/TeXworks.ini
+#     - if *not* available, initialize the default one with "pLaTeX (ptex2pdf)"
+#     - if       available, read and try to set the default if not already there
 #
-# Copyright 2016 Norbert Preining
+# Copyright 2016-2017 Norbert Preining
+# Copyright 2017 Japanese TeX Developer Community
 # This file is licensed under the GNU General Public License version 2
 # or any later version.
 #
@@ -178,19 +183,83 @@
 
 sub do_install {
   # how to find TeX Works
-  # on Windows: we assume that the TL internal TeXWorks is used and
-  #   search in TW_INIPATH
-  # all other: we assume a system-wide TeXworks and use ~/.TeXworks
+  # see http://doc.qt.io/qt-5/qsettings.html
+  #
+  # NativeFormat
+  # ------------
+  # Unix:
+  #  $HOME/.config/TUG/TeXworks.conf
+  #  $HOME/.config/TeXworks.conf
+  #  /etc/xdg/TUG/TeXworks.conf
+  #  /etc/xdg/TeXworks.conf
+  # Mac:
+  #  $HOME/Library/Preferences/org.TUG.TeXworks.plist ??
+  #  $HOME/Library/Preferences/com.TeXworks.plist ??
+  #  /Library/Preferences/com.TUG.TeXworks.plist
+  #  /Library/Preferences/com.TeXworks.plist
+  # Win:
+  #  HKEY_CURRENT_USER\Software\TUG\TeXworks
+  #  HKEY_CURRENT_USER\Software\TUG\OrganizationDefaults
+  #  HKEY_LOCAL_MACHINE\Software\TUG\TeXworks
+  #  HKEY_LOCAL_MACHINE\Software\TUG\OrganizationDefaults
+  #
+  # IniFormat
+  # ---------
+  # Unix/Mac/iOS:
+  #  $HOME/.config/TUG/TeXworks.ini
+  #  $HOME/.config/TeXworks.ini
+  #  /etc/xdg/TUG/TeXworks.ini
+  #  /etc/xdg/TeXworks.ini
+  # Windows
+  #  FOLDERID_RoamingAppData\TUG\TeXworks.ini
+  #  FOLDERID_RoamingAppData\TUG.ini
+  #  FOLDERID_ProgramData\TUG\TeXworks.ini
+  #  FOLDERID_ProgramData\TUG.ini
+  # where
+  #  FOLDERID_RoamingAppData usually points to C:\Users\User Name\AppData\Roaming
+  #  FOLDERID_ProgramData usually points to C:\ProgramData
+  #
+  # TeXworks uses a mixture of NativeFormat and IniFormat
+  # ConfigurableApp::ConfigurableApp set NativeFormat
+  # TWApp checking for portable mode uses IniFormat
+  #
+  # So my guess is:
+  # - TeXworks as shipped in TL uses the portable app setup, thus IniFormat
+  # - TeXworks on Mac/Unix (not distributed with TL) uses NativeFormat
+  #
   my $toolsdir;
+  my $tugdir;
+  my $inifile;
   if (win32()) {
+    # we assume TeXworks from TL, thus IniFormat
     chomp( my $twini = `kpsewhich -var-value=TW_INIPATH` ) ;
     $toolsdir = "$twini/configuration";
+    $tugdir = "$twini/TUG";
+    $inifile = "TeXworks.ini";
+  } elsif ($^O eq "darwin") {
+    $toolsdir = $ENV{'HOME'} . "/Library/TeXworks/configuration";
+    $tugdir = $ENV{'HOME'} . "/Library/Preferences"; # needs check TODO
+    $inifile = "org.TUG.TeXworks.plist"; # TODO needs check
+    # TODO but as we do not do anything with $tugdir/$inifile (since it
+    # is a plist file, this is not a problem for now.
   } else {
     $toolsdir = $ENV{'HOME'} . "/.TeXworks/configuration";
+    my $xdgconfhome = (defined($ENV{'XDG_CONFIG_HOME'}) ? $ENV{'XDG_CONFIG_HOME'} : $ENV{'HOME'} . "/.config");
+    $tugdir = $xdgconfhome . "/TUG";
+    $inifile = "TeXworks.conf";
   }
   # print "toolsdir = $toolsdir\n";
+  # print "tugdir = $tugdir\n";
   my $tools = "$toolsdir/tools.ini";
+  my $tug = "$tugdir/$inifile";
   my $highest_entry = 0;
+  my $noadjust;
+  my $found_platex;
+  my $fh;
+  #
+  # check tools.ini
+  $noadjust = 0;
+  $found_platex = 0;
   if (-r $tools) {
     # assume that succeeds, we tested -r above!
     open (FOO, "<", $tools);
@@ -228,8 +297,16 @@
     # now check that we don't see ptex2pdf
     for my $id (keys %entries) {
       if ($entries{$id}{'program'} && $entries{$id}{'program'} =~ m/^ptex2pdf/s) {
-        info("ptex2pdf programs already included in tools.ini, not adding again.\n");
-        return 0;
+        if (!$noadjust) { # this test reduces duplicate info below
+          info("ptex2pdf programs already included in tools.ini, not adding again.\n");
+          $noadjust = 1;
+        }
+        # no need for edit tools.ini, but still we need to check if
+        # the exact string "pLaTeX (ptex2pdf)" is available,
+        # to ensure success of setting it as the default
+        if ($entries{$id}{'name'} =~ m/^pLaTeX \(ptex2pdf\)$/s) {
+          $found_platex = 1;
+        }
       }
     }
   } else {
@@ -243,28 +320,78 @@
       }
     }
   }
-  for my $t (sort keys %ptex2pdf) {
-    my $id = sprintf("%03d", ++$highest_entry);
-    $entries{$id} = $ptex2pdf{$t};
-    if (win32()) {
-      $entries{$id}{'program'} .= ".exe";
+  # adjust tools.ini
+  if (!$noadjust) {
+    for my $t (sort keys %ptex2pdf) {
+      my $id = sprintf("%03d", ++$highest_entry);
+      $entries{$id} = $ptex2pdf{$t};
+      if (win32()) {
+        $entries{$id}{'program'} .= ".exe";
+      }
     }
+    if (!open ($fh, ">>", $tools)) {
+      tlwarn("\nptex2pdf postaction: cannot update $tools!\n");
+      return 1;
+    }
+    # we are in install mode in a line that will be finished with ...done 
+    info("(ptex2pdf postinst: adjusting TeXworks tools.ini)");
+    for my $k (sort keys %entries) {
+      print $fh "[", $k, "]\n";
+      for my $key (qw/name program arguments showPdf/) {
+        print $fh $key, '=', $entries{$k}{$key}, "\n";
+      }
+      print $fh "\n";
+    }
+    close($fh) or tlwarn("\nptex2pdf postaction: cannot close $tools\n");
+    # the exact string "pLaTeX (ptex2pdf)" is added by myself
+    $found_platex = 1;
   }
-  my $fh;
-  if (!open ($fh, ">>", $tools)) {
-    tlwarn("\nptex2pdf postaction: cannot update $tools!\n");
-    return 1;
+  #
+  # Setting defaults on Mac needs plist changes, nothing we can easily do, sorry.
+  if ($^O eq "darwin") {
+    info("(ptex2pdf postinst: default setting on Mac is currently unsupported)");
+    return 0;
   }
-  # we are in install mode in a line that will be finished with ...done 
-  info("(ptex2pdf postinst: adjusting TeXworks tools.ini)");
-  for my $k (sort keys %entries) {
-    print $fh "[", $k, "]\n";
-    for my $key (qw/name program arguments showPdf/) {
-      print $fh $key, '=', $entries{$k}{$key}, "\n";
+  # check TeXworks.ini
+  $noadjust = 0;
+  if (-r $tug) {
+    # assume that succeeds, we tested -r above!
+    open (FOO, "<", $tug);
+    my @lines = <FOO>;
+    chomp(@lines);
+    close(FOO);
+    # policy: if defaultEngine appears in TeXworks.ini, we do nothing.
+    # Only otherwise we set the value to "pLaTeX (ptex2pdf)".
+    foreach my $l (@lines) {
+      if ($l =~ m/^defaultEngine=(.*)$/) {
+        $noadjust = $1;
+      }
     }
-    print $fh "\n";
+    if ($noadjust) {
+      info("default is already set as $noadjust in TeXworks.ini, no change.\n");
+    }
+  } else {
+    # no TeXworks.ini, we need to create the path and the file
+    mkdirhier($tugdir);
   }
-  close($fh) or tlwarn("\nptex2pdf postaction: cannot close $tools\n");
+  # adjust TeXworks.ini
+  if (!$noadjust) {
+    if (!open ($fh, ">>", $tug)) {
+      tlwarn("\nptex2pdf postaction: cannot update $tug!\n");
+      return 1;
+    }
+    # we are in install mode in a line that will be finished with ...done 
+    if ($found_platex) {
+      info("(ptex2pdf postinst: adjusting TeXworks.ini)");
+      print $fh "defaultEngine=pLaTeX (ptex2pdf)\n";
+    } else {
+      tlwarn("\nptex2pdf postaction: \"pLaTeX (ptex2pdf)\" not found, exiting without setting default!\n");
+      return 1;
+    }
+    close($fh) or tlwarn("\nptex2pdf postaction: cannot close $tug\n");
+  }
+  #
+  # all done
   return 0;
 }
 



More information about the tex-live-commits mailing list