root/freepbx/branches/experimental/publish.php

Revision 2739, 2.9 kB (checked in by qldrob, 2 years ago)

Mime-type so I can look at this in trac 8)

  • Property svn:mime-type set to text/html
  • Property svn:executable set to *
Line 
1 #!/usr/bin/php
2 <?php
3
4 $rver = "2.2";
5 $reldir = "release/";
6 $schema = "module.xsd";
7
8 $out = NULL;
9 $ret = NULL;
10
11 $xmlschema = @file_get_contents($schema);
12 if (!$xmlschema)
13         die ("Cannot open XML Schema file: $schema\n");
14
15
16 libxml_use_internal_errors(True);
17
18 for ($i = $_SERVER['argc']; $i > 1; $i--) {
19         $module = $_SERVER['argv'][$i - 1];
20         printf ("Processing module $module...\n");
21
22         $modulexml = @file_get_contents($module.'/module.xml');
23
24         if (!$modulexml) {
25                 print("\tCannot open: $module/module.xml\n");
26                 print("\tSkipping module: $module \n\n");
27                 continue;
28         }
29
30         $dom = new DomDocument();
31         $dom->strictErrorChecking = TRUE;
32         $dom->formatOutput = TRUE;
33
34         // Well-formedness
35         if (!$dom->loadXML($modulexml)) {
36                 print("\tXML not well-formed: $module/module.xml\n");
37                 $errors = libxml_get_errors();
38                 foreach ($errors as $error) {
39                         print display_xml_error($error);
40                 }
41                 libxml_clear_errors();
42                 unset($dom);
43                 print("\tSkipping module: $module \n\n");
44                 continue;
45         }
46
47         print("\tXML is well formed\n");       
48
49         // Validation
50         if (!$dom->schemaValidateSource($xmlschema)) {
51                 print("\tXML not validated: $module/module.xml\n");
52                 $errors = libxml_get_errors();
53                 foreach ($errors as $error) {
54                         print display_xml_error($error);
55                 }
56                 libxml_clear_errors();
57                 unset($dom);
58                 print("\tSkipping module: $module \n\n");
59                 continue;
60         }
61
62         print("\tXML is valid\n");     
63
64         $version = $dom->documentElement->getAttribute('version');
65         $rawname = $dom->documentElement->getAttribute('rawname');
66
67         if ($rawname != $module) {
68                 printf("\tModule name doesn't match directory name\n");
69                 printf("\tSkipping module\n");
70                 continue;
71         }
72                 
73         printf("\tPublishing module %s version %s\n", $rawname, $version);     
74
75         #exec("svn ci -m \"Auto Check-in of any outstanding patches\" $moddir", $out, $ret);
76         $filename = "$rawname-$version.tgz";
77         exec("tar zcf $filename --exclude .svn $rawname", $out, $ret);
78
79         $tgz = file_get_contents($filename);
80         $md5 = md5($tgz);
81
82         $dom->documentElement->setAttribute('md5sum', $md5);
83         $dom->documentElement->setAttribute('location', 'X');
84         $dom->save($module.'/module.xml');
85         
86         exec("mv $filename ../../release/$rver", $out, $ret);
87         exec("svn add ../../release/$rver/$filename", $out, $ret);
88         exec("svn ps svn:mime-type application/tgz ../../release/$rver/$filename", $out, $ret);
89         exec("svn ci ../../release/$rver/$filename $rawname/module.xml -m \"Module Publish Script: $rawname $version\"", $out, $ret);
90                         
91         print ("\tDone\n\n");
92         
93 }
94
95 function display_xml_error($error)      {
96   
97    switch ($error->level) {
98        case LIBXML_ERR_WARNING:
99            $return .= "\t\tWarning $error->code: ";
100            break;
101          case LIBXML_ERR_ERROR:
102            $return .= "\t\tError $error->code: ";
103            break;
104        case LIBXML_ERR_FATAL:
105            $return .= "\t\tFatal Error $error->code: ";
106            break;
107    }
108
109    $return .= trim($error->message) .
110                "at line $error->line\n";
111
112
113    return "$return";
114 }
115
116
117 ?>
Note: See TracBrowser for help on using the browser.