emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-gnuplot: handle remote input files
@ 2020-09-29 17:00 Ferdinand Pieper
  2020-10-24 12:15 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Ferdinand Pieper @ 2020-09-29 17:00 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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
#+end_src
--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.

Best,



[-- 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)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ob-gnuplot: handle remote input files
  2020-09-29 17:00 [PATCH] ob-gnuplot: handle remote input files Ferdinand Pieper
@ 2020-10-24 12:15 ` Bastien
  2020-10-25 16:53   ` Ferdinand Pieper
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2020-10-24 12:15 UTC (permalink / raw)
  To: Ferdinand Pieper; +Cc: emacs-orgmode

Hi Ferdinand,

Ferdinand Pieper <fer@pie.tf> writes:

> 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.

Applied, thanks!

> An example:
>
> #+begin_src gnuplot :var data="/ssh:myserver:/myfile.txt"
> plot data u 1:2
> #+end_src
>
> 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.

The commit message and the changelog were perfect, thanks for taking
care of this.  I simply added "TINYCHANGE".

Best,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ob-gnuplot: handle remote input files
  2020-10-24 12:15 ` Bastien
@ 2020-10-25 16:53   ` Ferdinand Pieper
  2020-10-27  9:55     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Ferdinand Pieper @ 2020-10-25 16:53 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Hi Bastien,

Bastien <bzg@gnu.org> writes:

> Applied, thanks!

Thank you.

> The commit message and the changelog were perfect, thanks for taking
> care of this.  I simply added "TINYCHANGE".

I signed the FSF copyright times a short while ago, so I think this is
no longer necessary.


Best,


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ob-gnuplot: handle remote input files
  2020-10-25 16:53   ` Ferdinand Pieper
@ 2020-10-27  9:55     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2020-10-27  9:55 UTC (permalink / raw)
  To: Ferdinand Pieper; +Cc: emacs-orgmode

Hi Ferdinand,

Ferdinand Pieper <fer@pie.tf> writes:

> I signed the FSF copyright times a short while ago, so I think this is
> no longer necessary.

Indeed, thanks.  https://orgmode.org/worg/org-contribute.html was not
up to date, I've fixed this.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-27  9:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-29 17:00 [PATCH] ob-gnuplot: handle remote input files Ferdinand Pieper
2020-10-24 12:15 ` Bastien
2020-10-25 16:53   ` Ferdinand Pieper
2020-10-27  9:55     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).