Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
binds = []
# Case 1: No binds provided
if not bindlist:
return binds
# Case 2: provides a long string or non list, and must be split
if not isinstance(bindlist, list):
bindlist = bindlist.split(" ")
for bind in bindlist:
# Still cannot be None
if bind:
bot.debug("Adding bind %s" % bind)
binds += ["--bind", bind]
# Check that exists on host
host = bind.split(":")[0]
if not os.path.exists(host):
bot.error("%s does not exist on host." % bind)
sys.exit(1)
return binds
fromHeader: the fromHeader parsed from self.from, possibly with AS
"""
# Derive if there is a named layer
match = re.search("AS (?P.+)", fromHeader, flags=re.I)
if match:
layer = match.groups("layer")[0].strip()
# If it's the first layer named incorrectly, we need to rename
if len(self.recipe) == 1 and list(self.recipe)[0] == "spython-base":
self.recipe[layer] = deepcopy(self.recipe[self.active_layer])
del self.recipe[self.active_layer]
else:
self.active_layer_num += 1
self.recipe[layer] = Recipe(self.filename, self.active_layer_num)
self.active_layer = layer
bot.debug(
"Active layer #%s updated to %s"
% (self.active_layer_num, self.active_layer)
)
if not defined, the attribute name is used.
"""
# Default section name is the same as attribute
if name is None:
name = attribute
# Put a space between sections
section = ["\n"]
# Only continue if we have the section and it's not empty
try:
section = getattr(self.recipe[self.stage], attribute)
except AttributeError:
bot.debug("Recipe does not have section for %s" % attribute)
return section
# if the section is empty, don't print it
if not section:
return section
# Files
if attribute in ["files", "labels"]:
return create_keyval_section(section, name, stage)
# An environment section needs exports
if attribute in ["environ"]:
return create_env_section(section, name)
# Post, Setup
return finish_section(section, name)
if not defined, the attribute name is used.
'''
# Default section name is the same as attribute
if name is None:
name = attribute
# Put a space between sections
section = ['\n']
# Only continue if we have the section and it's not empty
try:
section = getattr(self, attribute)
except AttributeError:
bot.debug('Recipe does not have section for %s' %attribute)
return section
# if the section is empty, don't print it
if len(section) == 0:
return section
# Files or Labels
if attribute in ['labels', 'files']:
return create_keyval_section(section, name)
# An environment section needs exports
if attribute in ['environ']:
return create_env_section(section, name)
# Post, Setup
return finish_section(section, name)
self._load_from(fromHeader)
# Identify stage
elif re.search("stage:", stripped, re.IGNORECASE):
stage = re.sub("stage:", "", stripped.lower()).strip()
self._multistage("as %s" % stage)
self._load_from(fromHeader)
# Comment
elif stripped.startswith("#") and stripped not in comments:
comments.append(stripped)
# Section
elif stripped.startswith("%"):
section, layer = self._get_section(stripped)
bot.debug("Found section %s" % section)
# If we have a section, and are adding it
elif section is not None:
lines = [line] + lines
self._load_section(lines=lines, section=section, layer=layer)
self._comments(comments)
line: the line from the recipe file to parse for FROM
recipe: the recipe object to populate.
"""
fromHeader = self._setup("FROM", line)
# Do we have a multistge build to update the active layer?
self._multistage(fromHeader[0])
# Now extract the from header, make args replacements
self.recipe[self.active_layer].fromHeader = self._replace_from_dict(
re.sub("AS .+", "", fromHeader[0], flags=re.I), self.args
)
if "scratch" in self.recipe[self.active_layer].fromHeader:
bot.warning("scratch is no longer available on Docker Hub.")
bot.debug("FROM %s" % self.recipe[self.active_layer].fromHeader)
def _setup(self, action, line):
""" replace the command name from the group, alert the user of content,
and clean up empty spaces
"""
bot.debug("[in] %s" % line)
# Replace ACTION at beginning
line = re.sub("^%s" % action, "", line)
# Handle continuation lines without ACTION by padding with leading space
line = " " + line
# Split into components
return [x for x in self._split_line(line) if x not in ["", None]]
def setenv(self, variable, value):
'''set an environment variable for Singularity
Parameters
==========
variable: the variable to set
value: the value to set
'''
os.environ[variable] = value
os.putenv(variable, value)
bot.debug('%s set to %s' % (variable, value))