emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ferdinand Pieper <fer@pie.tf>
To: emacs-orgmode@gnu.org
Subject: [PATCH] ob-gnuplot: handle remote input files
Date: Tue, 29 Sep 2020 19:00:58 +0200	[thread overview]
Message-ID: <87imbwsek5.fsf@ims.uni-hannover.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 597 bytes --]

When passing a remote file like "/ssh:myserver:/myfile.txt" to a gnuplot block as variable the gnuplot process can not access the remote data.

An example:

--8<---------------cut here---------------start------------->8---
#+begin_src gnuplot :var data="/ssh:myserver:/myfile.txt"
plot data u 1:2
--8<---------------cut here---------------end--------------->8---

Attached is a patch, which instead downloads remote files to a unique path and passes this new path to gnuplot.

Please let me know if there's something to improve regarding the commit message or patch formatting.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-gnuplot-Download-remote-input-files.patch --]
[-- Type: text/x-diff, Size: 1466 bytes --]

From 4f9f98ed8f48754eeff09b8de51734bc8521bb6a Mon Sep 17 00:00:00 2001
From: fpi <git@pie.tf>
Date: Tue, 29 Sep 2020 18:43:07 +0200
Subject: [PATCH] ob-gnuplot: Download remote input files

* lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars): When variables
point to remote files download them and use a local copy instead.
 lisp/ob-gnuplot.el | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el
index 62ab04d94..820929c84 100644
--- a/lisp/ob-gnuplot.el
+++ b/lisp/ob-gnuplot.el
@@ -92,7 +92,21 @@ code."
 		      (tablep (or (listp first) (symbolp first))))
 		 (if tablep val (mapcar 'list val)))
 	       (org-babel-temp-file "gnuplot-") params)
-	  val))))
+	    (if (and (file-remote-p val)  ;; check if val is a remote file
+		     (file-exists-p val)) ;; call to file-exists-p is slow, maybe remove it
+		(let* ((local-name (concat ;; create a unique filename to avoid multiple downloads
+				org-babel-temporary-directory
+				"/gnuplot/"
+				(file-remote-p val 'host)
+				(file-local-name val))))
+		  (if (and (file-exists-p local-name) ;; only download file if remote is newer
+			   (file-newer-than-file-p local-name val))
+		      local-name
+		    (make-directory (file-name-directory local-name) t)
+		    (copy-file val local-name t)
+		  ))
+	      val
+		)))))
      (org-babel--get-vars params))))
 (defun org-babel-expand-body:gnuplot (body params)

             reply	other threads:[~2020-09-29 17:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 17:00 Ferdinand Pieper [this message]
2020-10-24 12:15 ` [PATCH] ob-gnuplot: handle remote input files Bastien
2020-10-25 16:53   ` Ferdinand Pieper
2020-10-27  9:55     ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imbwsek5.fsf@ims.uni-hannover.de \
    --to=fer@pie.tf \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).