コード例 #1
0
    def execute(self, results):
        """
        Executes the action_block in the PinFile
        """

        for action in self.action_data["actions"]:
            result = {}

            res_str = json.dumps(results, separators=(',', ':'))
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            file_path = "{0}/{1}".format(path, action)

            command = self.add_ctx_params(file_path, context)
            run_data = run_rb(command, arguments=res_str)

            print(run_data.stdout)

            data = run_data.stderr
            try:
                if data:
                    result['data'] = json.loads(data)
            except ValueError:
                print("Warning: '{0}' is not a valid JSON object.  "
                      "Data from this hook will be discarded".format(data))

            result['return_code'] = run_data.exitcode
            result['state'] = str(self.state)
            results.append(result)

        return results
コード例 #2
0
    def execute(self):
        """
        Executes the action_block in the PinFile
        """

        for action in self.action_data["actions"]:
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            file_path = "{0}/{1}".format(path, action)

            command = self.add_ctx_params(file_path, context)
            success = run_rb(command)
            return success
コード例 #3
0
    def execute(self):

        """
        Executes the action_block in the PinFile
        """

        for action in self.action_data["actions"]:
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            file_path = "{0}/{1}".format(
                        path,
                        action
            )

            command = self.add_ctx_params(file_path, context)
            success = run_rb(command)
            return success
コード例 #4
0
    def execute(self, results):
        """
        Executes the action_block in the PinFile
        """

        tmpdir = tempfile.mkdtemp()
        for action in self.action_data["actions"]:
            result = {}

            data_path = os.path.join(tmpdir, action)
            res_str = json.dumps(results, separators=(',', ':'))
            context = self.action_data.get("context", True)
            path = self.action_data["path"]
            hook_path = "{0}/{1}".format(path, action)

            command = self.add_ctx_params(hook_path, res_str, data_path,
                                          context)
            run_data = run_rb(command, arguments=res_str)

            try:
                data_file = open(data_path, 'r')
                data = data_file.read()
                if data:
                    result['data'] = json.loads(data)
                data_file.close()
            except IOError:
                # if an IOError is thrown, the file does not exist
                result['data'] = ''
            except ValueError:
                print("Warning: '{0}' is not a valid JSON object.  "
                      "Data from this hook will be discarded".format(data))

            if not run_data:
                result['return_code'] = 1
            else:
                result['return_code'] = 0
            result['state'] = str(self.state)
            results.append(result)

        shutil.rmtree(tmpdir)
        return results
コード例 #5
0
ファイル: test_SHELL.py プロジェクト: Ripnrip/EyePop-Scraper
 def test_run_rb_fail_suppress_exitstatus_false(self):
     with self.assertRaises(SystemExit):
         out = run_rb(
             self.ruby_fail_path, suppress_exit_status_call=False
         )  # when suppress_exit_status=True, Python script stopped prematurely
コード例 #6
0
ファイル: test_SHELL.py プロジェクト: Ripnrip/EyePop-Scraper
 def test_run_rb_fail_suppress_stderr(self):
     out = run_rb(self.ruby_fail_path, suppress_stderr=True)
     self.assertEqual(False, out)  # returns False
コード例 #7
0
ファイル: test_SHELL.py プロジェクト: Ripnrip/EyePop-Scraper
 def test_run_rb_success_suppress_stdout(self):
     out = run_rb(self.ruby_success_path, suppress_stdout=True)
     self.assertEqual(
         b'success\n',
         out)  # still returns a value, does not print to std out
コード例 #8
0
ファイル: test_SHELL.py プロジェクト: Ripnrip/EyePop-Scraper
 def test_run_rb_success(self):
     out = run_rb(self.ruby_success_path)
     self.assertEqual(b'success\n', out)
コード例 #9
0
ファイル: test_SHELL.py プロジェクト: chrisidefix/naked
 def test_run_rb_fail_suppress_exitstatus_false(self):
     with self.assertRaises(SystemExit):
         out = run_rb(self.ruby_fail_path, suppress_exit_status_call=False) # when suppress_exit_status=True, Python script stopped prematurely
コード例 #10
0
ファイル: test_SHELL.py プロジェクト: chrisidefix/naked
 def test_run_rb_fail_suppress_stderr(self):
     out = run_rb(self.ruby_fail_path, suppress_stderr=True)
     self.assertEqual(False, out)  # returns False
コード例 #11
0
ファイル: test_SHELL.py プロジェクト: chrisidefix/naked
 def test_run_rb_success_suppress_stdout(self):
     out = run_rb(self.ruby_success_path, suppress_stdout=True)
     self.assertEqual(b'success\n', out) # still returns a value, does not print to std out
コード例 #12
0
ファイル: test_SHELL.py プロジェクト: chrisidefix/naked
 def test_run_rb_success(self):
     out = run_rb(self.ruby_success_path)
     self.assertEqual(b'success\n', out)