From: <jhe...@us...> - 2002-11-12 11:06:19
|
Update of /cvsroot/upcase-project/UpCase/lib In directory usw-pr-cvs1:/tmp/cvs-serv26230 Added Files: uc_repository.php Log Message: client side repository handling (info retrieval and updating) --- NEW FILE: uc_repository.php --- <?php define("REPOSITORY_ROOT", "/packages"); define("METADATA_FILE", "meta.inc"); define("METADATA_BACKUP", "/db"); include_once("uc_utils.php"); class UcRepositoryObject { var $sourceDir; // remote directory for this object var $localDir; // local directory where this objects live var $metaDataFile; var $name; function UcRepositoryObject($localDir, $sourceDir) { $this->localDir = $localDir; $this->metaDataFile = $this->localDir . "/" . METADATA_FILE; $this->sourceDir = $sourceDir; } function initialize() { } function fetchMetaData() { $srcFile = $this->sourceDir . "/" . METADATA_FILE; $dstFile = $this->metaDataFile; if (file_exists($dstFile)) unlink($dstFile); if (download($srcFile, $dstFile) > -1) return true; else return false; } function checkDirectory() { if (is_dir($this->localDir) && is_writeable($this->localDir)) return true; return false; } function createDirectory() { if (file_exists($this->localDir)) { if (!is_dir($this->localDir)) die("$this->localDir exists and is not a directory"); } else mkdir($this->localDir, 0775) or die("Unable to create directory $this->localDir"); } function update() { $this->fetchMetaData() or die("Unable to get meta data for $this->name"); $this->initialize(); } } class UcLocalRepository extends UcRepositoryObject { var $categories; var $description; var $metaBackup; function UcLocalRepository() { $cfg = $GLOBALS["ucConfig"]; $this->UcRepositoryObject($cfg->filesRoot . REPOSITORY_ROOT, $GLOBALS["packagesSource"]); $this->name = "repository"; $this->initialize(); } function initialize() { if (!$this->checkDirectory()) $this->createDirectory(); if (!file_exists($this->metaDataFile)) $this->fetchMetaData(); include($this->metaDataFile); foreach ($categories as $categoryName) { $this->categories[] = $categoryName; } $this->categories = $categories; $this->description = $description; } function getCategories() { $car = array(); foreach ($this->categories as $category) $car[$category] = new UcCategory($this, $category); return $car; } function getCategory($category) { $car = $this->getCategories(); return $car[$category]; } function update() { $this->fetchMetaData() or die("Unable to get meta data for $this->name"); $this->initialize(); $categories = $this->getCategories(); foreach ($categories as $category) $category->update(); } } class UcCategory extends UcRepositoryObject { var $packages; var $description; function UcCategory($repository, $categoryName) { $this->UcRepositoryObject($repository->localDir . "/$categoryName", $repository->sourceDir . "/$categoryName"); $this->name = $categoryName; $this->initialize(); } function initialize() { if (!$this->checkDirectory()) $this->createDirectory(); if (!file_exists($this->metaDataFile)) $this->fetchMetaData(); include($this->metaDataFile); $this->packages = $packages; $this->description = $description; } function getPackages() { $par = array(); foreach ($this->packages as $packageName) $par[$packageName] = new UcPackage($this, $packageName); return $par; } function getPackage($pkgname) { $par = $this->getPackages(); return $par[$pkgname]; } function update() { $this->fetchMetaData() or die("Unable to get meta data for $this->name"); $this->initialize(); $packages = $this->getPackages(); foreach ($packages as $package) $package->update(); } } class UcPackage extends UcRepositoryObject { function UcPackage($category, $packageName) { $this->UcRepositoryObject($category->localDir . "/$packageName", $category->sourceDir . "/$packageName"); $this->name = $packageName; $this->initialize(); } function initialize() { if (!$this->checkDirectory()) $this->createDirectory(); if (!file_exists($this->metaDataFile)) $this->fetchMetaData(); include($this->metaDataFile); $this->description = $description; $this->homePage = $home_page; $this->version = $version; $this->source = $source; } } ?> |