-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.inc
More file actions
71 lines (61 loc) · 1.75 KB
/
tools.inc
File metadata and controls
71 lines (61 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Helpful Exec
*/
function shop_exec($command, $interactive = FALSE){
$lines = array();
drush_log("[DEVUDO] Running: $command", "ok");
if ($interactive){
drush_shell_exec_interactive($command);
} else {
exec($command, $lines);
foreach ($lines as $line){
drush_log("[EXEC] $line", 'ok');
}
}
}
/**
* Helpful Exec
*/
function shop_exec_return($command, $output = 'array'){
$lines = array();
drush_log("[DEVUDO] Running: $command", "ok");
exec($command, $lines);
return $output == 'string'? implode("\n", $lines): $lines;
}
/**
* Helpful Exec to JSon
*/
function shop_exec_json($command, $return_string = FALSE, $label = "EXEC"){
drush_log("[$label] Running: $command");
drush_shell_exec($command);
$lines = drush_shell_exec_output();
$data_string = implode($lines);
$data_json = json_decode($data_string);
// Force return string if json did not decode
if (!is_array($data_json) && !is_object($data_json)){
return $data_string;
} else {
// If asked to return a string, return a string.
return $return_string? $data_string: $data_json;
}
}
/**
* Helper to load a server node from chef server by name
*/
function shop_get_server($node_name, $options = ' -l'){
$return = shop_exec_json("knife node show $node_name -Fj $options", FALSE, 'KNIFE');
// Handle
if (is_string($return)) {
// If a knife node was explicitly not found, knife successfully connected.
if (strpos($return, 'ERROR: The object you are looking for could not be found') === 0){
return 'not found';
}
// Otherwise, it failed to connect for some reason.
else {
return drush_set_error(DRUSH_DEVUDO_ERROR, '[DEVUDO] knife failed: ' . $return);
}
} else {
return $return;
}
}