Example #1
0
 /**
  * Analyse packages associated with specified channel
  *
  * Return stats array (and total size used by all packages inside a
  * specified channel).
  *
  * @param array  $packages      array of names of packages to search for.
  * @param object $reg           PEAR Registry object.
  * @param int    $channel_index index value of entry in channels_full array to
  *                              search for packages
  *
  * @return array
  */
 private function _analysePackages($packages, $reg, $channel_index)
 {
     $index = $channel_index;
     $stats = array();
     $channel_total = 0;
     foreach ($packages as $package) {
         if (strlen($package) > $this->_name_length) {
             $this->_name_length = strlen($package);
         }
         $sizes = array('data' => 0, 'doc' => 0, 'ext' => 0, 'php' => 0, 'man' => 0, 'script' => 0, 'src' => 0, 'test' => 0, 'www' => 0);
         $pkg = $this->reg->getPackage($package, $this->_channels_full[$index]);
         if ($pkg === null) {
             array_push($this->warnings, "Package \"{$package}\" not found");
             continue;
         }
         $version = $pkg->getVersion();
         $filelist = $pkg->getFileList();
         $package_total = 0;
         foreach ($filelist as $file) {
             $role = $file['role'];
             $srole = "|{$role}|";
             if (strpos($this->search_roles, $srole) !== false) {
                 $installed_location = $file['installed_as'];
                 if (!file_exists($installed_location)) {
                     $dn = explode("/", $installed_location);
                     if ($dn[0] == 'debian') {
                         array_shift($dn);
                         array_shift($dn);
                         $installed_location = "/" . implode($dn, "/");
                         unset($dn);
                     }
                 }
                 if (file_exists($installed_location)) {
                     $fsize = filesize($installed_location);
                     $sizes[$role] += $fsize;
                     $package_total += $fsize;
                 } else {
                     array_push($this->warnings, "File \"{$installed_location}\" does not exist");
                 }
             }
         }
         array_push($stats, array('package' => $pkg->getName(), 'total' => $package_total, 'sizes' => $sizes));
         $channel_total += $package_total;
     }
     $this->_grand_total += $channel_total;
     return array($stats, $channel_total);
 }