Subject: Support for Python3 in TRAMP's `tramp-get-remote-uid-with-python'

From: [email-masked]
Date: Sun, 27 Jul 2014 16:32:31 +0200

Dear Emacs maintainers,

the following patch makes possible to use TRAMP to connect to systems
where both `perl' and `id' are missing and where the Python program is
called `python3'.  Note that the syntax `print foo' is invalid in
Python3 since there `print' is a function, whereas in Python2 it is/was
a statement.  The syntax `print(foo)' works in both cases and it's what
I used bellow.

Regards

 Emílio

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]
# target_branch: http://bzr.savannah.gnu.org/r/emacs/trunk/
# testament_sha1: cbaad612600a8166a622e1019484b64d24afeae9
# timestamp: 2014-07-25 17:17:36 +0200
# base_revision_id: [email-masked]
#
# Begin patch
=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog    2014-07-25 09:37:07 +0000
+++ lisp/ChangeLog    2014-07-25 15:12:22 +0000
@@ -1,3 +1,11 @@
+2014-07-25  Emilio C. Lopes  <[email-masked]>
+
+    * net/tramp-sh.el (tramp-get-remote-python): Also search for
+    executables named "python2" or "python3".
+    (tramp-get-remote-uid-with-python): Use parentheses around arguments to
+    `print' to make it compatible with Python 3.
+    (tramp-get-remote-gid-with-python): Ditto.
+
 2014-07-25  Glenn Morris  <[email-masked]>
 
     * vc/ediff-init.el (ediff-toggle-read-only-function):

=== modified file 'lisp/net/tramp-sh.el'
--- lisp/net/tramp-sh.el    2014-07-03 09:27:02 +0000
+++ lisp/net/tramp-sh.el    2014-07-25 15:12:22 +0000
@@ -5256,7 +5256,9 @@
 (defun tramp-get-remote-python (vec)
   (with-tramp-connection-property vec "python"
     (tramp-message vec 5 "Finding a suitable `python' command")
-    (tramp-find-executable vec "python" (tramp-get-remote-path vec))))
+    (or (tramp-find-executable vec "python" (tramp-get-remote-path vec))
+        (tramp-find-executable vec "python2" (tramp-get-remote-path vec))
+        (tramp-find-executable vec "python3" (tramp-get-remote-path vec)))))
 
 (defun tramp-get-remote-uid-with-python (vec id-format)
   (tramp-send-command-and-read
@@ -5264,8 +5266,8 @@
    (format "%s -c \"%s\""
        (tramp-get-remote-python vec)
        (if (equal id-format 'integer)
-           "import os; print os.getuid()"
-         "import os, pwd; print '\\\"' + pwd.getpwuid(os.getuid())[0] + '\\\"'"))))
+           "import os; print (os.getuid())"
+         "import os, pwd; print ('\\\"' + pwd.getpwuid(os.getuid())[0] + '\\\"')"))))
 
 (defun tramp-get-remote-uid (vec id-format)
   (with-tramp-connection-property vec (format "uid-%s" id-format)
@@ -5305,8 +5307,8 @@
    (format "%s -c \"%s\""
        (tramp-get-remote-python vec)
        (if (equal id-format 'integer)
-           "import os; print os.getgid()"
-         "import os, grp; print '\\\"' + grp.getgrgid(os.getgid())[0] + '\\\"'"))))
+           "import os; print (os.getgid())"
+         "import os, grp; print ('\\\"' + grp.getgrgid(os.getgid())[0] + '\\\"')"))))
 
 (defun tramp-get-remote-gid (vec id-format)
   (with-tramp-connection-property vec (format "gid-%s" id-format)

# Begin bundle