forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree_threader_splitter
executable file
·82 lines (70 loc) · 1.86 KB
/
tree_threader_splitter
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
81
#! /usr/bin/env php
<?php
// ./bin/tree_threader_splitter input_dir
//
// input_dir: a directory with a number of template files
//
// Split these into N groups, make each group into a zip file
// named "tree_threader_template_T_i"
// where T is the current time and i is the index.
// Put these in the download hierarchy,
// and write a file "tree_threader_template_files"
// containing the file names
$files_per_group = 10;
require_once("html/inc/dir_hier.inc");
if ($argc != 2) die("usage: tree_threader_splitter dir\n");
if (!is_dir($argv[1])) die("usage: tree_threader_splitter dir\n");
$now = time();
$flist = fopen("tree_threader_template_files", "w");
function start_group($i) {
global $now;
mkdir("/tmp/tree_threader_template_".$now."_$i");
}
function add_file_to_group($i, $path) {
global $now;
$dir = "/tmp/tree_threader_template_".$now."_$i";
$cmd = "cp $path $dir";
system($cmd);
}
$config = simplexml_load_string(file_get_contents("config.xml"));
if (!$config) die("can't parse config.xml");
$fanout = (int)$config->config->uldl_dir_fanout;
function finish_group($i) {
global $now, $fanout, $flist;
$dir = "tree_threader_template_".$now."_$i";
$dirpath = "/tmp/$dir";
$cmd = "zip -r $dirpath $dirpath";
system($cmd);
$f = "$dir.zip";
$path = dir_hier_path($f, "download", $fanout);
if (rename("/tmp/$f", $path)) {
echo "renamed /tmp/$f to $path\n";
} else {
die("can't rename /tmp/$f to $path\n");
}
fprintf($flist, "$f\n");
}
$dir = $argv[1];
$d = opendir($dir);
$igp = 0;
$gpsize = 0;
while (($f = readdir($d)) !== false) {
$p = "$dir/$f";
echo "processing $p\n";
if (!is_file($p)) continue;
if ($gpsize == 0) {
start_group($igp);
}
add_file_to_group($igp, $p);
$gpsize++;
if ($gpsize == $files_per_group) {
finish_group($igp);
$gpsize = 0;
$igp++;
}
}
if ($gpsize) {
finish_group($igp);
}
fclose($flist);
?>