public static function get_screenshots()
 {
     if (!empty(self::$screenshots)) {
         return self::$screenshots;
     } else {
         // Another thread is going on and thread empty so try to query the file-system for differences
         $screenshots = pts_file_io::glob(pts_module::save_dir() . 'screenshot-*.png');
         return array_diff($screenshots, self::$existing_screenshots);
     }
 }
Exemplo n.º 2
0
 private static function set_user_context($context_script, $trigger, $schedule_id, $process)
 {
     if (!empty($context_script)) {
         $context_file = pts_client::create_temporary_file();
         file_put_contents($context_file, $context_script);
         chmod($context_file, 0755);
         pts_file_io::mkdir(pts_module::save_dir());
         $storage_path = pts_module::save_dir() . 'memory.pt2so';
         $storage_object = pts_storage_object::recover_from_file($storage_path);
         $notes_log_file = pts_module::save_dir() . sha1($trigger . $schedule_id . $process);
         // We check to see if the context was already set but the system rebooted or something in that script
         if ($storage_object == false) {
             $storage_object = new pts_storage_object(true, true);
         } else {
             if ($storage_object->read_object('last_set_context_trigger') == $trigger && $storage_object->read_object('last_set_context_schedule') == $schedule_id && $storage_object->read_object('last_set_context_process') == $process) {
                 // If the script already ran once for this trigger, don't run it again
                 self::check_user_context_log($trigger, $schedule_id, $process, $notes_log_file, null);
                 return false;
             }
         }
         $storage_object->add_object('last_set_context_trigger', $trigger);
         $storage_object->add_object('last_set_context_schedule', $schedule_id);
         $storage_object->add_object('last_set_context_process', $process);
         $storage_object->save_to_file($storage_path);
         phoromatic::update_system_status('Setting context for: ' . $schedule_id . ' - ' . $trigger . ' - ' . $process);
         // Run the set context script
         $env_vars['PHOROMATIC_TRIGGER'] = $trigger;
         $env_vars['PHOROMATIC_SCHEDULE_ID'] = $schedule_id;
         $env_vars['PHOROMATIC_SCHEDULE_PROCESS'] = $process;
         $env_vars['PHOROMATIC_LOG_FILE'] = $notes_log_file;
         $log_output = pts_client::shell_exec('./' . $context_script . ' ' . $trigger . ' 2>&1', $env_vars);
         self::check_user_context_log($trigger, $schedule_id, $process, $notes_log_file, $log_output);
         // Just simply return true for now, perhaps check exit code status and do something
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 protected static function process_user_config_external_hook_process($process)
 {
     // Check to not run the same process
     $last_call_file = pts_module::save_dir() . self::$context . '.last-call';
     if (is_file($last_call_file)) {
         $check = pts_file_io::file_get_contents($last_call_file);
         if ($process == $check) {
             unlink($last_call_file);
             return false;
         }
     }
     $process != 'post_run' && file_put_contents($last_call_file, $process);
     if (self::$ini['set_context'][$process]) {
         $command = self::find_file(self::$ini['set_context'][$process]) ? self::find_file(self::$ini['set_context'][$process]) : self::$ini['set_context'][$process];
         $descriptor_spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
         $env_vars = null;
         pts_client::$display->test_run_instance_error('Running ' . $process . ' set-context script.');
         if (is_executable($command)) {
             // Pass the context as the first argument to the string
             $command .= ' ' . self::$context;
         } else {
             // Else find $MATISK_CONTEXT in the command string
             $command = str_replace('$MATISK_CONTEXT', self::$context, $command);
         }
         $proc = proc_open($command, $descriptor_spec, $pipes, null, $env_vars);
         echo $std_output = stream_get_contents($pipes[1]);
         $return_value = proc_close($proc);
         if (pts_strings::string_bool(self::$ini['set_context']['log_context_outputs'])) {
             file_put_contents(pts_module::save_dir() . $ini['workload']['save_name'] . '/' . self::$context . '-' . $process . '.txt', $std_output);
         }
         switch ($return_value) {
             case 8:
                 exit(0);
             case 9:
                 self::$skip_test_set = true;
                 break;
         }
     }
 }
Exemplo n.º 4
0
 private static function set_user_context($context_script, $trigger, $schedule_id, $process)
 {
     if (!empty($context_script)) {
         if (!is_executable($context_script)) {
             if (($context_script = pts_client::executable_in_path($context_script)) == false || !is_executable($context_script)) {
                 return false;
             }
         }
         $storage_path = pts_module::save_dir() . 'memory.pt2so';
         $storage_object = pts_storage_object::recover_from_file($storage_path);
         // We check to see if the context was already set but the system rebooted or something in that script
         if ($storage_object == false) {
             $storage_object = new pts_storage_object(true, true);
         } else {
             if ($storage_object->read_object('last_set_context_trigger') == $trigger && $storage_object->read_object('last_set_context_schedule') == $schedule_id && $storage_object->read_object('last_set_context_process') == $process) {
                 // If the script already ran once for this trigger, don't run it again
                 return false;
             }
         }
         $storage_object->add_object('last_set_context_trigger', $trigger);
         $storage_object->add_object('last_set_context_schedule', $schedule_id);
         $storage_object->add_object('last_set_context_process', $process);
         $storage_object->save_to_file($storage_path);
         // Run the set context script
         exec($context_script . ' ' . $trigger);
         // Just simply return true for now, perhaps check exit code status and do something
         return true;
     }
     return false;
 }