From 345bed28b8e66859224e8a560cad6621d5c17e3f Mon Sep 17 00:00:00 2001
From: Klaus Reuter <khr@mpcdf.mpg.de>
Date: Thu, 25 Jan 2024 13:16:30 +0100
Subject: [PATCH] version bump to 0.1.10, introducing the cache subcommand

---
 README.md              | 30 ++++++++++++++++++++++++++++++
 condainer/condainer.py | 14 ++++++++++++++
 condainer/main.py      |  3 +++
 condainer/version.py   |  2 +-
 4 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index c7dd2a8..4a8e9ea 100644
--- a/README.md
+++ b/README.md
@@ -199,6 +199,36 @@ No installer is downloaded in case that variable is defined.
 * Condainer environments are read-only and immutable. In case you need to add packages, rebuild the image.
 * Within the same project, when experimenting, you can toggle between multiple existing squashfs images by editing the UUID string in `condainer.yml`.
 
+## `cnd` command line flags
+
+```text
+$ cnd --help
+usage: cnd [-h] [-q] [-d DIRECTORY] [-y] {init,build,exec,mount,umount,prereq,status,cache,version} ...
+
+Create and manage conda environments based on compressed squashfs images.
+
+positional arguments:
+  {init,build,exec,mount,umount,prereq,status,cache,version}
+    init                initialize directory with config files
+    build               build containerized conda environment
+    exec                execute command within containerized conda environment
+    mount               mount containerized conda environment
+    umount              unmount ("eject") containerized conda environment
+    prereq              check if the necessary tools are installed
+    status              print status information about the condainer
+    cache               put condainer image into the page cache of the OS
+    version             print version information and exit
+
+optional arguments:
+  -h, --help            show this help message and exit
+  -q, --quiet           be quiet, do not write to stdout unless an error occurs
+  -d DIRECTORY, --directory DIRECTORY
+                        condainer project directory, the default is the current working directory
+  -y, --dryrun          dry run, do not actually do any operations, instead print information on what would be done
+
+More information at https://gitlab.mpcdf.mpg.de/mpcdf/condainer
+```
+
 ## Source Code and Contact
 
 Condainer is available under the MIT license at <https://gitlab.mpcdf.mpg.de/mpcdf/condainer> or <https://github.com/reuterk/condainer>.
diff --git a/condainer/condainer.py b/condainer/condainer.py
index f27d790..d07070f 100644
--- a/condainer/condainer.py
+++ b/condainer/condainer.py
@@ -552,6 +552,20 @@ def status(args):
     print(f" - image mounted     : {is_mounted(cfg)}")
 
 
+def cache(args):
+    """Read squashfs image file once to motivate the OS to cache it.
+    """
+    cfg = get_cfg()
+    squashfs_image = get_image_filename(cfg)
+    cmd = f"dd if={squashfs_image} of=/dev/null bs=1M".split()
+    if args.dryrun:
+        print(f"dryrun: {' '.join(cmd)}")
+    else:
+        proc = subprocess.Popen(cmd, shell=False)
+        proc.communicate()
+        assert(proc.returncode == 0)
+
+
 def test(args):
     """Dummy function for quick testing
     """
diff --git a/condainer/main.py b/condainer/main.py
index 8762286..48887f5 100644
--- a/condainer/main.py
+++ b/condainer/main.py
@@ -38,6 +38,7 @@ def get_args():
     subparsers.add_parser('umount', help='unmount ("eject") containerized conda environment')
     subparsers.add_parser('prereq', help='check if the necessary tools are installed')
     subparsers.add_parser('status', help='print status information about the condainer')
+    subparsers.add_parser('cache', help='put condainer image into the page cache of the OS')
     # subparsers.add_parser('test', help=argparse.SUPPRESS)
 
     subparsers.add_parser('version', help='print version information and exit')
@@ -69,5 +70,7 @@ def cli():
         condainer.test(args)
     elif args.subcommand == 'status':
         condainer.status(args)
+    elif args.subcommand == 'cache':
+        condainer.cache(args)
     elif args.subcommand == 'version':
         print(version.get_descriptive_version_string())
diff --git a/condainer/version.py b/condainer/version.py
index b5b1a9d..06b429d 100644
--- a/condainer/version.py
+++ b/condainer/version.py
@@ -3,7 +3,7 @@
 Single location for the version information.
 """
 
-ver = (0, 1, 9)
+ver = (0, 1, 10)
 
 def get_version_string():
     """Return the full version number."""
-- 
GitLab