From 5aaef1fc620e9f0ef539654b720eadaa28c2fd7d Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Tue, 30 Aug 2011 01:10:42 +0200 Subject: [PATCH] Add small library for running jobs with different programs --- application/libraries/Program_runner.php | 46 ++++++++++++++++++++++++ application/libraries/programs/Scatt.php | 42 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 application/libraries/Program_runner.php create mode 100644 application/libraries/programs/Scatt.php diff --git a/application/libraries/Program_runner.php b/application/libraries/Program_runner.php new file mode 100644 index 0000000..3b9184e --- /dev/null +++ b/application/libraries/Program_runner.php @@ -0,0 +1,46 @@ + 'scatt'); + + foreach ($defaults as $key => $val) { + if (isset($params[$key]) && $params[$key] !== "") { + $defaults[$key] = $params[$key]; + } + } + + extract($defaults); + + $this->CI =& get_instance(); + + // load the requested programs library + $this->CI->load->library('programs/' . $program_driver, array()); + // make calc to refer to current library + $this->driver =& $this->CI->$program_driver; + + log_message('debug', "Program Runner Class Initialized and loaded. Driver used: " . $program_driver); + } + + /** + * Creates a job from the specified trial. + * + * @param string $trialId + */ + public function createJob($trialId) { + if ($this->driver->_createJob($trialId)) { + $this->CI->load->model('job'); + $this->CI->job->create(array('trial_id' => $trialId, 'started_by' => $this->CI->session->userdata('user_id'))); + } + return true; + } + +} diff --git a/application/libraries/programs/Scatt.php b/application/libraries/programs/Scatt.php new file mode 100644 index 0000000..deee038 --- /dev/null +++ b/application/libraries/programs/Scatt.php @@ -0,0 +1,42 @@ + + */ +class Scatt extends Program_runner { + + /** + * + * @param unknown_type $params + */ + public function __construct($params) { + $this->CI =& get_instance(); + extract($params); + + $this->CI->load->model('program'); + $this->program = $this->CI->program->getByDriver(strtolower(__CLASS__)); + + log_message('debug', "Scatt Class Initialized"); + } + + /** + * + * @param unknown_type $trialId + */ + public function _createJob($trialId) { + $this->CI->load->library('parser'); + + $trial = $this->CI->trial->getById($trialId); + + $path = FCPATH . 'uploads/' . $trial['project_id'] . '/' . $trial['id'] . '/'; + $handler = fopen($path . 'default.calc', "w"); + + $data['parameters'] = $this->CI->trial->getParameters($trialId); + + @fwrite($handler, $this->CI->parser->parse_string($this->program['config_template'], $data, true)); + @fclose($handler); + + return true; + } +} \ No newline at end of file