I updated a centos machine from this code... you ripper, it works!
[glcas.git] / unittests / repomdxmlload.php
diff --git a/unittests/repomdxmlload.php b/unittests/repomdxmlload.php
new file mode 100644 (file)
index 0000000..7054529
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+
+// begin unit test header
+$WEB_ROOT_FS = realpath(dirname(__FILE__));
+$BASE_URL = dirname($_SERVER["PHP_SELF"]);
+
+global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
+
+if(file_exists("../libglcas")) {
+       $path = realpath($WEB_ROOT_FS."/../");
+       error_log("added glcas path as $path");
+       set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+require_once("../libglcas/lib.php");
+
+
+glcas_pluginLoader();
+
+// find our config
+$configpath = "";
+
+// TODO: do this better
+if(file_exists($WEB_ROOT_FS."/../var")) {
+       
+       // is it there?
+       if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) {
+               $configpath = realpath("$WEB_ROOT_FS/../var/glcas/webconfig");
+       } else {        
+               // if not, attempt to create
+               if(!file_exists($WEB_ROOT_FS."/../var/glcas")) {
+                       mkdir($WEB_ROOT_FS."/../var/glcas");
+               }
+               // success!
+               touch("$WEB_ROOT_FS/../var/glcas/webconfig");
+               $configpath = realpath("$WEB_ROOT_FS/../var/glcas/webconfig");
+       }
+}
+
+
+$glconfig = new GLCASConfig();
+$glconfig->loadConfig($configpath);
+
+
+// end unit test header
+$repostore = $glconfig->getConfigVar("storagelocation");
+
+// find a repomd.xml file
+echo "<html><pre>";
+$ckey =0;
+for($i=0; $i<100; $i++) {
+       //echo "Checking $repostore/$i\n";
+       if(file_exists($repostore."/$i/repodata/repomd.xml")) $ckey = $i;
+}
+
+if($ckey == 0) {
+       echo "couldnt find a ckey";
+       return;
+}
+
+$xml = simplexml_load_file($repostore."/$ckey/repodata/repomd.xml");
+
+//echo "XML $ckey is:\n";
+//print_r($xml);
+
+foreach($xml as $key => $var) {
+       //echo "for key $key has:\n";
+       //print_r($var);
+       if($key == "data") {
+               $fileloc = $var->location["href"];
+               echo "file loc to load: $fileloc\n";
+       }
+}
+
+echo "</pre></html>";
+
+?>
\ No newline at end of file