On Tue, 15 Sep 2015, Benda Xu wrote:
Hi Charles,
"Charles C. Berry" <ccbe...@ucsd.edu> writes:
Look at the :post header arg
(info "(org) post")
You write a src block that extracts the remote file name from *this*,
creates a local file name from it, copies the remote file to the local
host, then substitutes the local file name in *this* and uses it as
the return value.
Use the name of that src block as the argument to :post
Thanks for your hint. I come up with the following example:
#+NAME: line
| 1 |
| 2 |
| 3 |
#+name: localize
#+BEGIN_SRC emacs-lisp :var file="" dir=""
(let ((rfile (concat (file-name-as-directory dir) file)))
(let ((lfile (car (last (split-string rfile ":")))))
(copy-file rfile lfile 1)
lfile))
#+END_SRC
#+HEADER: :post localize(*this*, "/ipmuap02:/tmp")
#+BEGIN_SRC python :results file :var dt=line :dir /ipmuap02:/tmp
from matplotlib import pylab as plt
plt.plot(dt)
plt.savefig("line.png")
return "line.png"
#+END_SRC
#+RESULTS:
[[file:/tmp/line.png]]
*this* only returns the resulting file name, without :dir. I have to
set the same remote directory again in the :post call. Is there a
smarter way to achieve it without duplication?
Untested, but try this :
#+name: localize
#+BEGIN_SRC emacs-lisp :var file="" srcinfo=(org-babel-get-src-block-info)
(let* ((dir (cdr (assoc :dir (nth 2 srcinfo))))
(rfile (concat (file-name-as-directory dir) file))
(lfile (car (last (split-string rfile ":")))))
(copy-file rfile lfile 1)
lfile)
#+END_SRC
then use
#+HEADER: :post localize(*this*)
in your python src block.
HTH,
Chuck