emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r114395: * net/tramp-sh.el (tramp-get-remote-id): Do


From: Michael Albinus
Subject: [Emacs-diffs] trunk r114395: * net/tramp-sh.el (tramp-get-remote-id): Do not raise an error.
Date: Thu, 19 Sep 2013 11:08:05 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114395
revision-id: address@hidden
parent: address@hidden
committer: Michael Albinus <address@hidden>
branch nick: trunk
timestamp: Thu 2013-09-19 13:08:01 +0200
message:
  * net/tramp-sh.el (tramp-get-remote-id): Do not raise an error.
  (tramp-get-remote-uid-with-id, tramp-get-remote-gid-with-id)
  (tramp-get-remote-python): New defuns.
  (tramp-get-remote-uid-with-perl)
  (tramp-get-remote-gid-with-perl): New defuns.  Perl code
  contributed by yary <address@hidden> (tiny change).
  (tramp-get-remote-uid-with-python)
  (tramp-get-remote-gid-with-python): New defuns.  Python code
  contributed by Andrey Tykhonov <address@hidden> (tiny change).
  (tramp-get-remote-uid, tramp-get-remote-gid): Use new defuns.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/net/tramp-sh.el           trampsh.el-20100913133439-a1faifh29eqoi4nh-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-09-19 07:14:53 +0000
+++ b/lisp/ChangeLog    2013-09-19 11:08:01 +0000
@@ -1,3 +1,16 @@
+2013-09-19  Michael Albinus  <address@hidden>
+
+       * net/tramp-sh.el (tramp-get-remote-id): Do not raise an error.
+       (tramp-get-remote-uid-with-id, tramp-get-remote-gid-with-id)
+       (tramp-get-remote-python): New defuns.
+       (tramp-get-remote-uid-with-perl)
+       (tramp-get-remote-gid-with-perl): New defuns.  Perl code
+       contributed by yary <address@hidden> (tiny change).
+       (tramp-get-remote-uid-with-python)
+       (tramp-get-remote-gid-with-python): New defuns.  Python code
+       contributed by Andrey Tykhonov <address@hidden> (tiny change).
+       (tramp-get-remote-uid, tramp-get-remote-gid): Use new defuns.
+
 2013-09-19  Glenn Morris  <address@hidden>
 
        * emacs-lisp/eieio.el (class-parent): Don't use defalias with macros.

=== modified file 'lisp/net/tramp-sh.el'
--- a/lisp/net/tramp-sh.el      2013-09-13 06:03:06 +0000
+++ b/lisp/net/tramp-sh.el      2013-09-19 11:08:01 +0000
@@ -4950,38 +4950,97 @@
 (defun tramp-get-remote-id (vec)
   (with-tramp-connection-property vec "id"
     (tramp-message vec 5 "Finding POSIX `id' command")
-    (or
-     (catch 'id-found
-       (let ((dl (tramp-get-remote-path vec))
-            result)
-        (while (and dl (setq result (tramp-find-executable vec "id" dl t t)))
-          ;; Check POSIX parameter.
-          (when (tramp-send-command-and-check vec (format "%s -u" result))
-            (throw 'id-found result))
-          (setq dl (cdr dl)))))
-     (tramp-error vec 'file-error "Couldn't find a POSIX `id' command"))))
+    (catch 'id-found
+      (let ((dl (tramp-get-remote-path vec))
+           result)
+       (while (and dl (setq result (tramp-find-executable vec "id" dl t t)))
+         ;; Check POSIX parameter.
+         (when (tramp-send-command-and-check vec (format "%s -u" result))
+           (throw 'id-found result))
+         (setq dl (cdr dl)))))))
+
+(defun tramp-get-remote-uid-with-id (vec id-format)
+  (tramp-send-command-and-read
+   vec
+   (format "%s -u%s %s"
+          (tramp-get-remote-id vec)
+          (if (equal id-format 'integer) "" "n")
+          (if (equal id-format 'integer)
+              "" "| sed -e s/^/\\\"/ -e s/\$/\\\"/"))))
+
+(defun tramp-get-remote-uid-with-perl (vec id-format)
+  (tramp-send-command-and-read
+   vec
+   (format "%s -le '%s'"
+          (tramp-get-remote-perl vec)
+          (if (equal id-format 'integer)
+              "print $>"
+            "print \"\\\"\", scalar getpwuid($>), \"\\\"\""))))
+
+(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))))
+
+(defun tramp-get-remote-uid-with-python (vec id-format)
+  (tramp-send-command-and-read
+   vec
+   (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] + 
'\\\"'"))))
 
 (defun tramp-get-remote-uid (vec id-format)
   (with-tramp-connection-property vec (format "uid-%s" id-format)
-    (let ((res (tramp-send-command-and-read
-               vec
-               (format "%s -u%s %s"
-                       (tramp-get-remote-id vec)
-                       (if (equal id-format 'integer) "" "n")
-                       (if (equal id-format 'integer)
-                           "" "| sed -e s/^/\\\"/ -e s/\$/\\\"/")))))
+    (let ((res (cond
+               ((tramp-get-remote-id vec)
+                (tramp-get-remote-uid-with-id vec id-format))
+               ((tramp-get-remote-perl vec)
+                (tramp-get-remote-uid-with-perl vec id-format))
+               ((tramp-get-remote-python vec)
+                (tramp-get-remote-uid-with-python vec id-format))
+               (t (tramp-error vec "Cannot determine remote uid")))))
       ;; The command might not always return a number.
       (if (and (equal id-format 'integer) (not (integerp res))) -1 res))))
 
+(defun tramp-get-remote-gid-with-id (vec id-format)
+  (tramp-send-command-and-read
+   vec
+   (format "%s -g%s %s"
+          (tramp-get-remote-id vec)
+          (if (equal id-format 'integer) "" "n")
+          (if (equal id-format 'integer)
+              "" "| sed -e s/^/\\\"/ -e s/\$/\\\"/"))))
+
+(defun tramp-get-remote-gid-with-perl (vec id-format)
+  (tramp-send-command-and-read
+   vec
+   (format "%s -le '%s'"
+          (tramp-get-remote-perl vec)
+          (if (equal id-format 'integer)
+              "print ($)=~/(\\d+)/)"
+            "print \"\\\"\", scalar getgrgid($)), \"\\\"\""))))
+
+(defun tramp-get-remote-gid-with-python (vec id-format)
+  (tramp-send-command-and-read
+   vec
+   (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] + 
'\\\"'"))))
+
 (defun tramp-get-remote-gid (vec id-format)
   (with-tramp-connection-property vec (format "gid-%s" id-format)
-    (let ((res (tramp-send-command-and-read
-               vec
-               (format "%s -g%s %s"
-                       (tramp-get-remote-id vec)
-                       (if (equal id-format 'integer) "" "n")
-                       (if (equal id-format 'integer)
-                           "" "| sed -e s/^/\\\"/ -e s/\$/\\\"/")))))
+    (let ((res (cond
+               ((tramp-get-remote-id vec)
+                (tramp-get-remote-gid-with-id vec id-format))
+               ((tramp-get-remote-perl vec)
+                (tramp-get-remote-gid-with-perl vec id-format))
+               ((tramp-get-remote-python vec)
+                (tramp-get-remote-gid-with-python vec id-format))
+               (t (tramp-error vec "Cannot determine remote gid")))))
       ;; The command might not always return a number.
       (if (and (equal id-format 'integer) (not (integerp res))) -1 res))))
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]