Permalink
Browse files

updated sauce connect to use proc_open and streams

  • Loading branch information...
1 parent 8a83f12 commit d87e58e0ae47ff837c4d14b2471d67321f7e2738 @jlipps committed Sep 18, 2012
Showing with 52 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +2 −1 bin/sauce_config
  3. +41 −0 bin/sauce_connect
  4. +8 −0 src/Sauce/Sausage/SauceConfig.php
View
@@ -1,3 +1,4 @@
composer.phar
vendor/
composer.lock
+.sauce_config
View
@@ -1,8 +1,9 @@
#!/usr/bin/env php
<?php
+require_once dirname(__FILE__).'/../src/Sauce/Sausage/SauceConfig.php';
+
use Sauce\Sausage\SauceConfig;
-echo dirname(__FILE__);
$USAGE = "USAGE: sauce_config USERNAME API_KEY";
View
@@ -1,3 +1,44 @@
#!/usr/bin/env php
<?php
+require_once dirname(__FILE__).'/../src/Sauce/Sausage/SauceConfig.php';
+
+use Sauce\Sausage\SauceConfig;
+
+$CONNECT_BINARY = dirname(__FILE__).'/../lib/Sauce-Connect.jar';
+
+list($username, $api_key) = SauceConfig::GetConfig();
+
+if (!$username || !$api_key) {
+ echo "You need to run sauce_config to set your username and api key!\n";
+ exit(1);
+}
+
+if (count($argv) > 1) {
+ $args = " ".join(' ', array_slice($argv, 1));
+} else {
+ $args = "";
+}
+
+$cmd = "java -jar $CONNECT_BINARY $username $api_key$args";
+
+stream_set_blocking($pipes[1], 0);
+stream_set_blocking($pipes[2], 0);
+$status = proc_get_status($process);
+
+while ($status['running']) {
+ $out_streams = array($pipes[1], $pipes[2]);
+ $e = NULL; $f = NULL;
+ $num_changed = stream_select($out_streams, $e, $f, 0, 20000);
+ if ($num_changed) {
+ foreach ($out_streams as $changed_stream) {
+ echo stream_get_contents($changed_stream);
+ }
+ }
+ $status = proc_get_status($process);
+}
+
+fclose($pipes[0]);
+fclose($pipes[1]);
+fclose($pipes[2]);
+proc_close($proc);
@@ -24,6 +24,14 @@ public static function LoadConfig()
}
}
+ public static function GetConfig()
+ {
+ self::LoadConfig();
+ $username = defined('SAUCE_USERNAME') ? SAUCE_USERNAME : '';
+ $api_key = defined('SAUCE_API_KEY') ? SAUCE_API_KEY : '';
+ return array($username, $api_key);
+ }
+
public static function WriteConfig($username, $api_key) {
file_put_contents(CONFIG_PATH, "{$username},{$api_key}");
}

0 comments on commit d87e58e

Please sign in to comment.