emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Douglas Perrin <doug2024@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Import Reusable org-babel snippet using #+SETUPFILE
Date: Mon, 15 Jun 2020 15:52:16 -0400	[thread overview]
Message-ID: <CAFw+bXFJS+DKD5MQYZpPQ0igQ3LOHPkFetP9RDNQM1OX3hPT1w@mail.gmail.com> (raw)

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

Hi Salomon Turgman,
I do this a lot and have had success using a combination of #+SETUPFILE to
bring in names and configuration, and org-sbe to do initialization. I mix
emacs vars and org names in my source headers with back quoting.

The following example has a template file containing user/local
information. This is brought into the example file, on load, through #:eval
calling org-babel-lob-ingest and org-sbe, in addition, parameters are
pulled in with #+SETUPFILE and the same template file name. The end result
for this example is a running docker image with access to local paths and
"remote" execution via tramp. More complex orchestration and actions in the
template are certainly possible using org-sbe calls in the init elisp
source blocks but hopefully, this shows the flavor of what can be done.

In addition to avoiding code duplication, I have found this to be very
effective when my group is all working from the same org file (via git) but
everyone has their own template file with credentials, local paths, and org
more preferences (ie showstars).

#+SETUPFILE: Template-Loader.org

* Init Code, run when file is opened
#+name: Execute-On-Load
#+begin_src elisp  :results output
   ;; for this the container and image have the same name
    (setq *DockerName* "ContanerName")

* Run Contaner
#+begin_src bash  :results raw drawer :var DockerName=`,*DockerName*
DockerHubUID=`,*DockerHubUID* containerName=`,*DockerContainer*
LocalWorkPath=`,*LocalWorkPath* LocalDataPath=`,*LocalDataPath*
   docker run --rm -d \
          -v $LocalWorkPath:/root/Workdir \
          -v $LocalDataPath:/root/Data \
          --name $DockerName $DockerHubUID/$DockerName bash -c "tail -f

* run IN contaner
#+begin_src bash  :results output :dir (concat "/docker:" `,*DockerName*

# Local Variables:
# eval: (org-babel-lob-ingest "Template-Loader.org")
# eval: (org-sbe "Init-Template")
# eval: (org-sbe "Execute-On-Load")
# End:

#+STARTUP: showstars
#+PROPERTY: header-args :mkdirp yes

#+name: Init-Template
#+begin_src emacs-lisp :results none
  ;; This is called expecitly via org-sbe in the buffer that will uses the
    (setq *DockerHubUID* "MyUserName")
    (setq *LocalWorkPath* "/run/desktop/mnt/host/c/Users/.....")
    (setq *LocalDataPath* "/run/desktop/mnt/host/d/devData/")

  ;; ingest + SBE can be used to bring in a hierarchy of templates
  (org-babel-lob-ingest "./GroupTools/GeneralORGTools.org")
  (org-sbe "GeneralORGTools.org")


[-- Attachment #2: Type: text/html, Size: 4398 bytes --]

             reply	other threads:[~2020-06-15 19:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 19:52 Douglas Perrin [this message]
2020-06-16 15:21 ` Import Reusable org-babel snippet using #+SETUPFILE Salomon Turgman
2020-06-17 14:23   ` Salomon Turgman
  -- strict thread matches above, loose matches on Subject: below --
2020-06-18 16:03 Douglas Perrin
2020-06-09 17:28 Salomon Turgman
2020-06-09 23:09 ` Nicolas Goaziou

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=CAFw+bXFJS+DKD5MQYZpPQ0igQ3LOHPkFetP9RDNQM1OX3hPT1w@mail.gmail.com \
    --to=doug2024@gmail.com \
    --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).