Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_install(self):
"""ensure that singularity is installed, and exit if not.
"""
if check_install() is not True:
bot.exit("Cannot find Singularity! Is it installed?")
def get_container_id(self, container_id=None):
""" a helper function shared between functions that will return a
container_id. First preference goes to a container_id provided by
the user at runtime. Second preference goes to the container_id
instantiated with the client.
Parameters
==========
container_id: image uri to parse (required)
"""
# The user must provide a container_id, or have one with the client
if container_id is None and self.container_id is None:
bot.exit("You must provide a container_id.")
# Choose whichever is not None, with preference for function provided
container_id = container_id or self.container_id
return container_id
def main(args, options):
if check_install() is not True:
bot.error("Cannot find Singularity! Is it installed?")
sys.exit(1)
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
def main(args, parser, subparser):
if check_install() is not True:
bot.error("Cannot find Singularity! Is it installed?")
sys.exit(1)
def _run_checks(self):
"""basic sanity checks for the file name (and others if needed) before
attempting parsing.
"""
if self.filename is not None:
# Does the recipe provided exist?
if not os.path.exists(self.filename):
bot.exit("Cannot find %s, is the path correct?" % self.filename)
# Ensure we carry fullpath
self.filename = os.path.abspath(self.filename)
parser = get_parser('singularity')
# If the parser still isn't defined, no go.
if parser is None:
bot.exit('Please provide a Dockerfile or Singularity recipe, or define the --parser type.')
# If the writer needs auto-detect
if args.writer == "auto":
if parser.name == "docker":
writer = get_writer('singularity')
else:
writer = get_writer('docker')
# If the writer still isn't defined, no go
if writer is None:
bot.exit('Please define the --writer type.')
# Initialize the chosen parser
recipeParser = parser(args.files[0])
# By default, discover entrypoint / cmd from Dockerfile
entrypoint = "/bin/bash"
force = False
if args.entrypoint is not None:
entrypoint = args.entrypoint
# This is only done if the user intended to print json here
recipeParser.entrypoint = args.entrypoint
recipeParser.cmd = None
force = True
if recipe is None:
recipe = "Singularity"
if not os.path.exists(recipe):
bot.exit("Cannot find %s, exiting." % image)
if image is None:
if re.search("(docker|shub|library)://", recipe) and not robot_name:
image = self._get_filename(recipe, ext)
else:
image = "%s.%s" % (self.RobotNamer.generate(), ext)
# Does the user want a custom build folder?
if build_folder is not None:
if not os.path.exists(build_folder):
bot.exit("%s does not exist!" % build_folder)
image = os.path.join(build_folder, image)
# The user wants to run an isolated build
if isolated:
cmd.append("--isolated")
if sandbox:
cmd.append("--sandbox")
elif writable:
cmd.append("--writable")
cmd = cmd + options + [image, recipe]
if not stream:
self._run_command(
"""
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"
if "version 3" in self.version():
subgroup = ["instance", "start"]
cmd = self._init_command(subgroup, singularity_options)
# Add options, if they are provided
if not isinstance(options, list):
options = [] if options is None else options.split(" ")
# Assemble the command!
cmd = cmd + options + [image, self.name]
ext = "sif"
# Force the build if the image / sandbox exists
if force:
cmd.append("--force")
# No image provided, default to use the client's loaded image
if recipe is None:
recipe = self._get_uri()
# If it's still None, try default build recipe
if recipe is None:
recipe = "Singularity"
if not os.path.exists(recipe):
bot.exit("Cannot find %s, exiting." % image)
if image is None:
if re.search("(docker|shub|library)://", recipe) and not robot_name:
image = self._get_filename(recipe, ext)
else:
image = "%s.%s" % (self.RobotNamer.generate(), ext)
# Does the user want a custom build folder?
if build_folder is not None:
if not os.path.exists(build_folder):
bot.exit("%s does not exist!" % build_folder)
image = os.path.join(build_folder, image)
# The user wants to run an isolated build
if isolated:
cmd.append("--isolated")