-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbuild_all_py.php
executable file
·49 lines (43 loc) · 1.06 KB
/
build_all_py.php
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
#!/usr/bin/env php
<?php
$path = @$argv[1] ?: '.';
//$files = explode( "\n", `locate .py` );
$files = explode( "\n", `find $path -name *.py` );
/*
$outdir = '/tmp/py2php.out';
if(!is_dir($outdir)) {
mkdir($outdir);
}
*/
$failed_cnt = 0;
$success_cnt = 0;
foreach( $files as $f ) {
if( !$f || !file_exists( $f )) {
continue;
}
if( pathinfo($f, PATHINFO_EXTENSION) != 'py' ) {
continue;
}
$dir = @$outdir ? $outdir : dirname($f);
$dest = basename($f, '.py');
$outfile = "$dir/$dest.php";
$errfile = "$dir/$dest.stderr";
if( file_exists( $outfile ) && filesize($outfile) > 10 ) {
continue;
}
$cmd = './py2php ' . $f . " > $outfile 2> $errfile";
echo "processing " . basename($f) . "\n";
// echo $cmd . "\n";
exec($cmd, $output, $rc);
if( $rc != 0 ) {
$failed_cnt ++;
echo "Failed: $f\n";
readfile( $errfile );
exit(1);
}
else {
$success_cnt ++;
unlink("$dir/$dest.stderr");
}
}
echo "\nSucceeded: $success_cnt, Failed: $failed_cnt\n\n";