Re: package.xml release generation

From: Date: Mon, 02 Dec 2002 03:48:18 +0000
Subject: Re: package.xml release generation
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-11286@lists.php.net to get a copy of this message
"Pierre-Alain Joye" <paj@pearfr.org> wrote in message news:20021202004035.6a31f279.paj@pearfr.org... > Hello, > > it seems there is a problem with the mime attachment, can you attach the > script as a txt or provides an url ? > > tia > > pierre Apologies for the confusion, here is the txt of the script: create_package.xml.php:344 lines/8311 chars approx. ------------cut---------------- <?php /** * PEAR Package.xml file generator * * @note This uses phpDocumentor 1.2.0 docblock templates, and will not parse * properly with phpDocumentor 1.1.0 * @package PEAR * @author Greg Beaver <cellog@users.sourceforge.net> * @copyright Copyright 2002, Greg Beaver * @version 0.1 */ /**#@+ * phpDocumentor include files. If you don't have phpDocumentor, go get it! * Your php life will be changed forever */ include_once("common.inc.php"); include_once("Io.inc"); /**#@-*/ /** * @global string $version */ $version = "1.2.0"; /** * @global string $state */ $state = "stable"; /** * @global string $date */ $date = date('m-d-Y'); /** * @global string $notes */ $notes = <<< EOF These are the release notes for phpDocumentor 1.2.0 EOF; /** * Physical location on this computer of the package to parse * @global string $package_directory */ $package_directory = 'C:/Web Pages/chiara/phpdoc-1.1.0'; /** * PEAR-relative install dir, used as attribute for <dir name="/"> * @global string $baseinstalldir */ $baseinstalldir = 'phpDocumentor'; /** * Comma-separated list of files and directories to ignore * * This uses wildcards * and ? to remove extra files/directories that are * not part of the package or release * @global string $ignore */ $ignore = array('CVS/','package.xml','*.tgz'); /** * Mapping of file extensions to the role attribute of the <file> tag * * '*' is the default role for files with no extension or extensions not shown * @global array $roles */ $roles = array ( 'php' => 'php', 'inc' => 'php', 'html' => 'doc', '*' => 'data', ); /** * Mapping of subdirectory names to the role attribute of the <dir> tag * @global array $dir_roles */ $dir_roles = array ( 'spec' => 'doc', 'tests' => 'test', 'Release-old' => 'doc', 'user' => 'data', 'templates' => 'data', ); /** * Mapping of filenames to roles for files that don't fit the normal * {@link $roles} * @global array $exceptions */ $exceptions = array ( 'README' => 'doc', 'ChangeLog' => 'doc', 'makedoc.sh' => 'script', 'phpdoc' => 'script', 'Release-1.2.0' => 'doc', 'Release-1.1.0' => 'doc', 'Release-1.1.0rc1' => 'doc', 'Release-1.1.0rc2' => 'doc', ); /*************************************************************************** *** * Don't change anything below here unless you're adventuresome * **************************************************************************** ***/ /** * Determines whether output is made html-friendly or not * @global boolean $webinterface */ $webinterface = isset($_SERVER['PATH_TRANSLATED']); /** * @global Io $files */ $files = new Io; $allfiles = $files->dirList($package_directory); /**#@+ * Sorting functions for the file list * @param string * @param string */ function sort_directory($a, $b) { global $package_directory; if (dirname($a) == dirname($b)) return strnatcasecmp($a, $b); if (strpos(dirname($a),dirname($b)) === 0) return -1; if (strpos(dirname($b),dirname($a)) === 0) return 1; return strnatcasecmp($a, $b); } function sortfiles($a, $b) { return strnatcasecmp($a['file'],$b['file']); } function mystrucsort($a, $b) { if (is_numeric($a) && is_string($b)) return 1; if (is_numeric($b) && is_string($a)) return -1; if (is_numeric($a) && is_numeric($b)) { if ($a > $b) return 1; if ($a < $b) return -1; if ($a == $b) return 0; } return strnatcasecmp($a,$b); } /**#@-*/ $struc = array(); foreach($allfiles as $file) { if ($files->checkIgnore(basename($file),dirname($file),$ignore)) continue; $path = substr(dirname($file),strlen(str_replace('\\','/',realpath($package_director y)))+1); if (!$path) $path = '/'; $file = basename($file); $ext = array_pop(explode('.',$file)); if (strlen($ext) == strlen($file)) $ext = ''; $struc[$path][] = array('file' => $file,'ext' => $ext); } uksort($struc,'strnatcasecmp'); foreach($struc as $key => $ind) { usort($ind,'sortfiles'); $struc[$key] = $ind; $save = $key; if ($key != '/') { $key = explode('/',$key); while (count($key)) { array_pop($key); if (isset($struc[join('/',$key)])) { $struc[join('/',$key)][substr($save,strlen(join('/',$key)) + 1)] = $ind; unset($struc[$save]); } } } } foreach($struc as $key => $ind) { if ($key != '/') { if (count(explode('/',$key)) == 1) { $struc['/'][$key] = $struc[$key]; unset($struc[$key]); } } } $tempstruc = $struc; unset($tempstruc['/']); $leftover_dirs = array_keys($tempstruc); foreach($leftover_dirs as $dir) { $splitdirs[] = explode('/',$dir); } $leftover_dirs = array(); /** * Recursively add all the subdirectories of $contents to $dir without erasing anything in * $dir * @param array * @param array * @return array processed $dir */ function set_dir($dir,$contents) { while(list($one,$two) = each($contents)) { if (isset($dir[$one])) { $dir[$one] = set_dir($dir[$one],$contents[$one]); } else $dir[$one] = $two; } return $dir; } /** * Recursively move contents of $struc into associative array * * The contents of $struc have many indexes like 'dir/subdir/subdir2'. * This function converts them to * array('dir' => array('subdir' => array('subdir2'))) * @param array * @param array * @return array */ function setup_dirs($struc,$dir,$contents) { if (!count($dir)) { foreach($contents as $dir => $files) { if (is_string($dir)) { if (strpos($dir,'/')) { $test = true; $a = $contents[$dir]; unset($contents[$dir]); $b = explode('/',$dir); $c = array_shift($b); if (isset($contents[$c])) { $contents[$c] = set_dir($contents[$c],setup_dirs(array(),$b,$a)); } else $contents[$c] = setup_dirs(array(),$b,$a); } } } return $contents; } $me = array_shift($dir); if (!isset($struc[$me])) $struc[$me] = array(); $struc[$me] = setup_dirs($struc[$me],$dir,$contents); return $struc; } foreach($splitdirs as $dir) { $save = join($dir,'/'); $struc['/'] = setup_dirs($struc['/'], $dir, $tempstruc[$save]); unset($struc[$save]); } uksort($struc['/'],'mystrucsort'); /** * Recursively generate the <filelist> section's <dir> and <file> tags * @param array the sorted directory structure * @param false|string whether the parent directory has a role this should * inherit * @param integer indentation level * @global array * @global array * @global array * @global string */ function getDirTag($struc, $role=false, $level = 0) { global $dir_roles, $exceptions, $roles, $baseinstalldir; $res = $spaces = ''; for($i= -4; $i < $level; $i++) { $spaces .= ' '; } foreach($struc as $dir => $files) { if ($dir === '/') { $my = ' <dir name="/" baseinstalldir="'.$baseinstalldir.'">'."\n"; $my .= getDirTag($struc[$dir], $role, $level + 1); $my .= ' </dir>'; return $my; } else { if (!isset($files['file'])) { $myrole = ''; if ($role) $myrole = $role; elseif (isset($dir_roles[$dir])) $myrole = ' role="'.$dir_roles[$dir].'"'; $res .= $spaces.'<dir name="'.$dir.'"'.$myrole.">\n"; $res .= getDirTag($files,$myrole,$level + 1); $res .= $spaces.'</dir>'."\n"; } else { $myrole = ''; if (!$role) { $myrole = false; if (isset($exceptions[$files['file']])) { $myrole = $exceptions[$files['file']]; } elseif (isset($roles[$files['ext']])) { $myrole = $roles[$files['ext']]; } else $myrole = $roles['*']; $myrole = ' role="'.$myrole.'"'; } $res .= $spaces.'<file'.$myrole.'>'.$files['file'].'</file>'."\n"; } } } return $res; } $notes = substr(" ".join(explode("\n",$notes),"\n "),0,strlen(join(explode("\n",$notes),"\n ")) - 3); $res = getDirTag($struc); $res = " <release> <version>$version</version> <state>$state</state> <date>$date</date> <notes> $notes </notes> <filelist> $res </filelist> </release> "; if ($webinterface) print nl2br(str_replace(' ','&nbsp;',htmlentities($res))); else print $res; ?>

« previous php.pear.dev (#11286) next »