root/modules/branches/2.10/package.php

Revision 12737, 5.0 kB (checked in by mbrevda, 2 years ago)

re #5394 - new module package script, aptly called package.php!

  • Property svn:executable set to *
Line 
1 #!/usr/bin/php -q
2 <?php
3
4
5 //get cli opts
6 $longopts = array(
7     "modules:",
8     "debug::",
9     "checkphp::",
10     'verbose::'
11 );
12 $vars = getopt('m:d::L::v::');
13
14 //move cli args to longopts for clarity throught the script
15 if (isset($vars['m'])) {
16     $vars['modules'] = (array) $vars['m'];
17     unset($vars['m']);
18 } else {
19     $vars['modules'] = false;
20 }
21
22 if (isset($vars['d'])) {
23     $vars['debug'] = true;
24     unset($vars['d']);
25 } else {
26     $vars['debug'] = false;
27 }
28
29 if (isset($vars['L'])) {
30     $vars['checkphp'] = false;
31     unset($vars['L']);
32 } else {
33     $vars['checkphp'] = true;
34 }
35
36 if (isset($vars['v'])) {
37     $vars['verbose'] =  true;
38     unset($vars['L']);
39 } else {
40     $vars['verbose'] = false;
41 }
42
43 //find location of md5 command
44 if (!$vars['md5'] = run_cmd('which md5sum')) {
45     if (!run_cmd('which md5')) {
46         die("no md5sum command\n");
47     } else {
48         $vars['md5'] = 'md5 -r';
49     }
50 }
51
52 //set up some other settings
53 $vars['rver']             = '2.10';
54 $vars['fwbranch']         = 'branches/2.10';
55 $vars['framework']        = 'framework';
56 $vars['fw_ari']            = 'fw_ari';
57 $vars['fw_langpacks']    = 'fw_langpacks';
58 $vars['reldir']            = 'reldir';
59
60 //ensure we have modules to package
61 if (!$vars['modules']) {
62     die('No modules specified. Please specify them one with the -m option (use multiple switches for more than one module)');
63 }
64 //print_r($vars);
65 //ensure the directory is up to date
66 run_cmd('svn up');
67
68 foreach ($vars['modules'] as $mod) {
69     $mod         = trim($mod, '/');
70     $files         =
71     $filename    =
72     $xml         =
73     $rawname    =
74     $ver         = '';
75     
76     echo 'Packaging ' . $mod . '...' . PHP_EOL;
77     $xml = file_get_contents($mod . '/module.xml');
78     
79     //check the xml script integrity
80     include_once('xml2Array.class.php');
81     $parser = new xml2ModuleArray($xml);
82     $xmlarray = $parser->parseAdvanced($xml);
83     //TODO: not sure how to detect a broken xml --MB
84     if (!true) {
85         echo $mod . '/module.xml seems corrupt, ' . $mod . ' won\'t be packaged' . PHP_EOL;
86         continue;
87     }
88     
89     //check that module name is set in module.xml
90     if (!preg_match('/<rawname>(.*?)<\/rawname>/', $xml, $rawname)) {
91         echo $mod . '/module.xml is missing a module name, ' . $mod . ' won\'t be packaged' . PHP_EOL;
92         continue;
93     } else {
94         $rawname = $rawname[1];
95     }
96     
97     //check that module version is set in module.xml
98     if (!preg_match('/<version>(.*?)<\/version>/', $xml, $version)) {
99         echo $mod . '/module.xml is missing a version number, ' . $mod . ' won\'t be packaged' . PHP_EOL;
100         continue;
101     } else {
102         $ver = $version[1];
103     }
104     
105     //check php files for syntaxt errors
106     if ($vars['checkphp']) {
107         $files = scandirr($mod, true);
108         foreach ($files as $f) {
109             if (pathinfo($f, PATHINFO_EXTENSION) == 'php') {
110                 if (!system('php -l ' . $f)) {
111                     echo('syntaxt error detected in ' . $f . ',' $mod . ' won\'t be packaged' . PHP_EOL);
112                     continue 2;
113                 }
114             }
115         }
116     }
117
118     //check in out standing files
119     if (run_cmd('svn st ' . $mod . '|wc -l') > 1) {
120         run_cmd('svn ci -m "Auto Check-in of any outstanding patches in ' . $mod . '" ' . $mod);
121     }
122     
123     
124     //set tarball name var
125     $filename = $rawname . '-' . $ver . '.tgz';
126     
127     //build tarball
128     run_cmd('tar zcf ' . $filename . ' ' . $mod . ' --exclude ".*" -C ' . $mod );
129     
130     //update md5 sum
131     //TODO!
132     
133     //move tarbal to relase dir
134     run_cmd('mv ' . $filename . ' ../../release/' . $vars['rver']);
135     
136     //add tarball to repository
137     run_cmd('svn add ../../release/' . $vars['rver'] . '/' . $filename);
138     
139     //set mietype of tarball
140     run_cmd('svn ps svn:mime-type application/tgz ../../release/' . $vars['rver'] . '/' . $filename);
141     
142     //set latpublished property
143     $lastpub = run_cmd('svn info ' . $mod . ' | grep Revision: | awk \'{print $2}\'');
144     run_cmd('svn ps lastpublish ' . $lastpub . ' ' . $mod);
145     
146     //check in new tarball and module.xml
147     run_cmd('svn ci ../../release/' . $vars['rver'] . '/' . $filename . ' ' . $mod . '/module.xml'
148                     . ' -m"Module package script: ' . $rawname . ' ' . $ver . '"');
149     
150 }
151
152 /**
153  * function scandirr
154  * scans a directory just like scandir(), only recursively
155  * returns a hierarchical array representing the directory structure
156  *
157  * @pram string - directory to scan
158  * @pram strin - retirn absolute paths
159  * @returns array
160  *
161  * @author Moshe Brevda mbrevda => gmail ~ com
162  */
163 function scandirr($dir, $absolute = false) {
164     $list = array();
165     if ($absolute) {
166         global $list;
167     }
168     
169     
170     //get directory contents
171     foreach (scandir($dir) as $d) {
172         
173         //ignore any of the files in the array
174         if (in_array($d, array('.', '..'))) {
175             continue;
176         }
177         
178         //if current file ($d) is a directory, call scandirr
179         if (is_dir($dir . '/' . $d)) {
180             if ($absolute) {
181                 scandirr($dir . '/' . $d, $absolute);
182             } else {
183                 $list[$d] = scandirr($dir . '/' . $d, $absolute);
184             }
185             
186         
187             //otherwise, add the file to the list
188         } elseif (is_file($dir . '/' . $d) || is_link($dir . '/' . $d)) {
189             if ($absolute) {
190                 $list[] = $dir . '/' . $d;
191             } else {
192                 $list[] = $d;
193             }
194             
195         }
196     }
197
198     return $list;
199 }
200
201 function run_cmd($cmd, $quite = false) {
202     global $vars;
203     $quite = $quite ? ' > /dev/null' : '';
204
205     if ($vars['debug']) {
206         echo $cmd . PHP_EOL;
207         return true;
208     } elseif($vars['verbose']) {
209         echo '+ ' . $cmd . PHP_EOL;
210         return system($cmd . $quite);
211     } else {
212         return system($cmd . $quite);
213     }
214 }
215 ?>
Note: See TracBrowser for help on using the browser.