protected function fromUrl($param, $saveparam = '') { $this->type = 'url'; $dir = Config::current()->download_dir; try { $response = \Pyrus\Main::downloadWithProgress($param); if ($response->code != '200') { throw new Exception('Download failed, received ' . $response->code); } $info = parse_url($param); $name = urldecode(basename($info['path'])); if (isset($response->headers['content-disposition'])) { if (preg_match('/filename="(.+)"/', $response->headers['content-disposition'], $match)) { $name = $match[1]; } } if (!@file_exists($dir)) { mkdir($dir, 0755, true); } if (false === file_put_contents($dir . DIRECTORY_SEPARATOR . $name, $response->body)) { throw new Exception('Unable to save package ' . $name . ' to downloads directory, ' . $dir . '. Do we have permission to write there?'); } // whew, download worked! $a = new \Pyrus\Package($dir . DIRECTORY_SEPARATOR . $name); return $a->getInternalPackage(); } catch (\Pyrus\HTTPException $e) { throw $e; // pass it along } catch (\Exception $e) { if (!empty($saveparam)) { $saveparam = ", cannot download \"{$saveparam}\""; } throw new Exception('Could not download from "' . $param . '"' . $saveparam, $e); } }
public function info($package, $channel, $field) { if (!$this->exists($package, $channel)) { throw new Exception('Unknown package ' . $channel . '/' . $package); } $packagefile = glob($this->_namePath($channel, $package) . DIRECTORY_SEPARATOR . '*.xml'); if (!$packagefile || !isset($packagefile[0])) { throw new Exception('Cannot find registry for package ' . $channel . '/' . $package); } $packageobject = new \Pyrus\Package($packagefile[0]); if ($field === null) { return $packageobject->getInternalPackage()->getPackageFile()->getPackageFileObject(); } if ($field == 'version') { $field = 'release-version'; } elseif ($field == 'installedfiles') { $ret = array(); try { $config = new \Pyrus\Config\Snapshot($packageobject->date . ' ' . $packageobject->time); } catch (\Exception $e) { throw new Exception('Cannot retrieve files, config ' . 'snapshot could not be processed', $e); } $roles = array(); foreach (Role::getValidRoles($packageobject->getPackageType()) as $role) { // set up a list of file role => configuration variable // for storing in the registry $roles[$role] = Role::factory($packageobject->getPackageType(), $role); } $ret = array(); foreach ($packageobject->installcontents as $file) { $relativepath = $roles[$file->role]->getRelativeLocation($packageobject, $file); if (!$relativepath) { continue; } $filepath = $config->{$roles[$file->role]->getLocationConfig()} . DIRECTORY_SEPARATOR . $relativepath; $attrs = $file->getArrayCopy(); $ret[$filepath] = $attrs['attribs']; $ret[$filepath]['installed_as'] = $filepath; $ret[$filepath]['relativepath'] = $relativepath; $ret[$filepath]['configpath'] = $config->{$roles[$file->role]->getLocationConfig()}; } return $ret; } elseif ($field == 'dirtree') { $files = $this->info($package, $channel, 'installedfiles'); foreach ($files as $file => $unused) { do { $file = dirname($file); if (strlen($file) > strlen($this->_path)) { $ret[$file] = 1; } } while (strlen($file) > strlen($this->_path)); } $ret = array_keys($ret); usort($ret, 'strnatcasecmp'); return array_reverse($ret); } return $packageobject->{$field}; }