Ticket #13673: maintainers.php

File maintainers.php, 1.9 KB (added by ryandesign (Ryan Carsten Schmidt), 16 years ago)

print list of all port maintainers

Line 
1#!/usr/bin/php
2<?php
3
4define('PORT', '/opt/local/bin/port');
5if (!is_executable(PORT)) {
6        fwrite(STDERR, sprintf('Can\'t execute %s', PORT) . "\n");
7        exit(1);
8}
9define('PORTINDEX', dirname(dirname(exec(PORT . ' dir MacPorts'))) . '/PortIndex');
10
11$exclude_maintainers = array(
12        'openmaintainer@macports.org',
13        'nomaintainer@macports.org',
14);
15
16$fh = fopen(PORTINDEX, 'rb');
17$i = 0;
18$maintainers = array();
19while (!feof($fh)) {
20        ++$i;
21        $line = fgets($fh);
22        if ($i % 2) continue;
23        while (!empty($line)) {
24                $key = take_token($line);
25                $value = take_token($line);
26                if ('maintainers' == $key) {
27                        if (preg_match('%^\{(.*)\}$%', $value, $matches)) {
28                                $new_maintainers = explode(' ', $matches[1]);
29                        } else {
30                                $new_maintainers = array($value);
31                        }
32                        foreach ($new_maintainers as $new_maintainer) {
33                                $maintainers[fix_maintainer($new_maintainer)] = true;
34                        }
35                }
36        }
37}
38fclose($fh);
39
40foreach ($exclude_maintainers as $exclude_maintainer) {
41        unset($maintainers[$exclude_maintainer]);
42}
43
44$maintainers = array_keys($maintainers);
45sort($maintainers);
46echo implode("\n", $maintainers) . "\n";
47
48exit;
49
50function take_token(&$line) {
51        if (preg_match('%^(?:\{.*?\}|\S+)\s%', $line, $matches)) {
52                $line = substr($line, strlen($matches[0]));
53                $token = $matches[0];
54                while (substr_count($token, '{') > substr_count($token, '}')) {
55                        if (preg_match('%^.*?\}\s%', $line, $matches)) {
56                                $line = substr($line, strlen($matches[0]));
57                                $token .= $matches[0];
58                        } else {
59                                fwrite(STDERR, 'Couldn\'t finish reading a token!' . "\n");
60                                exit(1);
61                        }
62                }
63                return rtrim($token);
64        } else {
65                fwrite(STDERR, 'Couldn\'t find a token!' . "\n");
66                exit(1);
67        }
68}
69
70function fix_maintainer($maintainer) {
71        if (preg_match('%^([^:]+):([^:]+)$%', $maintainer, $matches)) {
72                return $matches[2] . '@' . $matches[1];
73        }
74        if (false === strpos($maintainer, '@')) {
75                return $maintainer . '@macports.org';
76        }
77        return $maintainer;
78}
79
80?>