[zi-cvs] packages/com.zzoss.plugin.lib Plugin.php,1.9,1.10

Sandro Zic <[email protected]> Tue, 23 Mar 2004 18:20:35 +0000
Newsgroups gmane.comp.php.zzoss.installer.cvs
Message-ID <[email protected]>
Update of /cvsroot/zzossinstaller/packages/com.zzoss.plugin.lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25860/com.zzoss.plugin.lib

Modified Files:
	Plugin.php 
Log Message:
deal with dir elements in filelist element of package.xml

Index: Plugin.php
===================================================================
RCS file: /cvsroot/zzossinstaller/packages/com.zzoss.plugin.lib/Plugin.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Plugin.php	22 Mar 2004 08:25:24 -0000	1.9
--- Plugin.php	23 Mar 2004 18:20:33 -0000	1.10
***************
*** 66,69 ****
--- 66,79 ----
      var $file_baseinstalldir = array();
      
+     /**
+     * Track dirs of filelist.
+     */
+     var $filelist_dirs = array();
+     
+     /**
+     * Track roles of dirs of filelist.
+     */
+     var $filelist_dirs_roles = array();
+     
      function setDestDir($dest_dir)
      {
***************
*** 195,225 ****
      function execRole()
      {
          //$this->log .= 'Files: '.var_export($files, true);
!         if(isset($this->package["release"]["filelist"]) && is_array($this->package["release"]["filelist"])) {
!             $files = $this->package["release"]["filelist"]["file"];
!             foreach($files as $file) {
!                 $this->file = $file;
!                 
!                 if(isset($this->file["@"]["baseinstalldir"])){
!                     $this->file_baseinstalldir[$this->file["@"]["name"]] = $this->file["@"]["baseinstalldir"];
!                 }
!                 
!                 if(!isset($this->file["@"]["role"])){
!                     $this->file["@"]["role"] = '';
!                 }
!                 
!                 // execute plugins
!                 $this->log .= "* Dealing with role '".$this->file["@"]["role"]."'\n";
!                 //$this->log .= "  performing on '".var_export($this->plugins['role']['role'], true)."'\n";
!                 if(!isset($this->plugins['role']['role'][$this->file["@"]["role"]])){
!                     $this->execPluginRole();
!                 } else {
!                     if(!$this->includePlugins($this->plugins['role']['role'][$this->file["@"]["role"]])){
!                         $this->log .= "* ERROR: A handler for this role does not exist.\n";
!                     }
!                 }
!             }
!         } else {
!             $this->log .= "No files.\n";
          }
          
--- 205,225 ----
      function execRole()
      {
+         /*
+         if($this->package['name'] == 'Auth_HTTP'){
+             echo '<h1>'.$this->package['name'].'</h1>';
+             echo '<pre>';
+             print_r($this->package["release"]['filelist']);
+             echo '</pre>';
+             unlink('C:\WINDOWS\Temp\zzoss_installer\1\dev\distributions\com.zzoss-1.0.0\applications\zic-1.1.0dev1\installer\packages_packages.reg');
+             //die();
+         }
+         //return true;
+         */
          //$this->log .= 'Files: '.var_export($files, true);
!         if(isset($this->package["release"]["filelist"])){
!             // clean up previous filelist
!             $this->filelist_dirs = array();
!             $this->filelist_dirs_roles = array();
!             $this->execRoleFilelist($this->package["release"]["filelist"]);
          }
          
***************
*** 243,246 ****
--- 243,374 ----
      }
      
+     function execRoleFilelist($filelist, $role = null)
+     {
+         if(!is_array($filelist) || !count($filelist)){
+             $this->log .= "No files.\n";
+             return false;
+         } else {
+             // path of previous dir
+             $path_prev = '';
+             if(isset($filelist['@']['baseinstalldir'])){
+                 $path_prev = $filelist['@']['baseinstalldir'];
+             }
+             if(isset($filelist['@']['name']) && $filelist['@']['name'] != '/' && $filelist['@']['name'] != '\\'){
+                 $path_prev .= DIRECTORY_SEPARATOR.$filelist['@']['name'];
+             }
+             foreach($filelist as $type => $items){
+                 switch($type){
+                     case 'dir':
+                         foreach($items as $dir){
+                             $path = '';
+                             $path = null;
+                             $role = null;
+                             
+                             if(isset($dir['@']['baseinstalldir'])){
+                                 $path = $dir['@']['baseinstalldir'];
+                             }
+                             if(isset($dir['@']['name']) && $dir['@']['name'] != '/' && $dir['@']['name'] != '\\'){
+                                 $path .= DIRECTORY_SEPARATOR.$dir['@']['name'];
+                             }
+                             
+                             if(isset($dir['@']['role'])){
+                                 $role = $dir['@']['role'];
+                             }
+                             
+                             $this->updateDirsStack($path_prev);
+                             array_push($this->filelist_dirs, $path);
+                             
+                             $this->execRoleFilelist($dir, $role);
+                         }
+                     break;
+                     case 'file':
+                         $this->updateDirsStack($path_prev);
+                         $dir_path = '';
+                         if(count($this->filelist_dirs)){
+                             $dir_path = ZZOSS_InstallerUtils::fixPath(implode(DIRECTORY_SEPARATOR,$this->filelist_dirs));
+                             //echo "Path: $dir_path <br/>";
+                         }
+                         
+                         foreach($items as $key => $file) {
+                             if(!is_array($file)){
+                                 $this->file["@"]["name"] = $file;
+                                 if(!is_null($role)){
+                                     $this->file["@"]["role"] = $role;
+                                 }
+                             } else {
+                                 $this->file = $file;
+                             }
+                             
+                             if(!isset($this->file["@"]["name"])){
+                                 $this->file["@"]["name"] = $this->file["#"];
+                             }
+                             
+                             if(isset($this->file["@"]["baseinstalldir"])){
+                                 $this->file_baseinstalldir[$this->file["@"]["name"]] = $dir_path.$this->file["@"]["baseinstalldir"];
+                             } else {
+                                 $this->file_baseinstalldir[$this->file["@"]["name"]] = $dir_path;
+                             }
+                             
+                             if(!isset($this->file["@"]["role"])){
+                                 // check if we have a role association defined by the directory
+                                 if(!is_null($role)){
+                                     $this->file["@"]["role"] = $role;
+                                 } else {
+                                     $this->file["@"]["role"] = '';
+                                 }
+                             }
+                             
+                             //echo "Filename: {$this->file["@"]["name"]} <br/>";
+                             //echo "Role: {$this->file["@"]["role"]} <br/>";
+                             //echo "Path: {$this->file_baseinstalldir[$this->file["@"]["name"]]}".DIRECTORY_SEPARATOR."{$this->file["@"]["name"]} <br/>";
+                             
+                             // execute plugins
+                             $this->log .= "* Dealing with role '".$this->file["@"]["role"]."'\n";
+                             //$this->log .= "  performing on '".var_export($this->plugins['role']['role'], true)."'\n";
+                             if(!isset($this->plugins['role']['role'][$this->file["@"]["role"]])){
+                                 $this->execPluginRole();
+                             } else {
+                                 if(!$this->includePlugins($this->plugins['role']['role'][$this->file["@"]["role"]])){
+                                     $this->log .= "* ERROR: A handler for this role does not exist.\n";
+                                 }
+                             }
+                         }
+                     break;
+                 }
+             }
+         }
+         
+         return true;
+     }
+     
+     function updateDirsStack($path_prev)
+     {
+         // if the current dir is within previous dirs, we truncate the array,
+         // but only if the current directory is not the last one in our stack
+         if(strlen($path_prev) && end($this->filelist_dirs) != $path_prev){
+             //reset($this->fielist_dirs);
+             $filelist_dirs = array();
+             /*
+             echo '<pre>1';
+             print_r($this->filelist_dirs);
+             echo '</pre>';
+             */
+             // rearrange the array with values only until we hit
+             // the current directory
+             foreach($this->filelist_dirs as $filelist_dir){
+                 $filelist_dirs[] = $filelist_dir;
+                 if($filelist_dir == $path_prev){
+                     break;
+                 }
+             }
+             /*
+             echo '<pre>2';
+             print_r($filelist_dirs);
+             echo '</pre>';
+             */
+             $this->filelist_dirs = $filelist_dirs;
+         }
+     }
+     
      function execPluginRole()
      {



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click