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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#!/usr/bin/php
<?php
define('MKVIEW_VERSION', '1.0.0-dev');
$title = "Repository";
$url = "http://localhost";
$level = 1;
$template = __DIR__;
// 0: debug, 1: message, 2: error, 3: die
function msg(int $l, string $m) {
global $level;
if ($l >= $level) {
if (!$l) {
echo "+ ";
}
echo "$m\n";
}
if ($l >= 3) {
exit(1);
}
}
function usage() {
printf("\nMkView version %s - (c) Remi Collet\n", MKVIEW_VERSION);
printf("\nusage: %s [ options ]\n\n", $_SERVER['argv'][0]);
printf("\t--template directory\n");
printf("\t--url repository public URL\n");
printf("\t--quiet less message\n");
printf("\t--verbose more message\n");
printf("\t--title repository title\n\n");
}
function parse_repomd() {
if (!is_dir("repodata")) {
msg(3, "repodata directory missing");
}
if (!is_file("repodata/repomd.xml")) {
msg(3, "repomd.xml is missing");
}
$md = simplexml_load_file("repodata/repomd.xml");
if (!$md) {
msg(3, "Can't read repomd.xml or empty");
}
msg(0, "Read repomd.xml");
foreach($md->data as $n) {
$a = (string)$n->attributes()->type[0];
if ($a === 'primary') {
$path = (string)$n->location->attributes()->href[0];
}
}
if ($path) {
msg(0, "Primary stored in $path");
} else {
msg(3, "Primary not found");
}
return $path;
}
for($i=1 ; $i<$_SERVER['argc'] ; $i++) {
$arg = $_SERVER['argv'][$i];
switch ($arg) {
case '-h':
case '--help':
usage();
exit(0);
case '-t':
case '--title':
$title = $_SERVER['argv'][++$i];
break;
case '-T':
case '--template':
$template = realpath($_SERVER['argv'][++$i]);
break;
case '-u':
case '--url':
$url = $_SERVER['argv'][++$i];
break;
case '-v':
case '--verbose':
$level--;
break;
case '-q':
case '--quiet':
$level++;
break;
default:
if (!is_dir($arg)) {
msg(3, "Unkownn option $arg");
} else if (!chdir($arg)) {
msg(3, "Bad directory $arg");
exit(1);
}
}
}
msg(1, sprintf("MkView version %s - (c) Remi Collet", MKVIEW_VERSION));
msg(0, "Work in " . getcwd());
$prim = parse_repomd();
msg(0, "Done");
|