TestRunnable.py 1.83 KB
Newer Older
1

2
# Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Brandon Walts's avatar
Brandon Walts committed
3
# Copyright [2016-2019] EMBL-European Bioinformatics Institute
4 5 6 7 8 9 10 11 12 13 14 15 16
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

17 18 19 20 21
# standaloneJob.pl eHive.examples.TestRunnable -language python3

import os
import subprocess

22
import eHive
23

24
class TestRunnable(eHive.BaseRunnable):
25
    """Simple Runnable to test as a standaloneJob"""
26 27 28

    def param_defaults(self):
        return {
29 30
            'alpha' : 37,
            'beta' : 78
31 32 33 34
        }

    def fetch_input(self):
        self.warning("Fetch the world !")
35 36
        print("alpha is", self.param_required('alpha'))
        print("beta is", self.param_required('beta'))
37 38
        self.temp_dir = self.worker_temp_directory()
        print("my directory name is", self.temp_dir)
39 40 41

    def run(self):
        self.warning("Run the world !")
42 43 44
        s = self.param('alpha') + self.param('beta')
        print("set gamma to", s)
        self.param('gamma', s)
45 46
        self.greeting_path = os.path.join(self.temp_dir, "hello")
        subprocess.check_call(["touch", self.greeting_path])
47 48 49 50

    def write_output(self):
        self.warning("Write to the world !")
        print("gamma is", self.param('gamma'))
51
        self.dataflow( {'gamma': self.param('gamma')}, 2 )
52
        print("Greetings in place:", os.path.exists(self.greeting_path))
53