From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 2C2PGpjR516tDQAA0tVLHw (envelope-from ) for ; Mon, 15 Jun 2020 19:52:56 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id iC1IFpjR515EAQAAbx9fmQ (envelope-from ) for ; Mon, 15 Jun 2020 19:52:56 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DF2C394013C for ; Mon, 15 Jun 2020 19:52:55 +0000 (UTC) Received: from localhost ([::1]:46186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jkvA5-00083i-D9 for larch@yhetil.org; Mon, 15 Jun 2020 15:52:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkv9k-00083W-1r for emacs-orgmode@gnu.org; Mon, 15 Jun 2020 15:52:32 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:36212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jkv9i-0008WS-8q for emacs-orgmode@gnu.org; Mon, 15 Jun 2020 15:52:31 -0400 Received: by mail-wr1-x42b.google.com with SMTP id q11so18416883wrp.3 for ; Mon, 15 Jun 2020 12:52:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=t3e1YzBOab01uped4oYtA4WXVL1rQZncM3tUk9ZAUqE=; b=pWaD8AhywGaR+DTC5OOQfSnN9erTtaMXTnC3KAfBJCSgyk4MFqnipWbVbP2YnJiZc4 xGhJd3agZz67KqiHcG2KPQlL+7TxLz84jKYhMHXNhPySafcoZFJD1oIw1XivzaysF/c6 U0JQbdH/yHhsyVczsPbMLCOfgev50bjpeN4z24Sa+wLrhR83PeOb2K6ZOYtGtudDwzO8 96TGIttUx76LtXFdKoh3O1C4A+JnhcZBEPh8cLVOczCWR6/d4z078vv8mvaz117VEgln j5BmSaqCoPrGdNijgk+5F0oSMzbfLWyLu1/u+Dxr+LWA5GatJlZQzET4EO9DzB/0i+1P p8mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=t3e1YzBOab01uped4oYtA4WXVL1rQZncM3tUk9ZAUqE=; b=jW1EAS29OIYlGZJcsn9iQJfVOls30VkyxwumdJno1eP+3ajNwzQHL+1R7WorL6VlFi 2Ly8f1VlLhZmllhqSQhZsXRGM94UFYZ2bwb9S36mkB/teGQl78ZF7Zt7vw5UKfGDuTSs r9lSEBNCpbxsqOxru2zDpWuWdYDjVgCzplDpUPBBwJhVcYCdxznoFFEJDTCPdoqncFL9 aw1VUssSjGQWXBZ9lFIqUATyPtOgFdguZWUrcWNUJUcTUSI3WmT5kSZkqlPKGZLLWzSX kyfWUCP06pxCivHB4ZANKTL/NJeqeN6UqV5l6QgAwYG+7oJ3Cg1urnzQ1e47x2F+Ht9d owCg== X-Gm-Message-State: AOAM531py1NnGspcHHLq/X6v9IxwSNjtE7YS2pS/NcjkGEEQ0Yy4i1yk mHaqDFCLtYG9Rpzwc5CCxJWklrFikV5OU3lWVYAQyQ3xCdk= X-Google-Smtp-Source: ABdhPJxZqIM9B6dFgUVfgkc7QQo+DmDjUO274XiQxG05C9m9FyNJTHkhBXwSqTau+ZZYFzqP17oJwwnvorpPOHBI4mE= X-Received: by 2002:adf:e4cc:: with SMTP id v12mr29263871wrm.183.1592250747669; Mon, 15 Jun 2020 12:52:27 -0700 (PDT) MIME-Version: 1.0 From: Douglas Perrin Date: Mon, 15 Jun 2020 15:52:16 -0400 Message-ID: Subject: Re: Import Reusable org-babel snippet using #+SETUPFILE To: emacs-orgmode@gnu.org Content-Type: multipart/alternative; boundary="0000000000003552e305a824c423" Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=doug2024@gmail.com; helo=mail-wr1-x42b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=pWaD8Ahy; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.29 X-TUID: tydHUNocHSUK --0000000000003552e305a824c423 Content-Type: text/plain; charset="UTF-8" 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). Regards, Doug --------------------------------------------------------------------------------------------------------------------------------- TemplatingExample.org --------------------------------------------------------------------------------------------------------------------------------- #+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") #+end_src * 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 /dev/null" #+end_src * run IN contaner #+begin_src bash :results output :dir (concat "/docker:" `,*DockerName* ":/root/Workdir/") ls #+end_src # Local Variables: # eval: (org-babel-lob-ingest "Template-Loader.org") # eval: (org-sbe "Init-Template") # eval: (org-sbe "Execute-On-Load") # End: --------------------------------------------------------------------------------------------------------------------------------- Template-Loader.org --------------------------------------------------------------------------------------------------------------------------------- #+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 templating (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") #+end_src --0000000000003552e305a824c423 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Salomon Turgman,
I do this a lot and have had success=C2=A0usi= ng a combination=C2=A0of #+SETUPFILE to bring in names and configuration, a= nd org-sbe to do initialization. I mix emacs vars and org names in my sourc= e headers with back quoting.=C2=A0

The following= =C2=A0example has a template file containing user/local information. This i= s brought=C2=A0into the example file, on load, through #:eval calling org-b= abel-lob-ingest and org-sbe, in addition, parameters are pulled in with #+S= ETUPFILE and the same template file name. The end result for this example i= s a running docker image with access to local paths and "remote" = execution=C2=A0via tramp. More complex=C2=A0orchestration=C2=A0and actions = in the template are certainly=C2=A0possible using org-sbe calls in the init= elisp source=C2=A0blocks but hopefully,=C2=A0this shows the flavor of what= can be done.

In addition to avoiding code duplica= tion, I have found this to be very effective when my group is all working f= rom the same org file (via git) but everyone has their own template file wi= th credentials, local=C2=A0paths, and org more preferences (ie showstars).= =C2=A0
Regards,
Doug

---------= ---------------------------------------------------------------------------= ---------------------------------------------
TemplatingExample.o= rg
--------------------------------------------------------------= -------------------------------------------------------------------
#+SETUPFILE: Template-Loader.org

* Init Code, run when file is opened
#+name: Execute-On-Lo= ad
#+begin_src elisp=C2=A0 :results output
=C2=A0 =C2= =A0;; for this the container=C2=A0and image have the same name
= =C2=A0 =C2=A0 (setq *DockerName* "ContanerName")
#+end_= src

* Run Contaner
#+begin_sr= c bash=C2=A0 :results raw drawer=C2=A0:var DockerName=3D`,*DockerName* Dock= erHubUID=3D`,*DockerHubUID* containerName=3D`,*DockerContainer* LocalWorkPa= th=3D`,*LocalWorkPath* LocalDataPath=3D`,*LocalDataPath*
=C2=A0 = =C2=A0docker run --rm -d \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -v = $LocalWorkPath:/root/Workdir \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= -v $LocalDataPath:/root/Data \
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 --name $DockerName $DockerHubUID/$DockerName bash -c "tail -f /dev= /null"
=C2=A0 #+end_src

* run= IN contaner=C2=A0
#+begin_src bash=C2=A0 :results output :dir (c= oncat "/docker:" `,*DockerName* ":/root/Workdir/")=C2= =A0
ls
#+end_src

# Local V= ariables:
# eval: (org-babel-lob-ingest "Template-Loader.org= ")
# eval: (org-sbe "Init-Template")
# e= val: (org-sbe "Execute-On-Load")
# End:

-----------------------------------------------------------= ----------------------------------------------------------------------
<= /div>
Template-Loader.org
-------------------------------= ---------------------------------------------------------------------------= -----------------------
#+STARTUP: showstars= =C2=A0
#+PROPERTY: header-args :mkdirp yes

#+name: Init-Template
#+begin_src emacs-lisp :results none
=C2=A0 ;; This is called expecitly via org-sbe in the buffer that wi= ll uses the templating
=C2=A0 =C2=A0 (setq *DockerHubUID* "M= yUserName")
=C2=A0 =C2=A0 (setq *LocalWorkPath* "/run/d= esktop/mnt/host/c/Users/.....")
=C2=A0 =C2=A0 (setq *LocalDa= taPath* "/run/desktop/mnt/host/d/devData/")

<= div>=C2=A0 ;; ingest=C2=A0+ SBE can be used to bring in a hierarchy of temp= lates=C2=A0
=C2=A0 (org-babel-lob-ingest "./GroupTools/Gener= alORGTools.org")
=C2=A0 (org-sbe "GeneralORGTools.org&q= uot;)

#+end_src

--0000000000003552e305a824c423--