commit-gnue
[Top][All Lists]
Advanced

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

gnue/appserver/src frontend.py


From: Reinhard Mueller
Subject: gnue/appserver/src frontend.py
Date: Sat, 28 Dec 2002 10:47:20 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Reinhard Mueller <address@hidden>       02/12/28 10:47:20

Modified files:
        appserver/src  : frontend.py 

Log message:
        Added menu so that more functions can be added.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/appserver/src/frontend.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: gnue/appserver/src/frontend.py
diff -c gnue/appserver/src/frontend.py:1.2 gnue/appserver/src/frontend.py:1.3
*** gnue/appserver/src/frontend.py:1.2  Sat Dec 28 08:31:29 2002
--- gnue/appserver/src/frontend.py      Sat Dec 28 10:47:20 2002
***************
*** 19,25 ****
  # write to the Free Software Foundation, Inc., 59 Temple Place 
  # - Suite 330, Boston, MA 02111-1307, USA.
  #
! # $Id: frontend.py,v 1.2 2002/12/28 13:31:29 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.3 2002/12/28 15:47:20 reinhard Exp $
  
  import os, getpass
  from gnue.common import GClientApp
***************
*** 56,138 ****
  
  class application (GClientApp.GClientApp):
      
    # 
---------------------------------------------------------------------------
    # Display objects
    # 
---------------------------------------------------------------------------
  
!   def display (self, server, session, list, propertylist):
      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 = server.count (session, list) - start
  
      count = askint ("Number of objects to display", "%d" % maxcount)
!     rset = server.fetch (session, list, start, count)
  
      for index in range (0, count):
        object = rset [index]
        print "* Object number %d with id %s:" % (start+index, object["_id_"])
!       for property in propertylist:
          print "*   " + property + ":", object [property]
  
    # 
---------------------------------------------------------------------------
!   # Main loop
    # 
---------------------------------------------------------------------------
  
!   def run (self):
!     # create session manager object representing the server
!     server = geasSessionManager.geasSessionManager ()
  
!     # this should (IMHO) happen in geasSessionManager -- reinhard
!     self.connections.setLoginHandler (geasLoginHandler ())
!     server.setConnections (self.connections)
!     server.setDatabase ("gnue")
  
      # open a session
      # user = ask ("Username", getpass.getuser ())
      # password = getpass.getpass ("? Password: ")
      user = ask ("Username", "hacker")
      password = ask ("Password", "secret")
!     session = server.open ({"user": user, "password": password})
! 
!     # select the class to operate upon
!     classname = raw_input ("? Classname (empty to exit): ")
!     while classname:
!       # select the properties to fetch
!       propertylist = []
!       while 1:
!         property = raw_input ("? Property to read: ")
!         if property:
!           break
!         print "! Please enter at least one property"
!       while property:
!         propertylist.append (property)
!         property = raw_input ("? Property to read (empty to finish): ")
! 
!       # TODO: define filter
! 
!       # select the properties to sort by
!       sortlist = []
!       sort = ask ("Sort key", propertylist [0])
!       while sort:
!         sortlist.append (sort)
!         sort = raw_input ("? Further sort key (empty to finish): ")
! 
!       # request the list
!       list = server.requestList (session, classname, [], sortlist, 
propertylist)
! 
!       count = server.count (session, list)
!       print "* The requested list contains %d entries" % count
  
!       self.display (server, session, list, propertylist)
  
!       # select another class
!       classname = raw_input ("? Classname (empty to exit): ")
  
!     server.close (session, None)
  
      print "Thank you for playing!"
  
--- 56,188 ----
  
  class application (GClientApp.GClientApp):
      
+   def __init__ (self):
+     GClientApp.GClientApp.__init__ (self)
+ 
+     # create session manager object representing the server
+     self.server = geasSessionManager.geasSessionManager ()
+ 
+     # this should (IMHO) happen in geasSessionManager -- reinhard
+     self.connections.setLoginHandler (geasLoginHandler ())
+     self.server.setConnections (self.connections)
+     self.server.setDatabase ("gnue")
+ 
+     # the current session_id
+     self.session = None
+ 
+     # the current list_id
+     self.list = None
+ 
+     # the parameters that were used to build the list
+     self.classname = None
+     self.propertylist = None
+ 
+   # 
---------------------------------------------------------------------------
+   # Main menu
+   # 
---------------------------------------------------------------------------
+ 
+   def menu (self):
+     print
+     print "* The current list is of class %s and contains %d objects" \
+           % (self.classname, self.server.count (self.session, self.list))
+     print
+     print "  1 - Display objects"
+     print "  8 - Request another list"
+     print "  9 - Exit"
+     print
+ 
+     while 1:
+       choice = askint ("Your choice", "1")
+ 
+       if choice == 1:
+         return self.display
+       elif choice == 8:
+         return self.request
+       elif choice == 9:
+         return None
+ 
    # 
---------------------------------------------------------------------------
    # Display objects
    # 
---------------------------------------------------------------------------
  
!   def display (self):
      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 display", "%d" % maxcount)
!     rset = self.server.fetch (self.session, self.list, start, count)
  
      for index in range (0, count):
        object = rset [index]
        print "* Object number %d with id %s:" % (start+index, object["_id_"])
!       for property in self.propertylist:
          print "*   " + property + ":", object [property]
  
    # 
---------------------------------------------------------------------------
!   # Request a list of objects
    # 
---------------------------------------------------------------------------
  
!   def request (self):
!     # select the class to operate upon
!     if self.classname:
!       self.classname = ask ("Classname", self.classname)
!     else:
!       while 1:
!         self.classname = raw_input ("? Classname: ")
!         if self.classname:
!           break
!         print "! Please enter a classname"
  
!     # select the properties to fetch
!     self.propertylist = []
!     while 1:
!       property = raw_input ("? Property to read: ")
!       if property:
!         break
!       print "! Please enter at least one property"
! 
!     while property:
!       self.propertylist.append (property)
!       property = raw_input ("? Property to read (empty to finish): ")
! 
!     print "propertylist", self.propertylist
!     # TODO: define filter
! 
!     # select the properties to sort by
!     sortlist = []
!     sort = ask ("Sort key", self.propertylist [0])
!     while sort:
!       sortlist.append (sort)
!       sort = raw_input ("? Further sort key (empty to finish): ")
! 
!     # request the list
!     self.list = self.server.requestList (self.session, self.classname, [], \
!                                          sortlist, self.propertylist)
  
+   # 
---------------------------------------------------------------------------
+   # Main loop
+   # 
---------------------------------------------------------------------------
+ 
+   def run (self):
      # open a session
      # user = ask ("Username", getpass.getuser ())
      # password = getpass.getpass ("? Password: ")
      user = ask ("Username", "hacker")
      password = ask ("Password", "secret")
!     self.session = self.server.open ({"user": user, "password": password})
  
!     action = self.request
  
!     while action:
!       action ()
!       action = self.menu ()
  
!     self.server.close (self.session, None)
  
      print "Thank you for playing!"
  



reply via email to

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