[zi-cvs] packages/com.zzoss.package.archive.lib Archive.php,NONE,1.1 package.xml,NONE,1.1
Sandro Zic <[email protected]> Sat, 24 Apr 2004 15:33:38 +0000
| Newsgroups | gmane.comp.php.zzoss.installer.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/zzossinstaller/packages/com.zzoss.package.archive.lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24755/com.zzoss.package.archive.lib
Added Files:
Archive.php package.xml
Log Message:
create package tgz with dir in filelist
--- NEW FILE: Archive.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: Archive.php,v 1.1 2004/04/24 15:33:36 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
*/
require_once 'PEAR.php';
require_once 'Archive/Tar.php';
require_once 'System.php';
require_once 'ZZOSS_Installer/Registry.php';
require_once 'ZZOSS_Config/Config.php';
require_once 'ZZOSS_Debug/Debug.php';
require_once 'ZZOSS_Dir/Dir.php';
/**
* This class parses the XML config file and provides the objects of the
* XML document.
*
* Extends PEAR XML_Parser class.
*
* @version 1
* @author Sandro Zic <[email protected]>; |
*/
class ZZOSS_PackageArchive extends PEAR {
function create($pkg_src_dir, $pkg_dest_dir = null)
{
static $pkg_tmpdir = '';
// take care of *nix and Win directory separators
if(DIRECTORY_SEPARATOR == '/'){
$wrong_dir_separator = '\\';
} else {
$wrong_dir_separator = '/';
}
if(is_null($pkg_dest_dir)){
$pkg_dest_dir = $pkg_src_dir;
}
$package_xml = $pkg_src_dir.DIRECTORY_SEPARATOR.'package.xml';
// Get package.xml and parse it to fill placeholder with content.
$replace_values['{zi_release_date}'] = date('Y-m-d');
$replace_values['{zi_copyright_year}'] = date('Y');
include_once 'ZZOSS_File/Replace.php';
$replace = new ZZOSS_FileReplace;
$replace->file($package_xml);
$replace->replace($replace_values);
// Create a temporary package.xml
// Create the temporary directory where we place it.
// But only if the directory does not already exist.
if(!isset($pkg_tmpdir) || !strlen($pkg_tmpdir)){
if (!($pkg_tmpdir = System::mktemp('-d'))) {
return PEAR::raiseError("Cannot create temporary directory.");
}
}
$package_xml_new = $pkg_tmpdir.DIRECTORY_SEPARATOR.'package.xml';
$replace->writeout($package_xml_new);
// Get package.xml parameters.
include_once 'ZZOSS_Config/Config.php';
$config = new ZZOSS_Config(array('numeric' => array('file', 'dir')));
$config->setFile($package_xml_new);
$xml = $config->query('/package');
$pkg_unique = $xml['name'].'-'.$xml['release']['version'];
$pkg_tgz = $pkg_dest_dir.DIRECTORY_SEPARATOR.$pkg_unique.'.tgz';
$tar_list = array();
// "Flatten" the filelist taking into accoutn <dir> elements
include_once 'ZZOSS_Package/Descriptor.php';
$descr = new ZZOSS_PackageDescriptor;
$descr->setArray($xml);
if(!$files = $descr->getFilelist('flat')){
$files = array();
} else {
include_once 'ZZOSS_File/File.php';
foreach($files as $file){
$tar_list[] = str_replace($wrong_dir_separator,DIRECTORY_SEPARATOR,ZZOSS_File::fixPath($file['@']['name']));
}
}
/*
echo '<pre>';
print_r($tar_list);
echo '</pre>';
*/
$plugin_files = array();
// Process plugin files.
if(
isset($xml['release']['plugin']['filelist']['file']) &&
is_array($xml['release']['plugin']['filelist']['file'])){
$plugin_files = $xml['release']['plugin']['filelist']['file'];
}
if(
isset($xml['release']['plugin']['file']) &&
is_array($xml['release']['plugin']['file'])){
$plugin_files = $xml['release']['plugin']['file'];
}
if(count($plugin_files)){
include_once 'ZZOSS_File/File.php';
// We remember if a plugin file has been defined
// various times, because we need to process it only once.
$plugin_files_processed = array();
foreach($plugin_files as $plugin_file){
if(!in_array($plugin_file['@']['name'], $plugin_files_processed)){
array_push($plugin_files_processed, $plugin_file['@']['name']);
$tar_list[] = str_replace($wrong_dir_separator,DIRECTORY_SEPARATOR,ZZOSS_File::fixPath($plugin_file['@']['name']));
}
}
}
$cwd = getcwd();
chdir($pkg_src_dir);
$tar = new Archive_Tar($pkg_tgz);
//$tar->setErrorHandling(PEAR_ERROR_PRINT);
$tar->createModify($package_xml_new, '', $pkg_tmpdir);
//$tar->create('package.xml');
$tar->addModify($tar_list, $pkg_unique);
chdir($cwd);
// delete the temporary package.xml
unlink($package_xml_new);
return $pkg_tgz;
}
}
?>
--- 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.archive.lib</name>
<summary>Class for Package Archives.</summary>
<description>Methods to create package .tgz from sources.</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="Archive.php"/>
</filelist>
<deps>
<dep type="pkg" rel="ge" version="1.0.0">com.zzoss.package.descriptor.lib</dep>
<dep type="pkg" rel="ge" version="1.0.0">com.zzoss.file.lib</dep>
<dep type="pkg" rel="ge" version="1.0.0">com.zzoss.file.replace.lib</dep>
</deps>
</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