gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r15268 - in gauger: . web


From: gnunet
Subject: [GNUnet-SVN] r15268 - in gauger: . web
Date: Fri, 20 May 2011 03:59:12 +0200

Author: bartpolot
Date: 2011-05-20 03:59:12 +0200 (Fri, 20 May 2011)
New Revision: 15268

Removed:
   gauger/gauger.py
Modified:
   gauger/install.sh
   gauger/web/hosts
   gauger/web/io.php
   gauger/web/postme.html
Log:
Deleted python server, imporved install script, changed POST feedback handling


Deleted: gauger/gauger.py
===================================================================
--- gauger/gauger.py    2011-05-19 22:17:12 UTC (rev 15267)
+++ gauger/gauger.py    2011-05-20 01:59:12 UTC (rev 15268)
@@ -1,268 +0,0 @@
-#!/usr/bin/env python
-"""gauger.py
-
-     This file is part of gauger.
-     Copyright 2011 Bartlomiej Polot
-
-     gauger is free software; you can redistribute it and/or modify
-     it under the terms of the GNU Affero General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     gauger is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     Affero General Public License for more details.
-
-     You should have received a copy of the GNU Affero General Public License
-     along with gauger; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-
-Gauger server.
-
-"""
-from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR
-import os
-import sys
-import glob
-import math
-import ConfigParser
-if(sys.version_info[0] == 2 and sys.version_info[1] < 7):
-    import ap27 as arg_parser
-else:
-    import argparse as arg_parser
-
-DATADIR="data/"
-PORT=10111
-
-def check_dir(path):
-    path = path.strip("/")
-    if (not os.path.exists(path)):
-        os.mkdir(path)
-        print "Created new host directory: ", path
-    if (not os.access(path, os.W_OK) or not os.path.isdir(path)):
-        print "Not a directory or not writable: ", path
-        return False
-    return True
-
-
-def process_arguments():
-    parser = arg_parser.ArgumentParser(description='Gauger server.')
-    parser.add_argument('--refresh', action='store_true',
-        help="refresh all .dat files and exit")
-    args = parser.parse_args()
-    return args
-
-def process_configuration():
-    global DATADIR
-    global PORT
-    parser = ConfigParser.ConfigParser()
-    parser.read(["gauger.conf"])
-    try:
-        DATADIR=parser.get("dir", "data")
-        DATADIR = DATADIR.strip('" ')
-        if(not DATADIR.endswith('/')):
-            DATADIR += '/'
-        if(not check_dir(DATADIR)):
-            print "ERROR: data dir not accessible"
-            exit (1)
-        print "Using datadir:", DATADIR
-        PORT=parser.getint('net', 'port')
-    except ConfigParser.NoSectionError:
-        pass
-    except ConfigParser.NoOptionError:
-        pass
-
-
-def get_all_data_files():
-    files = []
-    for d in glob.glob(DATADIR+"*/"):
-        for c in [x for x in glob.glob(d+"*") if x.find(".") == -1 and 
x.find("~") == -1]:
-            files.append(c)
-    return files
-
-
-def getminmax(s):
-    try:
-        f = open(s+".dat", "r")
-    except:
-        return None
-    for line in f.readlines():
-        try:
-            i = int(line.split(" ")[0])
-        except:
-            continue
-        try:
-            if(i < l):
-                l = i
-        except NameError:
-            l = i
-        try:
-            if(i > h):
-                h = i
-        except NameError:
-            h = i
-    f.close()
-    return l,h
-
-
-def refresh_all_dat():
-    """ Scans the raw data to regenrate the .dat files """
-    for f in get_all_data_files():
-        print f
-        fp = open(f, "r+")
-        add_data_to_file(fp, "", "")
-        fp.close()
-    create_global_range()
-
-
-def create_global_range():
-    """ Scans the data to find the lowest and highest x values """
-    for c in get_all_data_files():
-        try:
-            l,h = getminmax(c)
-        except:
-            continue
-        try:
-            if(l < xrange_min):
-                xrange_min = l
-        except NameError:
-            xrange_min = l
-        try:
-            if(h > xrange_max):
-                xrange_max = h
-        except NameError:
-            xrange_max = h
-    f = open(DATADIR+"global_range.dat", "w");
-    f.write("%d %d" % (xrange_min, xrange_max));
-    f.close();
-    return xrange_min,xrange_max;
-
-def get_global_range():
-    try:
-        f = open(DATADIR+"global_range.dat", "r");
-        xrange_min,xrange_max = f.readline().split(' ');
-        xrange_min = int(xrange_min);
-        xrange_max = int(xrange_max);
-        f.close();
-    except (IOError, ValueError):
-        xrange_min,xrange_max = create_global_range()
-    return xrange_min,xrange_max;
-
-def gethostfromlogin(user, password):
-  try:
-    f = open("gauger.conf", "r")
-  except:
-    print "ERROR: please create 'gauger.conf' with server configuration"
-    return ''
-  parser = ConfigParser.ConfigParser()
-  parser.readfp(f)
-  f.close()
-  try:
-    return parser.get("hosts", user+','+password)
-  except ConfigParser.NoSectionError:
-    return ''
-  except ConfigParser.NoOptionError:
-    return ''
-
-
-def add_data_to_file(datafile, revision, result):
-  datafile.seek(0, 0)
-  l = {}
-  for line in datafile.readlines():
-    try:
-        rev, val = line.split()
-        rev = int(rev)
-        val = float(val)
-    except ValueError:
-        continue
-    try:
-      l[rev].append(val)
-    except KeyError:
-      l[rev] = [val]
-  try:
-    l[int(revision)].append(float(result))
-  except KeyError:
-    l[int(revision)] = [float(result)]
-  except ValueError:            # Allows for add_data_to_file(f, "", "")
-    pass                        # in order to reprocess the data
-
-  datafile.seek(0, 0)
-  processedfile = open(datafile.name + ".dat", "w")
-
-  k = l.keys()
-  k.sort()
-
-  for rev in k:
-      avg = 0.0
-      sum = 0.0
-      n = 0
-      for val in l[rev]:
-          avg += val
-          n += 1
-          datafile.write("%d %f\n" % (rev, val))
-      avg /= n
-      for val in l[rev]:
-          sum += (avg - val)**2
-      stddev = math.sqrt(sum / n)
-      processedfile.write("%s %f %f\n" % (rev, avg, stddev))
-  processedfile.close()
-
-
-
-""" ******************* MAIN ******************************** """
-args = process_arguments()
-process_configuration()
-
-xrange_min,xrange_max = get_global_range()
-
-if(args.refresh):
-    refresh_all_dat()
-    exit(0)
-
-s1 = socket(AF_INET, SOCK_STREAM)
-s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
-s1.bind(("0.0.0.0", PORT))
-s1.listen(5)
-while(True):
-  s2, address = s1.accept()
-  print 'Connection from:', address
-  data = s2.recv(4096)
-  s2.close()
-  try:
-    user,password,revision,dataname,result = data.strip().split(',')
-  except:
-    print >> sys.stderr, "ERROR: malformed data", data.strip()
-    continue
-  hostname = gethostfromlogin(user, password)
-  if (not hostname):
-    print >> sys.stderr, "ERROR: username/password not correct"
-    continue
-  if (int(revision) == 0):
-    print >> sys.stderr, "ERROR: revision number cannot be 0"
-    continue
-  print 'Host:', hostname
-  print 'RevN:', revision
-  print 'Name:', dataname
-  print 'Data:', result
-  hostname = DATADIR+hostname
-  if (not check_dir(hostname)):
-    continue
-
-  dataname = dataname.replace('/', '-SLASH-');
-  try:
-      datafile = open(hostname + '/' + dataname, "r+")
-  except IOError:
-      datafile = open(hostname + '/' + dataname, "w+")
-  add_data_to_file(datafile, revision, result);
-  datafile.close()
-  revision = int(revision);
-  if(revision > xrange_max or revision < xrange_min):
-    print "Range change:", xrange_max, xrange_min,
-    xrange_max = max(xrange_max, revision);
-    xrange_min = min(xrange_min, revision);
-    print " -->> ", xrange_max, xrange_min
-    f = open(DATADIR+"global_range.dat", "w");
-    f.write("%d %d" % (xrange_min, xrange_max));
-    f.close();

Modified: gauger/install.sh
===================================================================
--- gauger/install.sh   2011-05-19 22:17:12 UTC (rev 15267)
+++ gauger/install.sh   2011-05-20 01:59:12 UTC (rev 15268)
@@ -1,16 +1,15 @@
 #!/bin/sh
 
+if [ "$(whoami)" != "root" ]; then
+    echo "Please consider running this script as root if you intend to install"
+    echo "gauger system-wide."
+fi
+
 echo $@ | grep "\-\-client" > /dev/null
 CLIENT=$?
 echo $@ | grep "\-\-server" > /dev/null
 SERVER=$?
 
-echo 
"*********************************************************************************"
-echo "*** This script checks your system to detect potential installation 
problems. ***"
-echo "*** It does not perform the actual installation, the README file 
explains the ***"
-echo "*** installation procedure, under the 'Installation' section.            
     ***"
-echo 
"*********************************************************************************"
-
 if [ "$CLIENT" = "1" -a "$SERVER" = "1" ]; then
     echo "Please indicate if you want to perfom install checks"
     echo "for the client (--client) or the server (--server)."
@@ -18,56 +17,73 @@
     exit 1
 fi
 
+
+if [ "$CLIENT" = "0" ]; then
+
 # ################ PYTHON ################ #
 
-V=$(/usr/bin/env python --version 2>&1)
-if [ "$?" != "0" ]; then
-    echo "Please make sure python is installed."
-    echo "Unless you are installing only the PHP server part,"
-    echo "Python is needed for both server and client."
-fi
-V=${V#* }
-MSD=${V%%.*}
-case $MSD in
-    2)
-       echo "Default python version: 2"
-       echo "Nothing to change..."
-       ;;
-    3)
-       echo "Default python version: 3"
-       echo "Trying version 2..."
-       V=$(/usr/bin/env python2 --version 2>&1)
-       if [ "$?" != "0" ]; then
-           echo "Please make sure python v2 is installed"
-           echo "Consult README for more information"
+    V=$(/usr/bin/env python --version 2>&1)
+    if [ "$?" != "0" ]; then
+       echo "Please make sure python is installed."
+       echo "Python is needed for the gauger client."
+    exit 1
+    fi
+    V=${V#* }
+    MSD=${V%%.*}
+    case $MSD in
+       2)
+           echo "Default python version: 2"
+           echo "Nothing to change..."
+           ;;
+       3)
+           echo "Default python version: 3"
+           echo "Trying version 2..."
+           V=$(/usr/bin/env python2 --version 2>&1)
+           if [ "$?" != "0" ]; then
+               echo "Please make sure python v2 is installed"
+               echo "Consult README for more information"
            echo "and adapt scripts accordingly."
            exit 1
-       fi
-       V=${V##* }
-       MSD=${V%%.*}
-       if [ "$MSD" != "2" ]; then
-           echo "Executlabe python2 is NOT python 2!!"
-           echo "Consult README for more information"
-           echo "and adapt scripts accordingly."
-           exit 1
-       fi
-       for i in *.py; do
-           echo "Adapting $i..."
-           sed -e "s/#!\/usr\/bin\/env python$/#!\/usr\/bin\/env python2/" $i 
> $i.tmp
-           mv $i.tmp $i
-       done
-       echo "Done!!"
-       ;;
-    *)
-       echo "Unknown version of python $MSD."
+           fi
+           V=${V##* }
+           MSD=${V%%.*}
+           if [ "$MSD" != "2" ]; then
+               echo "Executlabe python2 is NOT python 2!!"
+               echo "Consult README for more information"
+               echo "and adapt scripts accordingly."
+               exit 1
+           fi
+           sed -e "s/#!\/usr\/bin\/env python$/#!\/usr\/bin\/env python2/" 
gauger-cli.py > gauger-cli.tmp
+           mv gauger-cli.tmp gauger-cli.py
+           echo "Done!!"
+           ;;
+       *)
+           echo "Unknown version of python $MSD."
        echo "*** PROGRAM MIGHT NOT WORK ***"
        echo "Consult README file."
-esac
+    esac
 
+# ################ CLIENT INSTALL ################ #
+
+    echo "Please input route where to install the main gauger python script"
+    echo "  default [/usr/local/bin]"
+    read CLIENTPATH
+    if [ "$CLIENTPATH" = "" ]; then
+       CLIENTPATH="/usr/local/bin/"
+    fi
+    if [ ! -d "$CLIENTPATH" ]; then
+       mkdir -p "$CLIENTPATH"
+    fi
+    cp "gauger-cli.py" "$CLIENTPATH"
+
+fi # CLIENT PART
+
+
+
 if [ "$SERVER" = "0" ]; then
-
+    
 # ################ GNUPLOT ################ #
-
+    
     V=$(gnuplot --version 2>&1)
     if [ "$?" != "0" ]; then
        echo "Gnuplot not detected. Since you are installing the gauger server,"
@@ -80,12 +96,12 @@
            echo "Version of gnuplot is OK."
            ;;
        *)
-            echo "Untested version of gnuplot $MSD. Plotting *might* not work."
-            echo "Since you are insalling a server, try to update Gnuplot."
+           echo "Untested version of gnuplot $MSD. Plotting *might* not work."
+           echo "Since you are insalling a server, try to update Gnuplot."
     esac
-
+    
 # ################ PHP ################ #
-
+       
     V=$(php --version 2>&1 | head -n 1)
     if [ "$?" != "0" ]; then
        echo "Please make sure PHP is installed."
@@ -98,8 +114,18 @@
            echo "Version of PHP is OK."
            ;;
        *)
-            echo "Untested version of PHP $MSD."
-            echo "Dynamic page generation *might* not work."
+           echo "Untested version of PHP $MSD."
+           echo "Server *might* not work."
     esac
 
-fi #Server part
\ No newline at end of file
+# ################ SERVER INSTALL ################ #
+
+    echo "Please input route where to install the gauger server PHP scripts"
+    echo "  default [/usr/share/gauger]"
+    read CLIENTPATH
+    if [ "$CLIENTPATH" = "" ]; then
+        CLIENTPATH="/usr/local/bin/"
+    fi
+    cp "gauger-cli.py" "$CLIENTPATH"
+    
+fi #Server part

Modified: gauger/web/hosts
===================================================================
--- gauger/web/hosts    2011-05-19 22:17:12 UTC (rev 15267)
+++ gauger/web/hosts    2011-05-20 01:59:12 UTC (rev 15268)
@@ -22,7 +22,14 @@
             echo "user/pass not correct";
             die();
         }
-        add_data_to_host($_POST['host'], $_POST['name'], $_POST['revision'], 
$_POST['value']);
+        $res = add_data_to_host($_POST['host'], $_POST['name'], 
$_POST['revision'], $_POST['value']);
+        if($res === true) {
+            header('HTTP/1.1 201 Created');
+            die(url("hosts/".$_POST['host']."/".$_POST['name']));
+        } else {
+            header('HTTP/1.1 500 Internal Server Error');
+            die($res);
+        }
         break;
     case 'PUT':
     case 'DELETE':

Modified: gauger/web/io.php
===================================================================
--- gauger/web/io.php   2011-05-19 22:17:12 UTC (rev 15267)
+++ gauger/web/io.php   2011-05-20 01:59:12 UTC (rev 15268)
@@ -444,15 +444,13 @@
     check_permissions($datadir, 'file');
     check_permissions("$datadir.dat", 'file');
     if(false === ($pos = add_data_to_file($datadir, $rev, $value))) {
-        header('HTTP/1.1 500 Internal Server Error');
-        die("cannot add data to $datadir");
+        return "cannot add data to $datadir";
     }
     $data = recalculate_data($datadir, $rev, $pos);
     $res = write_data_to_summary($datadir, $rev, $data);
     if ($res === false) {
-        header('HTTP/1.1 500 Internal Server Error');
-        die("cannot add data to $datadir.dat");
+        return "cannot add data to $datadir.dat";
     }
     add_range_global($rev);
-    die("OK");
+    return true;
 }

Modified: gauger/web/postme.html
===================================================================
--- gauger/web/postme.html      2011-05-19 22:17:12 UTC (rev 15267)
+++ gauger/web/postme.html      2011-05-20 01:59:12 UTC (rev 15268)
@@ -1,5 +1,6 @@
 <html>
 <head>
+<script type="text/javascript" 
src="http://ranger/gauger/bindings/js/gauger.js";></script>
 <title>Test</title>
 </head>
 <body>
@@ -11,6 +12,7 @@
 <input name="value" value="100" /><br/>
 <input name="revision" value="15000" /><br/>
 <input type="submit" value="go" />
+<input type="button" value="gauger" 
onclick="GAUGER('http://ranger/gauger/web/', 'testuser', '123456', 'testhost', 
'CAT', 'name', 'unit', 100, 1000)"/>
 </form>
 </body>
 </html>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]