Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetupRubyEnvironmentAction(BaseAction):
action_type = "setup_ruby_environment"
_keys = ["repo", "packages"]
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetupPythonEnvironmentAction(BaseAction):
action_type = "setup_python_environment"
_keys = ["repo", "packages"]
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetupVirtualenvAction(BaseAction):
action_type = "setup_virtualenv"
_keys = ["use_requirements_file", "python", "requirements"]
def __init__(self, elem):
use_reqs = elem.attrib.get("use_requirements_file", "True")
self.use_requirements_file = asbool(use_reqs)
self.python = elem.get('python', 'python')
def to_bash(self):
return ["chmod %s %s" % (m["mode"], m["target"]) for m in self.mods], []
class MakeInstallAction(BaseAction):
action_type = "make_install"
_keys = []
def __init__(self, elem):
pass
def to_bash(self):
return ["make install"], []
class AutoconfAction(BaseAction):
action_type = "autoconf"
_keys = ["options"]
def __init__(self, elem):
self.options = elem.text
def to_bash(self):
if self.options:
raise NotImplementedError("Options with action autoconf not implemented yet.")
return ['./configure', 'make', 'make install'], []
class ChangeDirectoryAction(BaseAction):
action_type = "change_directory"
_keys = ["directory"]
mods = []
file_els = elem.findall("file")
assert file_els is not None
for mod_elem in file_els:
mod = {}
mod["mode"] = mod_elem.attrib["mode"]
mod["target"] = mod_elem.text
mods.append(mod)
self.mods = mods
assert self.mods
def to_bash(self):
return ["chmod %s %s" % (m["mode"], m["target"]) for m in self.mods], []
class MakeInstallAction(BaseAction):
action_type = "make_install"
_keys = []
def __init__(self, elem):
pass
def to_bash(self):
return ["make install"], []
class AutoconfAction(BaseAction):
action_type = "autoconf"
_keys = ["options"]
def __init__(self, elem):
self.options = elem.text
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetupVirtualenvAction(BaseAction):
action_type = "setup_virtualenv"
_keys = ["use_requirements_file", "python", "requirements"]
def __init__(self, elem):
use_reqs = elem.attrib.get("use_requirements_file", "True")
self.use_requirements_file = asbool(use_reqs)
self.python = elem.get('python', 'python')
self.requirements = elem.text or 'requirements.txt'
class SetupREnvironmentAction(BaseAction):
action_type = "setup_r_environment"
_keys = ["repo", "packages"]
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetEnvironmentForInstallAction(BaseAction):
action_type = "set_environment_for_install"
def __init__(self, elem):
pass
def to_bash(self):
# TODO - How could we resolve/check the dependencies?
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetupPythonEnvironmentAction(BaseAction):
action_type = "setup_python_environment"
_keys = ["repo", "packages"]
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetupVirtualenvAction(BaseAction):
action_type = "setup_virtualenv"
_keys = ["use_requirements_file", "python", "requirements"]
def __init__(self, elem):
use_reqs = elem.attrib.get("use_requirements_file", "True")
self.use_requirements_file = asbool(use_reqs)
self.python = elem.get('python', 'python')
self.requirements = elem.text or 'requirements.txt'
class SetupREnvironmentAction(BaseAction):
action_type = "setup_r_environment"
_keys = ["repo", "packages"]
def __init__(self, elem):
self.parse_action_repo(elem)
def to_bash(self):
answer = []
for var in self.variables:
# Expand $INSTALL_DIR here?
if var.action == "set_to":
answer.append('export %s=%s' % (var.name, var.raw_value))
elif var.action == "prepend_to":
answer.append('export %s=%s:$%s' % (var.name, var.raw_value, var.name))
elif var.action == "append_to":
answer.append('export %s=$%s:%s' % (var.name, var.name, var.raw_value))
else:
raise ValueError("Undefined environment variable action %r" % var.action)
return answer, answer # Actions needed in env.sh here!
class ChmodAction(BaseAction):
action_type = "chmod"
_keys = ["mods"]
def __init__(self, elem):
mods = []
file_els = elem.findall("file")
assert file_els is not None
for mod_elem in file_els:
mod = {}
mod["mode"] = mod_elem.attrib["mode"]
mod["target"] = mod_elem.text
mods.append(mod)
self.mods = mods
assert self.mods
def to_bash(self):
# This is inserted into the if-else for a fresh download only.
# Note double space between checksum and filename:
answer.append(' echo "%s %s" | shasum -a 256 -c -' % (sha256sum, target_filename))
answer.append('fi')
return answer, downloaded_filename
def _commands_to_download_and_extract(url, target_filename=None, sha256sum=None):
answer, downloaded_filename = _commands_and_downloaded_file(url, target_filename, sha256sum)
# Now should we unpack the tar-ball etc?
answer.extend(_determine_compressed_file_folder(url, downloaded_filename, target_filename, sha256sum))
return answer, []
class DownloadByUrlAction(BaseAction):
action_type = "download_by_url"
_keys = ["url"]
def __init__(self, elem):
self.url = elem.text.strip()
assert self.url
self.sha256sum = elem.attrib.get("sha256sum", None)
self.target_filename = elem.attrib.get("target_filename", None)
def to_bash(self):
# See class DownloadByUrl in Galaxy,
# lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py
return _commands_to_download_and_extract(self.url, self.target_filename, self.sha256sum)
class DownloadFileAction(BaseAction):
action_type = "download_by_url"
_keys = ["url"]
def __init__(self, elem):
self.url = elem.text.strip()
assert self.url
self.sha256sum = elem.attrib.get("sha256sum", None)
self.target_filename = elem.attrib.get("target_filename", None)
def to_bash(self):
# See class DownloadByUrl in Galaxy,
# lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py
return _commands_to_download_and_extract(self.url, self.target_filename, self.sha256sum)
class DownloadFileAction(BaseAction):
action_type = "download_file"
_keys = ["url", "extract"]
def __init__(self, elem):
self.url = elem.text.strip()
self.extract = asbool(elem.attrib.get("extract", False))
self.sha256sum = elem.attrib.get("sha256sum", None)
self.target_filename = elem.attrib.get("target_filename", None)
def to_bash(self):
if self.extract:
return _commands_to_download_and_extract(self.url, self.target_filename, self.sha256sum)
else:
commands, downloaded_file = _commands_and_downloaded_file(self.url, self.target_filename, self.sha256sum)
return commands, []
def parse_action(self, action):
return BaseAction.from_elem(action, package=self)
def to_bash(self):
return ["cd %s" % self.directory], []
class MakeDirectoryAction(BaseAction):
action_type = "make_directory"
_keys = ["directory"]
def __init__(self, elem):
self.directory = elem.text
def to_bash(self):
return ["mkdir -p %s" % self.directory], []
class SetupPerlEnvironmentAction(BaseAction):
action_type = "setup_perl_environment"
_keys = ["repo", "packages"]
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)
class SetupRubyEnvironmentAction(BaseAction):
action_type = "setup_ruby_environment"
_keys = ["repo", "packages"]
def __init__(self, elem):
self.parse_action_repo(elem)
self.parse_package_elems(elem)