[zi-cvs] packages/com.zzoss.package.descriptor.lib Descriptor.php,NONE,1.1 package.xml,NONE,1.1
Sandro Zic <[email protected]> Sat, 24 Apr 2004 15:33:55 +0000
| Newsgroups | gmane.comp.php.zzoss.installer.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/zzossinstaller/packages/com.zzoss.package.descriptor.lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24808/com.zzoss.package.descriptor.lib
Added Files:
Descriptor.php package.xml
Log Message:
create package tgz with dir in filelist
--- NEW FILE: Descriptor.php ---
<?php
/*
Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@version $Id: Descriptor.php,v 1.1 2004/04/24 15:33:52 ordnas Exp $
@copyright Copyright © 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
@license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
*/
/**
* Read and transform package XML descriptor.
*/
class ZZOSS_PackageDescriptor
{
/**
* The package XML descriptor array.
*/
var $xml;
/**
* The processed filelist.
*/
var $filelist = array();
/**
* Track baseinstalldir attributes of dir elements of filelist.
*/
var $dirs = array();
/**
* Track name attributes of dir elements of filelist.
*/
var $dirnames = array();
var $filelist_level = -1;
function setArray($xml)
{
$this->xml = $xml;
}
function getFilelist($structure = 'flat')
{
$method = '_getFilelist'.ucfirst($structure);
if(!method_exists($this, $method)){
trigger_error("Parameter '$structure' not available");
}
// clean up previous filelist
$this->filelist = array();
$this->dirs = array();
/*
echo '<pre>';
print_r($this->xml['release']['filelist']);
echo '</pre>';
*/
$this->$method($this->xml['release']['filelist']);
return $this->filelist;
}
function _getFilelistFlat($filelist, $role = null)
{
if(!is_array($filelist) || !count($filelist)){
return false;
} else {
// path of previous dir
$path_prev = '';
if(isset($filelist['@']['baseinstalldir'])){
$baseinstalldir_prev = $filelist['@']['baseinstalldir'];
}
if(isset($filelist['@']['name']) && $filelist['@']['name'] != '/' && $filelist['@']['name'] != '\\'){
$name_prev = $filelist['@']['name'];
}
foreach($filelist as $type => $items){
switch($type){
case 'dir':
//echo "<h1>Type: $type</h1>";
$this->increaseFilelistLevel();
foreach($items as $dir){
/*
echo "<h2>Dir: </h2>";
echo '<pre>';
print_r($dir);
echo '</pre>';
*/
$path = '';
$path = null;
$role = null;
if(isset($dir['@']['baseinstalldir'])){
$this->_updateDirs('baseinstalldir', $dir['@']['baseinstalldir']);
}
if(isset($dir['@']['name']) && $dir['@']['name'] != '/' && $dir['@']['name'] != '\\'){
$this->_updateDirs('name', $dir['@']['name']);
}
if(isset($dir['@']['role'])){
$role = $dir['@']['role'];
}
$this->_getFilelistFlat($dir, $role);
}
break;
case 'file':
//echo "<h1>Type: $type</h1>";
$dir_name = $this->_getDirsPath('name');
$dir_baseinstalldir = $this->_getDirsPath('baseinstalldir');
foreach($items as $file) {
//echo "<h2>File: (Level $this->filelist_level)</h2>";
$file_id = count($this->filelist);
if(!is_array($file)){
$this->filelist[$file_id]["@"]["name"] = $file;
if(!is_null($role)){
$this->filelist[$file_id]["@"]["role"] = $role;
}
} else {
$this->filelist[$file_id] = $file;
}
if(!isset($this->filelist[$file_id]["@"]["name"])){
$this->filelist[$file_id]["@"]["name"] = $dir_name.$this->filelist[$file_id]["#"];
} elseif(strlen($dir_name)){
$this->filelist[$file_id]["@"]["name"] = $dir_name.$this->filelist[$file_id]["@"]["name"];
}
if(isset($this->filelist[$file_id]["@"]["baseinstalldir"])){
// filter root slash
if(
$this->filelist[$file_id]["@"]["baseinstalldir"] == '/' ||
$this->filelist[$file_id]["@"]["baseinstalldir"] == '\\'
){
$this->filelist[$file_id]["@"]["baseinstalldir"] = '';
}
$this->filelist[$file_id]["@"]["baseinstalldir"] = $dir_baseinstalldir.$this->filelist[$file_id]["@"]["baseinstalldir"];
} else {
$this->filelist[$file_id]["@"]["baseinstalldir"] = $dir_baseinstalldir;
}
if(!isset($this->filelist[$file_id]["@"]["role"])){
// check if we have a role association defined by the directory
if(!is_null($role)){
$this->filelist[$file_id]["@"]["role"] = $role;
} else {
$this->filelist[$file_id]["@"]["role"] = '';
}
}
/*
echo '<pre>';
print_r($this->filelist[$file_id]);
echo '</pre>';
*/
}
// if there's no child directory, we lower the filelist level
if(!isset($filelist['dir'])){
$this->decreaseFilelistLevel();
$this->_updateDirs('baseinstalldir');
$this->_updateDirs('name');
}
break;
}
}
}
return true;
}
function increaseFilelistLevel()
{
$this->filelist_level++;
}
function decreaseFilelistLevel()
{
if($this->filelist_level != 0){
$this->filelist_level--;
}
}
function _updateDirs($type, $new_path = null)
{
if(!is_null($new_path)){
$this->dirs[$type][$this->filelist_level] = $new_path;
} elseif(isset($this->dirs[$type]) && is_array($this->dirs[$type])) {
if($this->filelist_level == 0){
$this->dirs[$type] = array();
} else {
$dirs_tmp = array();
/*
echo '<pre>1';
print_r($this->dirs);
echo '</pre>';
*/
// rearrange the array with values only until we hit
// the current directory
foreach($this->dirs[$type] as $level => $val){
$dirs_tmp[$level] = $val;
//echo 'Filelist Level: '.$this->filelist_level.'<br/>';
if($level == $this->filelist_level){
break;
}
}
/*
echo '<pre>2';
print_r($filelist_baseinstalldirs);
echo '</pre>';
*/
$this->dirs[$type] = $dirs_tmp;
}
}
}
function _getDirsPath($type)
{
/*
echo '<pre>1';
print_r($this->dirs);
echo '</pre>';
*/
$path = '';
if(isset($this->dirs[$type]) && is_array($this->dirs[$type]) && count($this->dirs[$type])){
$path = implode(DIRECTORY_SEPARATOR,$this->dirs[$type]);
//echo "Path: $path <br/>";
} else {
return false;
}
if(strlen($path)){
$path .= DIRECTORY_SEPARATOR;
}
return $path;
}
}
?>
--- NEW FILE: package.xml ---
<?xml version="1.0" encoding="ISO-8859-1" ?>
<package version="1.0"
xmlns="http://www.zzoss.com/NS/installer/package/">
<name>com.zzoss.package.descriptor.lib</name>
<summary>Class for Package XML Descriptor.</summary>
<description>Methods to read and transform the XML encoded information of a package XML file.</description>
<maintainers>
<maintainer>
<user>czonsius</user>
<name>Christian Zonsius</name>
<email>[email protected]</email>
<role>developer</role>
</maintainer>
<maintainer>
<user>ordnas</user>
<name>Sandro Zic</name>
<email>[email protected]</email>
<role>lead</role>
</maintainer>
</maintainers>
<release>
<version>1.0.0</version>
<date>{zi_release_date}</date>
<license url="http://www.gnu.org/licenses/lgpl.txt" version="2">LGPL</license>
<state>stable</state>
<notes>Initial release.</notes>
<copyright>
<holder year="{zi_copyright_year}" url="http://www.zzoss.com">ZZ/OSS</holder>
</copyright>
<filelist>
<file role="php" baseinstalldir="ZZOSS_Package" name="Descriptor.php"/>
</filelist>
</release>
</package>
-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297