How to use the spython.utils.check_install function in spython

To help you get started, we’ve selected a few spython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github singularityhub / singularity-cli / spython / client / siflist.py View on Github external
def main(args, parser, subparser):

    if check_install() is not True:
        bot.error("Cannot find Singularity! Is it installed?")
        sys.exit(1)
github singularityhub / singularity-cli / spython / image / cmd / create.py View on Github external
def create(self, image_path, size=1024, sudo=False, singularity_options=None):
    """create will create a a new image

        Parameters
        ==========
        image_path: full path to image
        size: image sizein MiB, default is 1024MiB
        filesystem: supported file systems ext3/ext4 (ext[2/3]: default ext3
        singularity_options: a list of options to provide to the singularity client
    """
    from spython.utils import check_install

    check_install()

    cmd = self.init_command("image.create", singularity_options)
    cmd = cmd + ["--size", str(size), image_path]

    output = self.run_command(cmd, sudo=sudo)
    self.println(output)

    if not os.path.exists(image_path):
        bot.exit("Could not create image %s" % image_path)

    return image_path
github singularityhub / singularity-cli / spython / main / inspect.py View on Github external
def inspect(
    self, image=None, json=True, app=None, quiet=True, singularity_options=None
):
    """inspect will show labels, defile, runscript, and tests for an image
    
       Parameters
       ==========
       image: path of image to inspect
       json: print json instead of raw text (default True)
       quiet: Don't print result to the screen (default True)
       app: if defined, return help in context of an app
       singularity_options: a list of options to provide to the singularity client

    """
    check_install()

    # No image provided, default to use the client's loaded image
    if not image:
        image = self._get_uri()

    # If there still isn't an image, exit on error
    if not image:
        bot.exit("Please provide an image to inspect.")

    cmd = self._init_command("inspect", singularity_options)
    if app:
        cmd = cmd + ["--app", app]

    options = ["e", "d", "l", "r", "hf", "t"]

    # After Singularity 3.0, helpfile was changed to H from
github singularityhub / singularity-cli / spython / instance / cmd / start.py View on Github external
image: optionally, an image uri (if called as a command from Client)
       name: a name for the instance
       sudo: if the user wants to run the command with sudo
       capture: capture output, default is False. With True likely to hang.
       args: arguments to provide to the instance (supported Singularity 3.1+)
       singularity_options: a list of options to provide to the singularity client
       options: a list of tuples, each an option to give to the start command
                [("--bind", "/tmp"),...]

       USAGE: 
       singularity [...] instance.start [...]  

    """
    from spython.utils import run_command, check_install

    check_install()

    # If name provided, over write robot (default)
    if name is not None:
        self.name = name

    # If an image isn't provided, we have an initialized instance
    if image is None:

        # Not having this means it was called as a command, without an image
        if not hasattr(self, "_image"):
            bot.exit("Please provide an image, or create an Instance first.")

        image = self._image

    # Derive subgroup command based on singularity version
    subgroup = "instance.start"
github singularityhub / singularity-cli / spython / client / mount.py View on Github external
def main(args, parser, subparser):

    if check_install() is not True:
        bot.error("Cannot find Singularity! Is it installed?")
        sys.exit(1)
github singularityhub / singularity-cli / spython / client / pull.py View on Github external
def main(args, parser, subparser):

    if check_install() is not True:
        bot.error("Cannot find Singularity! Is it installed?")
        sys.exit(1)
github singularityhub / singularity-cli / spython / instance / cmd / iutils.py View on Github external
def get(self, name, return_json=False, quiet=False, singularity_options=None):
    """get is a list for a single instance. It is assumed to be running,
       and we need to look up the PID, etc.
    """
    from spython.utils import check_install

    check_install()

    # Ensure compatible for singularity prior to 3.0, and after 3.0
    subgroup = "instance.list"

    if "version 3" in self.version():
        subgroup = ["instance", "list"]

    cmd = self._init_command(subgroup, singularity_options)

    cmd.append(name)
    output = self.run_command(cmd, quiet=True)

    # Success, we have instances

    if output["return_code"] == 0:
github singularityhub / singularity-cli / spython / instance / cmd / stop.py View on Github external
Parameters
       ==========
       name: a name for the instance
       sudo: if the user wants to run the command with sudo
       singularity_options: a list of options to provide to the singularity client
       timeout: forcebly kill non-stopped instance after the
                timeout specified in seconds

       USAGE: 
       singularity [...] instance.stop [...] 

    """
    from spython.utils import check_install, run_command

    check_install()

    subgroup = "instance.stop"

    if "version 3" in self.version():
        subgroup = ["instance", "stop"]
        if timeout:
            subgroup += ["-t", str(timeout)]

    cmd = self._init_command(subgroup, singularity_options)

    # If name is provided assume referencing an instance
    instance_name = self.name
    if name is not None:
        instance_name = name
    cmd = cmd + [instance_name]
github singularityhub / singularity-cli / spython / main / execute.py View on Github external
app: if not None, execute a command in context of an app
        writable: This option makes the file system accessible as read/write
        contain: This option disables the automatic sharing of writable
                 filesystems on your host
        options: an optional list of options to provide to execute.
        singularity_options: a list of options to provide to the singularity client
        bind: list or single string of bind paths.
             This option allows you to map directories on your host system to
             directories within your container using bind mounts
        nv: if True, load Nvidia Drivers in runtime (default False)
        return_result: if True, return entire json object with return code
                       and message result not (default)
    """
    from spython.utils import check_install

    check_install()

    cmd = self._init_command("exec", singularity_options)

    # nv option leverages any GPU cards
    if nv:
        cmd += ["--nv"]

    # If the image is given as a list, it's probably the command
    if isinstance(image, list):
        command = image
        image = None

    if command is not None:

        # No image provided, default to use the client's loaded image
        if image is None:
github singularityhub / singularity-cli / spython / main / execute.py View on Github external
image: full path to singularity image
        app: if not None, execute a shell in context of an app
        writable: This option makes the file system accessible as read/write
        contain: This option disables the automatic sharing of writable
                 filesystems on your host
        options: an optional list of options to provide to shell.
        singularity_options: a list of options to provide to the singularity client
        bind: list or single string of bind paths.
             This option allows you to map directories on your host system to
             directories within your container using bind mounts
        nv: if True, load Nvidia Drivers in runtime (default False)
    """
    from spython.utils import check_install

    check_install()

    cmd = self._init_command("shell", singularity_options)

    # nv option leverages any GPU cards
    if nv:
        cmd += ["--nv"]

    # Does the user want to use bind paths option?
    if bind is not None:
        cmd += self._generate_bind_list(bind)

    # Does the user want to run an app?
    if app is not None:
        cmd = cmd + ["--app", app]

    # Add additional options