PHP utility collection with hybrid and fluent APIs.

⌈⌋ branch:  hybrid7 libraries


Check-in [a5113eb7a6]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Converts php plugins into .deb or .rpm packages (using epm currently)
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a5113eb7a6892027cb30523aa826c18ce0ff93cd
User & Date: mario 2014-03-09 02:15:22
Context
2014-03-09
02:15
Trivial AR table handler building. check-in: dcaf21a373 user: mario tags: trunk
02:15
Converts php plugins into .deb or .rpm packages (using epm currently) check-in: a5113eb7a6 user: mario tags: trunk
02:12
Templating interface concept. check-in: 31f60c3bdd user: mario tags: trunk
Changes

Added tools/php2deb.









































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/php -Cq
<?php
/**
 * api: cli
 * type: application
 * title: plugin to package converter
 * description: converts a .php plugin into an installable .deb package
 * version: 0.2-STILL-VERY-LO-FI
 *
 * Converts a script or collection following the PHP plugin standard into a
 * distribution package. Uses EPM to generate DEB and RPM packages alike.
 * Generated files will be extracted to /usr/share/php unless overriden by
 * a deb-dir: PMD line.
 *
 * All files to be packaged must be given as parameters. It's recommended
 * to have multiple files located in a subdirectory. Example:
 *
 *   php2pkg module.php module/*.php
 *
 * The package name will be deduced from the first listed .php plugin.
 * And it should strictly be run in the current directory, it doesn't
 * care about clean filename treatment at the moment.
 *
 */

#-- libs 
include("/home/mario/www/sf.net/genericphpconfig/lib/pluginmetadata.php");
error_reporting(E_ALL&~E_NOTICE);

#-- config
  // plugin package name prefix
$prefix = "php-plugin-";
  // installation directory
$target = "/usr/share/php";
  // dependency names that should be filtered out to not confuse apt/dpkg, especially php module names
$filter_deps = array("pdo", "json", "bcmath", "bz2", "calendar", "Core", "ctype", "date", "dba", "dom", "ereg", "exif", "fileinfo", "filter", "ftp", "gd", "gettext", "hash", "iconv", "json", "libxml", "mbstring", "mhash", "mysql", "mysqli", "openssl", "pcntl", "pcre", "PDO", "pdo_mysql", "pdo_sqlite", "Phar", "posix", "readline", "Reflection", "session", "shmop", "SimpleXML", "soap", "sockets", "SPL", "SQLite", "sqlite3", "standard", "sysvmsg", "sysvsem", "sysvshm", "tokenizer", "wddx", "xml", "xmlreader", "xmlwriter", "zip", "zlib");


#-- search files 
if ("search") {
    $files = array();
    $pmd = new generic_pmd();
    array_shift($_SERVER["argv"]);
    foreach ($_SERVER["argv"] as $fn) {
        $row = $pmd->read($fn);
        $row["fn"] = $fn;
        $row["id"] = $pmd->basename($fn);
        $files[] = $row;
    }
    $pmd->scan(".");
}

#-- prepare package data
if ("meta") {
    $first = $files[0];
    $package = $first["id"];
    $target = $first["deb-dir"] ?: $target;
}

#-- write EPM file
if ("epm") {
    $tmp = tempnam("/tmp/", "php2pkg");
    file_put_contents(".LICENSE", $first["license"]);   // another unused stub
    file_put_contents(".NONE", "");     // EPM needs stubs
    $f = fopen($tmp, "w");
    fwrite($f, "
# %name {$prefix}{$package}
%product $first[title]
%version $first[version]
%vendor $first[author]
%license .LICENSE
%copyright copy: $first[copyright] / license: $first[license]
%readme .NONE

%description $first[description]
%description
#-- help text
    ");
    foreach (explode("\n", $first["help"]) as $line) {
        fwrite($f, "%description $line\n");
    }
    fwrite($f, "
    #-- files
    ");

    #-- add files
    foreach ($files as $row) {
        fwrite($f, "f 644 root root $target/$row[fn]  $row[fn]\n");
        #-- and dependencies
        if ($deps = $pmd->depends[$row["id"]]) {
            foreach ($deps as $dep) {
                if (!in_array($dep, $filter_deps) && !strpos($dep, ":")) {
                    fwrite($f, "%requires {$prefix}{$dep}\n");
                }
            }
       }
    }
}


#-- execute EPM
if ("run") {
    if (`which dpkg`)
    system("epm -a all -f deb {$prefix}{$package} {$tmp} --output-dir . -n");
    if (`which rpm`)
    system("epm -a all -f rpm {$prefix}{$package} {$tmp} --output-dir . -n");
}
exit;
#-- clean up
if ("done") {
    unlink($tmp);
    unlink(".LICENSE");
    unlink(".NONE");
}

?>