forked from sdboyer/drupalorg-git
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshared.php
More file actions
80 lines (69 loc) · 1.93 KB
/
Copy pathshared.php
File metadata and controls
80 lines (69 loc) · 1.93 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
72
73
74
75
76
77
78
79
80
<?php
if (!defined('LOGLEVEL')) {
// Let an environment variable set the log level
$level = getenv('LOGLEVEL');
if (is_string($level)) {
define('LOGLEVEL', (int) $level);
}
else {
// Or default to 'normal'
define('LOGLEVEL', 3);
}
}
function git_invoke($command, $fail_safe = FALSE, $repository_path = NULL, $env = NULL) {
if (!isset($env)) {
$env = $_ENV;
}
if ($repository_path) {
$env['GIT_DIR'] = $repository_path;
}
$descriptor_spec = array(
1 => array('pipe', 'w'),
2 => array('pipe', 'w'),
);
git_log('Invoking ' . $command, 'DEBUG');
$process = proc_open($command, $descriptor_spec, $pipes, NULL, $env);
if (is_resource($process)) {
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[2]);
$return_code = proc_close($process);
if ($return_code != 0 && !$fail_safe) {
throw new Exception("Invocation of '" . $command . "' failed with return code " . $return_code .": \n" . $stdout . $stderr);
}
return $stdout;
}
}
function is_empty_dir($dir){
return (($files = @scandir($dir)) && count($files) <= 2);
}
/**
* Recursively delete a directory on a local filesystem.
*
* @param string $path
* The path to the directory.
*/
function rmdirr($path) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST) as $item) {
$item->isFile() ? unlink($item) : rmdir($item);
}
rmdir($path);
}
function git_log($message, $level = 'NORMAL', $project = NULL) {
$loglevels = array(
'WARN' => 1,
'QUIET' => 2,
'NORMAL' => 3,
'INFO' => 4,
'DEBUG' => 5,
);
if (LOGLEVEL !== 0 && LOGLEVEL >= $loglevels[$level]) {
if (isset($project)) {
echo "[" . date('Y-m-d H:i:s') . "] [$level] [$project] $message\n";
}
else {
echo "[" . date('Y-m-d H:i:s') . "] [$level] $message\n";
}
}
}