commit-gnue
[Top][All Lists]
Advanced

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

gnue/appserver/src frontend.py geasSession.py


From: Reinhard Mueller
Subject: gnue/appserver/src frontend.py geasSession.py
Date: Mon, 06 Jan 2003 11:43:15 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Reinhard Mueller <address@hidden>       03/01/06 11:43:15

Modified files:
        appserver/src  : frontend.py geasSession.py 

Log message:
        Implemented "store" function.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/frontend.py.diff?tr1=1.6&tr2=1.7&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/geasSession.py.diff?tr1=1.18&tr2=1.19&r1=text&r2=text

Patches:
Index: gnue/appserver/src/frontend.py
diff -c gnue/appserver/src/frontend.py:1.6 gnue/appserver/src/frontend.py:1.7
*** gnue/appserver/src/frontend.py:1.6  Sat Jan  4 11:30:38 2003
--- gnue/appserver/src/frontend.py      Mon Jan  6 11:43:15 2003
***************
*** 19,25 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: frontend.py,v 1.6 2003/01/04 16:30:38 reinhard Exp $
  
  import os, getpass
  from gnue.common import GClientApp
--- 19,25 ----
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: frontend.py,v 1.7 2003/01/06 16:43:15 reinhard Exp $
  
  import os, getpass
  from gnue.common import GClientApp
***************
*** 88,93 ****
--- 88,95 ----
      print
      print "  1 - Display objects"
      print "  2 - Display more data"
+     print "  3 - Modify objects"
+     print "  4 - Add object"
      print "  8 - Request another list"
      print "  9 - Exit"
      print
***************
*** 97,104 ****
  
        if choice == 1:
          return self.display
!       if choice == 2:
          return self.more
        elif choice == 8:
          return self.request
        elif choice == 9:
--- 99,110 ----
  
        if choice == 1:
          return self.display
!       elif choice == 2:
          return self.more
+       elif choice == 3:
+         return self.modify
+       elif choice == 4:
+         return self.add
        elif choice == 8:
          return self.request
        elif choice == 9:
***************
*** 170,175 ****
--- 176,263 ----
                                                  object_ids [index])
        for property in propertylist:
          print "*   " + property + ":", object [property]
+ 
+   # 
---------------------------------------------------------------------------
+   # Modify objects
+   # 
---------------------------------------------------------------------------
+ 
+   def modify (self):
+     # select the properties to modify
+     propertylist = []
+     while 1:
+       property = raw_input ("? Property to modify: ")
+       if property:
+         break
+       print "! Please enter at least one property"
+ 
+     while property:
+       propertylist.append (property)
+       property = raw_input ("? Property to modify (empty to finish): ")
+ 
+     # select objects to modify
+     start = askint ("Start with object number", "0")
+ 
+     # get maximum possible object count from given start position
+     if start < 0:                       # from end of list
+       maxcount = -start
+     else:
+       maxcount = self.server.count (self.session, self.list) - start
+ 
+     count = askint ("Number of objects to modify", "%d" % maxcount)
+ 
+     # First, get all object_ids
+     rset = self.server.fetch (self.session, self.list, start, count)
+     object_ids = []
+     for index in range (0, count):
+       object = rset [index]
+       object_ids.append (object ["_id_"])
+ 
+     # Now, we have all object_ids and we can use "load" to get the data.
+     # This is not necessary for the subsequent call of "store", it's just
+     # convenient for the user.
+     rset = self.server.load (self.session, self.classname, object_ids,
+                              propertylist)
+     data = []
+     for index in range (0, count):
+       object = rset [index]
+       print "* Object number %d with id %s:" % (start + index,
+                                                 object_ids [index])
+       row = []
+       for property in propertylist:
+         row.append (ask (property, object [property]))
+       data.append (row)
+ 
+     # Now, we have the new data in our 2-dimensional array and we can call
+     # the "store" function.
+     self.server.store (self.session, self.classname, object_ids, propertylist,
+                        data)
+     self.server.commit (self.session)
+ 
+   # 
---------------------------------------------------------------------------
+   # Add new object
+   # 
---------------------------------------------------------------------------
+ 
+   def add (self):
+     # select the properties to add
+     propertylist = []
+     while 1:
+       property = raw_input ("? Property to add: ")
+       if property:
+         break
+       print "! Please enter at least one property"
+ 
+     while property:
+       propertylist.append (property)
+       property = raw_input ("? Property to add (empty to finish): ")
+ 
+     row = []
+     for property in propertylist:
+       row.append (ask (property, ""))
+ 
+     # Now, we have the new data in "row" and we can call the "store" function.
+     self.server.store (self.session, self.classname, [None], propertylist,
+                        [row])
+     self.server.commit (self.session)
  
    # 
---------------------------------------------------------------------------
    # Request a list of objects
Index: gnue/appserver/src/geasSession.py
diff -c gnue/appserver/src/geasSession.py:1.18 
gnue/appserver/src/geasSession.py:1.19
*** gnue/appserver/src/geasSession.py:1.18      Sat Jan  4 11:53:50 2003
--- gnue/appserver/src/geasSession.py   Mon Jan  6 11:43:15 2003
***************
*** 19,29 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: geasSession.py,v 1.18 2003/01/04 16:53:50 reinhard Exp $
  
  import geasList
  import geasTrigger 
  import geasAuthentification
  
  # 
=============================================================================
  # Session class
--- 19,45 ----
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: geasSession.py,v 1.19 2003/01/06 16:43:15 reinhard Exp $
  
  import geasList
  import geasTrigger 
  import geasAuthentification
+ import whrandom
+ 
+ # 
=============================================================================
+ # Helper functions
+ # 
=============================================================================
+ 
+ # 
-----------------------------------------------------------------------------
+ # Generate a new object_id
+ # 
-----------------------------------------------------------------------------
+ 
+ def new_object_id ():
+   # FIXME: need a better algorithm here
+   result = ""
+   for i in range (0, 32):
+     result = result + str ( int (whrandom.random () * 10))
+   return result
  
  # 
=============================================================================
  # Session class
***************
*** 148,153 ****
--- 164,170 ----
    # 
---------------------------------------------------------------------------
  
    def request (self, classname, conditions, sortorder, propertylist):
+     # FIXME: this list needn't be considered by commit and rollback
      list = self.createList (classname)
      list_id = self._listcount
  
***************
*** 196,205 ****
          row [property] = object.get (property)
        result.append (row)
      return result
!         
!   def store(self,classname,obj_id_list,propertylist,data):
!     return self._getClass(classname).store(obj_id_list,propertylist,data)
!   
    def call(self,classname,obj_id_list,methodname,parameters):
      return self._getClass(classname).call(obj_id_list,methodname,parameters)
  
--- 213,260 ----
          row [property] = object.get (property)
        result.append (row)
      return result
! 
!   # 
---------------------------------------------------------------------------
!   # Store data in the database backend
!   # 
---------------------------------------------------------------------------
! 
!   def store (self, classname, obj_id_list, propertylist, data):
!     result = []
!     i = 0
!     for object_id in obj_id_list:
!       # FIXME: if we already have (in this session) a geasInstance that holds
!       # exactly this object, then we _must_ reuse it, or the existing
!       # geasInstance won't reflect our change!
! 
!       # FIXME: when new geasInstance is inserted, and we have (in this 
session)
!       # a geasList that this geasInstance would belong into, then insert it
!       # into that geasList.
! 
!       # We have to create a geasList for each object, because commit only
!       # operates on lists. We should change that. -- Reinhard
!       list = self.createList (classname)
!       # We need to "reference" all properties so they become updated. This
!       # also should be changed. -- Reinhard
!       list.setPrefetch (["_id_"] + propertylist)
!       list.setSort (["_id_"])
!       # Even for an empty object_id, we need to popluate the list.
!       list.setConditions ("= _id_ %s" % object_id)
!       list.populate ()
!       if object_id:
!         object = list.firstInstance ()
!         result.append (object_id)
!       else:
!         object = list.insertNewInstance ()
!         object.put ("_id_", new_object_id ())
!         result.append (object.get ("_id_"))
!       row = data [i]
!       j = 0
!       for property in propertylist:
!         object.put (property, row [j])
!         j += 1
!       i += 1
!     return result
! 
    def call(self,classname,obj_id_list,methodname,parameters):
      return self._getClass(classname).call(obj_id_list,methodname,parameters)
  




reply via email to

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