Example #1
0
def copy_template_files_to(destination, source_action_name):
    common.print_verbose("Looking for files to copy in: " + str(
        pathlib.Path(
            MetaModel(common.meta_model()).template_for_action(
                source_action_name))))
    files_to_copy = [
        str(p) for p in pathlib.Path(
            MetaModel(common.meta_model()).template_for_action(
                source_action_name)).glob("*")
    ]
    common.print_verbose("Found " + str(len(files_to_copy)) +
                         " files to copy.")
    command_to_run = ['/bin/cp', "-R", *files_to_copy, destination]
    common.run_command(command_to_run)
Example #2
0
def action_for(action_name):
  meta_model = MetaModel(common.meta_model())
  the_actions = list(filter(lambda a: common.action_name(a) == action_name, meta_model.actions()))
  if the_actions:
    return the_actions[0]
  else:
    return NoActionError(action_name)
Example #3
0
    def test_meta_model(self):
        common.set_meta_model(None)
        s = 'blah'
        os.getenv = MagicMock(return_value=s)

        self.assertEqual(common.meta_model(), s)
        os.getenv.assert_called_with("POWER_DAPS_META_MODEL",
                                     "power_daps/python3")
Example #4
0
src_dir = os.path.realpath(
    os.path.abspath(
        os.path.join(
            os.path.split(inspect.getfile(inspect.currentframe()))[0],
            "../src")))

if src_dir not in sys.path:
    sys.path.insert(0, src_dir)

from dap_core import common, dap

actions_dir = os.path.realpath(
    os.path.abspath(
        os.path.join(
            os.path.split(inspect.getfile(inspect.currentframe()))[0],
            "../../meta_models/" + common.meta_model() + "/src")))

if actions_dir not in sys.path:
    sys.path.insert(0, actions_dir)

from power_daps.python3.actions import default_action, deps_action
from unittest.mock import patch


class TestDap(unittest.TestCase):
    def test_run_gets_action_in_the_right_order(self):
        with patch('power_daps.python3.actions.default_action.action'):
            mocked_default_action = self.mock_default_action()

            dap.run("error", "power_daps/python3", ["default"])
Example #5
0
def add_to_git(d):
  os.chdir(d)
  git_path = shutil.which('git')
  git_add_command = [git_path, 'add', '.']
  common.run_command(git_add_command)

  git_commit_command = [git_path, 'commit', '-m', 'Initialized with power_daps template ' + common.meta_model()]
  common.run_command(git_commit_command)

  return 0, ""