file datastore work
authorpaulr <me@pjr.cc>
Tue, 19 Apr 2011 17:50:05 +0000 (03:50 +1000)
committerpaulr <me@pjr.cc>
Tue, 19 Apr 2011 17:50:05 +0000 (03:50 +1000)
doc/globals.txt [new file with mode: 0644]
lib/lib.php
lib/plugins/aptproxy.php
lib/plugins/datastore.php
lib/plugins/db.php
lib/plugins/www.php
lib/plugins/yumproxy.php
unittests/datastores.php [new file with mode: 0644]

diff --git a/doc/globals.txt b/doc/globals.txt
new file mode 100644 (file)
index 0000000..e77fa2d
--- /dev/null
@@ -0,0 +1,8 @@
+$BASE_URLS["ypc"]["base"] = "ypc"; // ap for apt-proxy
+$BASE_URLS["ypc"]["function"] = "yp_contentUrlsCtl"; 
+
+$MENU_ITEMS["yp"]["title"] = "YUM Proxy";
+$MENU_ITEMS["yp"]["link"] = "/ypc/proxycontrol";
+
+$GLOBAL_BASE_URL="/src/eclipse-workspace/glcas/www/";
+$DB_URL="sqlite:$BASE_DIR/var/ds_store.db";
index 2a5ace8..e446b09 100644 (file)
@@ -3,8 +3,13 @@
 require_once("config.php");
 require_once("wsdl.php");
 
+
 // first and foremost, load the plugins
 $basedir = dirname(__FILE__);
+
+// we load this first
+if(file_exists("$basedir/plugins/www.php")) require_once("$basedir/plugins/www.php");
+
 if(is_dir("$basedir/plugins")) {
        $dh = opendir("$basedir/plugins");
        if($dh) {
index 65d0c0d..161ade2 100644 (file)
@@ -1,6 +1,32 @@
 <?php
 global $BASE_URLS;
 
-$BASE_URLS["ap"]["base"] = "ap"; // ap for apt-proxy
-$BASE_URLS["ap"]["function"] = "ap_pageBuilder"; // the page builder function for us
+$BASE_URLS["apc"]["base"] = "apc"; // ap for apt-proxy
+$BASE_URLS["apc"]["function"] = "ap_pageBuilderCtl"; // the page builder function for us
+$BASE_URLS["apr"]["base"] = "apr"; // ap for apt-proxy
+$BASE_URLS["apr"]["function"] = "ap_pageBuilderPrx"; // the page builder function for us
+
+$MENU_ITEMS["ap"]["title"] = "APT Proxy";
+$MENU_ITEMS["ap"]["link"] = "/apc/proxycontrol";
+
+function ap_pageBuilderCtl()
+{
+       $calls["needs_base_page"] = true;
+       $calls["content_pane_function"] = "ap_contentPane";
+       $calls["left_menu_function"] = "ap_leftMenu";
+       
+       return $calls;
+}
+
+function ap_contentPane()
+{
+       echo "i am a ap content pane<br>";
+}
+
+function ap_leftMenu()
+{
+       echo "i am a ap leftmenu";
+}
+
+
 ?>
\ No newline at end of file
index ccaca5c..16ae107 100644 (file)
@@ -4,7 +4,7 @@ global $BASE_URLS, $MENU_ITEMS, $GLOBAL_BASE_URL;
 $BASE_URLS["ds"]["base"] = "ds"; // ap for apt-proxy
 $BASE_URLS["ds"]["function"] = "ds_contentUrls"; // the page builder function for us
 $MENU_ITEMS["ds"]["title"] = "DataStores";
-$MENU_ITEMS["ds"]["link"] = "$GLOBAL_BASE_URL/ds/control";
+$MENU_ITEMS["ds"]["link"] = "/ds/control";
 
 
 function ds_contentPane()
@@ -28,11 +28,64 @@ function ds_contentUrls()
 
 function ds_createDS($ds_name, $store_location)
 {
+       db_createTable("datastores", "dsname", "dslocation");
+       db_createTable("datastores_files", "dsname", "fileowner", "filename", "dsfname");
        
+       $data = db_selectData("datastores", "dsname", "$ds_name");
+       if(isset($data[0]["dsname"])) return false;
+       
+       db_insertData("datastores", "$ds_name", "$store_location");
+}
+
+function ds_listDS()
+{
+       return db_selectData("datastores");
+}
+
+function ds_deleteFile($ds_name, $file_name, $file_tag)
+{
+       $dlk = db_selectData("datastores_files", "filename", $file_name);
+       $afname = "";
+       foreach($dlk as $kmm) {
+               if($kmm["fileowner"] == $file_tag) {
+                       // we got ya
+                       $afname = $kmm["dsfname"];
+                       if(file_exists($afname)) unlink($afname);
+                       echo "name was: $afname\n";
+               }
+       }
+       echo "now delete name was: $afname\n";
+       if($afname != "") db_deleteData("datastores_files", "dsfname", $afname);
+}
+
+// returns a file name to the location a file can be created
+function ds_fileds($ds_name, $file_name, $file_tag)
+{
+
+       $data = db_selectData("datastores", "dsname", "$ds_name");
+       
+       $dtime = time();
+       $made_file_name = "$dtime-".md5($file_name)."-".basename($file_name);
+       
+       $act_fname = $data[0]["dslocation"]."/".basename($made_file_name);
+       
+       db_insertData("datastores_files", "$ds_name", "$file_tag", "$file_name", "$act_fname");
+       
+       return $act_fname;
 }
 
-function ds_fileds($ds_name, $file_id, $file_name)
+function ds_getFileList($ds_name, $file_tag)
+{
+       $list = db_selectData("datastores_files", "fileowner", "$file_tag");
+       
+       return $list;
+}
+
+
+function ds_deleteDS($ds_name)
 {
+       db_deleteData("datastores", "dsname", "$ds_name");
+       db_deleteData("datastores_files", "dsname", $ds_name);
 }
 
 function ds_downloadAndStore($ds_name, $file_id, $file_name, $file_url)
index f19a1fa..1906157 100644 (file)
@@ -29,6 +29,8 @@ function db_createTable($tablename)
 {
        $db = db_getDB();
        
+       if(db_tableExists($tablename)) return true;
+       
        $sql = "create table \"$tablename\" (\"".$tablename."_id\" INTEGER PRIMARY KEY AUTOINCREMENT";
        for($i=1; $i < func_num_args(); $i++) {
                $colname = func_get_arg($i);
@@ -54,11 +56,13 @@ function db_insertData($tablename)
        $db->query($sql);
 }
 
-function db_selectData($tablename, $column, $value)
+function db_selectData($tablename, $column="", $value="")
 {
        $db = db_getDB();
        
-       $sql = "select * from \"$tablename\" where $column like '%$value%'";
+       if($column != "") $extra = " where $column like '%$value%'";
+       else $extra = "";
+       $sql = "select * from \"$tablename\"$extra";
        $res = $db->query($sql);
        $data = $res->fetchAll();
        
@@ -69,7 +73,8 @@ function db_deleteData($tablename, $column, $value)
 {
        $db = db_getDB();
        
-       $sql = "delete from \"$tablename\" where column_$column like '%$value%'";
+       $sql = "delete from \"$tablename\" where $column like '%$value%'";
+       //echo "Sql is $sql\n";
        return $db->query($sql);
        
 }
index 1738c23..d060677 100644 (file)
@@ -4,24 +4,32 @@ global $BASE_URLS;
 
 $BASE_URLS["wp"]["base"] = "";
 $BASE_URLS["wp"]["function"] = "wp_pageBuilder";
+$MENU_ITEMS["wp"]["title"] = "Home";
+$MENU_ITEMS["wp"]["link"] = "/";
 
 function goWebProcessor($calls)
 {
        if(isset($calls["needs_base_page"])) {
                if($calls["needs_base_page"] == true) {
                        // build page
-                       echo "here base\n";
+                       // echo "here base\n";
                        www_basePage($calls);
                } else {
                        $func = $calls["page_builder"];
                        $func();
                }
        } else {
-               echo "here base 2\n";
                www_basePage($calls);
        }
 }
 
+function wp_pageBuilder()
+{
+       $calls["needs_base_page"] = true;
+       
+       return $calls;
+}
+
 function www_basePage($calls)
 {
                
@@ -95,11 +103,14 @@ function www_top()
        echo "<h1>Welcome to GLCAS</h1>";
        echo "<table><tr>";
        
-       global $MENU_ITEMS;
+       global $MENU_ITEMS, $GLOBAL_BASE_URL;
        foreach($MENU_ITEMS as $mes) {
                $mtext = $mes["title"];
-               $mlink = $mes["link"];
-               echo "<td><a href=\"$mlink\">$mtext</a></td>";
+               $mlink = "$GLOBAL_BASE_URL/".$mes["link"];
+               // remove the excess /'s
+               $mlink2 = preg_replace("/\/[\/]+/", "/", $mlink);
+               //echo "went from $mlink to $mlink2\n";
+               echo "<td><a href=\"$mlink2\">$mtext</a></td>";
        }
        
        echo "</tr></table>";
index 5db52a0..68c8768 100644 (file)
@@ -6,7 +6,7 @@ $BASE_URLS["ypc"]["function"] = "yp_contentUrlsCtl"; // the page builder functio
 $BASE_URLS["ypr"]["base"] = "ypr"; // ap for apt-proxy
 $BASE_URLS["ypr"]["function"] = "yp_contentUrlsPrx"; // the page builder function for us
 $MENU_ITEMS["yp"]["title"] = "YUM Proxy";
-$MENU_ITEMS["yp"]["link"] = "$GLOBAL_BASE_URL/ypc/proxycontrol";
+$MENU_ITEMS["yp"]["link"] = "/ypc/proxycontrol";
 
 
 function yp_contentPane()
@@ -27,4 +27,17 @@ function yp_contentUrlsCtl()
        
        return $calls;
 }
+
+function yp_contentUrlsPrx()
+{
+       $calls["needs_base_page"] = false;
+       $calls["page_builder"] = "yp_proxyPageBuilder";
+       
+       return $calls;
+}
+
+function yp_proxyPageBuilder()
+{
+       echo "<html>I write the songs that make the whole world sing</html>";
+}
 ?>
\ No newline at end of file
diff --git a/unittests/datastores.php b/unittests/datastores.php
new file mode 100644 (file)
index 0000000..f5313c4
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+require_once("../lib/lib.php");
+
+echo "create 3 datastores\n";
+ds_createDS("name1", "/tmp");
+ds_createDS("name2", "/tmp");
+ds_createDS("name3", "/tmp");
+
+$tl = ds_listDS();
+
+print_r($tl);
+
+echo "try to create them again\n";
+ds_createDS("name1", "/tmp");
+ds_createDS("name2", "/tmp");
+ds_createDS("name3", "/tmp");
+
+$tl = ds_listDS();
+
+print_r($tl);
+
+echo "Delete 2 of them\n";
+ds_deleteDS("name1");
+ds_deleteDS("name2");
+
+$tl = ds_listDS();
+
+print_r($tl);
+
+echo "delete the last one\n";
+ds_deleteDS("name3");
+
+$tl = ds_listDS();
+
+print_r($tl);
+
+echo "now create a new ds\n";
+ds_createDS("name1", "/tmp");
+
+$myfname = "/asdf/asdf/asdf/asdf";
+$mytag = "mytag";
+
+echo "now createa a file inside our ds\n";
+//ds_fileds($ds_name, $file_name, $file_tag)
+$lk = ds_fileds("name1", $myfname, $mytag);
+echo "file created as name: $lk\n";
+
+echo "get file list:\n";
+$lk = ds_getFileList("name1", $mytag);
+print_r($lk);
+
+echo "delete the file\n";
+ds_deleteFile("name1", $myfname, $mytag);
+
+echo "get file list:\n";
+$lk = ds_getFileList("name1", $mytag);
+print_r($lk);
+
+echo "delete the last ds\n";
+ds_deleteDS("name1");
+?>
\ No newline at end of file