commit-gnue
[Top][All Lists]
Advanced

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

gnue-dbtools/src/sql Client.py commands/__init_...


From: Jason Cater
Subject: gnue-dbtools/src/sql Client.py commands/__init_...
Date: Fri, 26 Sep 2003 00:28:40 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue-dbtools
Branch:         
Changes by:     Jason Cater <address@hidden>    03/09/26 00:28:40

Modified files:
        src/sql        : Client.py 
        src/sql/commands: __init__.py call.py clear.py edit.py exit.py 
                          get.py help.py quit.py save.py 
Added files:
        src/sql/commands: list.py 

Log message:
        added bunches of commands, plus readline support

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/Client.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/list.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/__init__.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/call.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/clear.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/edit.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/exit.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/get.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/help.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/quit.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-dbtools/src/sql/commands/save.py.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnue-dbtools/src/sql/Client.py
diff -c gnue-dbtools/src/sql/Client.py:1.2 gnue-dbtools/src/sql/Client.py:1.3
*** gnue-dbtools/src/sql/Client.py:1.2  Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/Client.py      Fri Sep 26 00:28:39 2003
***************
*** 35,40 ****
--- 35,45 ----
  from gnue.common.datasources import GDataObjects, GConnections
  from gnue.common import events
  
+ from gnue.dbtools import VERSION
+ from Instance import Instance
+ #from gnue.dbtools.sql.Config import ConfigOptions
+ ConfigOptions = {}
+ 
  
  class SQLClient(GClientApp, events.EventAware):
    #
***************
*** 66,72 ****
        scriptname=self.ARGUMENTS[0]
        if scriptname in ('-','--'):
          scriptname=""
!       arguments =self.ARGUMENTS[1:]
      except IndexError:
        scriptname = ""
        arguments=self.ARGUMENTS[:]
--- 71,77 ----
        scriptname=self.ARGUMENTS[0]
        if scriptname in ('-','--'):
          scriptname=""
!       arguments = self.ARGUMENTS[1:]
      except IndexError:
        scriptname = ""
        arguments=self.ARGUMENTS[:]
***************
*** 77,84 ****
      userParameters = self.getCommandLineParameters(arguments)
  
  
!     self.instance = Instance(scriptname, userParameters)
! 
  
  
  if __name__ == '__main__':
--- 82,88 ----
      userParameters = self.getCommandLineParameters(arguments)
  
  
!     self.instance = Instance(scriptname, userParameters, self.OPTIONS)
  
  
  if __name__ == '__main__':
Index: gnue-dbtools/src/sql/commands/__init__.py
diff -c gnue-dbtools/src/sql/commands/__init__.py:1.1 
gnue-dbtools/src/sql/commands/__init__.py:1.2
*** gnue-dbtools/src/sql/commands/__init__.py:1.1       Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/__init__.py   Fri Sep 26 00:28:40 2003
***************
*** 0 ****
--- 1,59 ----
+ #
+ # This file is part of GNU Enterprise.
+ #
+ # GNU Enterprise is free software; you can redistribute it
+ # and/or modify it under the terms of the GNU General Public
+ # License as published by the Free Software Foundation; either
+ # version 2, or (at your option) any later version.
+ #
+ # GNU Enterprise 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 General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public
+ # License along with program; see the file COPYING. If not,
+ # write to the Free Software Foundation, Inc., 59 Temple Place
+ # - Suite 330, Boston, MA 02111-1307, USA.
+ #
+ # Copyright 2003 Free Software Foundation
+ #
+ # FILE:
+ # commands/__init__.py
+ #
+ # DESCRIPTION:
+ #
+ # NOTES:
+ #
+ 
+ from gnue.common.utils.FileUtils import dyn_import as _import
+ 
+ from Base import CommandError
+ 
+ all = (
+  'call',
+  'clear',
+  'command',
+  'comment',
+  'commit',
+  'edit',
+  'exit',
+  'get',
+  'heading',
+  'help',
+  'input',
+  'list', 
+  'option',
+  'print',
+  'quit',
+  'rollback',
+  'save',
+  'spool',
+ )
+ 
+ 
+ def initCommands(instance):
+   commands = {}
+   for comm in all:
+     commands[comm] = _import("gnue.dbtools.sql.commands.%s" % 
comm).Command(instance)
+   return commands
Index: gnue-dbtools/src/sql/commands/call.py
diff -c gnue-dbtools/src/sql/commands/call.py:1.1 
gnue-dbtools/src/sql/commands/call.py:1.2
*** gnue-dbtools/src/sql/commands/call.py:1.1   Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/call.py       Fri Sep 26 00:28:40 2003
***************
*** 27,36 ****
  # NOTES:
  #
  
! from Base import BaseCommand
  
  class Command(BaseCommand):
    def call(self, args):
!     if len(args) != 1:
!       raise CommandError, _("call requires a filename to be passed")
      self.instance.processFile(args[0])
--- 27,37 ----
  # NOTES:
  #
  
! from Base import BaseCommand, CommandError
  
  class Command(BaseCommand):
+   SHORT = "Runs another GNUe SQL script file"
    def call(self, args):
!     if not len(args):
!       raise CommandError, _("CALL requires a filename to be passed as its 
first argument")
      self.instance.processFile(args[0])
Index: gnue-dbtools/src/sql/commands/clear.py
diff -c gnue-dbtools/src/sql/commands/clear.py:1.1 
gnue-dbtools/src/sql/commands/clear.py:1.2
*** gnue-dbtools/src/sql/commands/clear.py:1.1  Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/clear.py      Fri Sep 26 00:28:40 2003
***************
*** 30,34 ****
--- 30,35 ----
  from Base import BaseCommand
  
  class Command(BaseCommand):
+   SHORT = "Clears the screen"
    def call(self, args):
      pass
Index: gnue-dbtools/src/sql/commands/edit.py
diff -c gnue-dbtools/src/sql/commands/edit.py:1.1 
gnue-dbtools/src/sql/commands/edit.py:1.2
*** gnue-dbtools/src/sql/commands/edit.py:1.1   Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/edit.py       Fri Sep 26 00:28:40 2003
***************
*** 29,35 ****
  #
  
  from Base import BaseCommand
  
  class Command(BaseCommand):
    def call(self, args):
!     pass
--- 29,58 ----
  #
  
  from Base import BaseCommand
+ import tempfile, os, sys, string
  
  class Command(BaseCommand):
+   SHORT = "Opens the current buffer in an external editor"
    def call(self, args):
!     file = tempfile.mktemp()
! 
!     f = open(file,"w")
!     f.writelines(self.instance.lastbuffer)
!     f.close()
! 
!     if len(args):
!       command = string.join(args)
!     elif os.environ.has_key('EDITOR'):
!       command = os.environ['EDITOR']
!     else:
!       command = 'vi'
! 
!     os.system('%s "%s"' % (command, file))
! 
!     self.instance.commands['get'].call([file])
!     os.unlink(file)
!     return
! 
! 
! 
! 
Index: gnue-dbtools/src/sql/commands/exit.py
diff -c gnue-dbtools/src/sql/commands/exit.py:1.1 
gnue-dbtools/src/sql/commands/exit.py:1.2
*** gnue-dbtools/src/sql/commands/exit.py:1.1   Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/exit.py       Fri Sep 26 00:28:40 2003
***************
*** 30,34 ****
  from Base import BaseCommand
  
  class Command(BaseCommand):
    def call(self, args):
!     pass
--- 30,36 ----
  from Base import BaseCommand
  
  class Command(BaseCommand):
+   SHORT = "Exits GNUe SQL"
    def call(self, args):
!     if not self.instance.ignoreexit:
!       self.instance.loop = 0
Index: gnue-dbtools/src/sql/commands/get.py
diff -c gnue-dbtools/src/sql/commands/get.py:1.1 
gnue-dbtools/src/sql/commands/get.py:1.2
*** gnue-dbtools/src/sql/commands/get.py:1.1    Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/get.py        Fri Sep 26 00:28:40 2003
***************
*** 27,34 ****
  # NOTES:
  #
  
! from Base import BaseCommand
  
  class Command(BaseCommand):
    def call(self, args):
!     pass
--- 27,65 ----
  # NOTES:
  #
  
! from Base import BaseCommand, CommandError
! import os
  
  class Command(BaseCommand):
+   SHORT = "Loads a file into the current buffer"
    def call(self, args):
!     try:
!       file = args[0]
!     except:
!       raise CommandError,'GET requires a file name as its first argument'
! 
!     if not os.path.isfile(file):
!       file = file + '.sql'
!     try:
!       f = open(file)
!       lines = f.readlines()
!       f.close()
!     except (IOError, OSError), mesg:
!       raise CommandError,'Unable to open requested file:\n\n  %s' % mesg
! 
!     buff = []
! 
!     for line in lines:
!       line = line.rstrip()
!       if line[-1:] == ';' and line[-2:] != '\\;':
!         line = line[:-1]
!       if not len(line):
!         continue
!       buff.append(line)
! 
!     f.close()
! 
!     if buff:
!       self.instance.lastbuffer = buff
!       self.instance.commands['list'].call()
! 
Index: gnue-dbtools/src/sql/commands/help.py
diff -c gnue-dbtools/src/sql/commands/help.py:1.1 
gnue-dbtools/src/sql/commands/help.py:1.2
*** gnue-dbtools/src/sql/commands/help.py:1.1   Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/help.py       Fri Sep 26 00:28:40 2003
***************
*** 29,34 ****
  
  from Base import BaseCommand
  
  class Command(BaseCommand):
!   def call(self, args):
!     pass
--- 29,58 ----
  
  from Base import BaseCommand
  
+ import string
+ 
  class Command(BaseCommand):
!   SHORT = "Shows the help screen"
!   def call(self, args=()):
!     try:
!       command = args[0].lower()
!     except:
!       command = 'help'
! 
!     if command == 'commands':
!       lt = self.instance.commands.keys()
!       lt.sort()
!       mx = 0
!       for l in lt:
!         mx = max(mx, len(lt))
! 
!       print
!       print "Available commands:"
!       for l in lt:
!         print "  " + string.ljust(l + ': ', mx + 3), 
self.instance.commands[l].SHORT
!       print
! 
!     else:
!       print
!       print "Sorry, no help currently available :("
!       print
Index: gnue-dbtools/src/sql/commands/quit.py
diff -c gnue-dbtools/src/sql/commands/quit.py:1.1 
gnue-dbtools/src/sql/commands/quit.py:1.2
*** gnue-dbtools/src/sql/commands/quit.py:1.1   Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/quit.py       Fri Sep 26 00:28:40 2003
***************
*** 27,34 ****
  # NOTES:
  #
  
! from Base import BaseCommand
! 
! class Command(BaseCommand):
!   def call(self, args):
!     pass
--- 27,30 ----
  # NOTES:
  #
  
! from exit import Command
Index: gnue-dbtools/src/sql/commands/save.py
diff -c gnue-dbtools/src/sql/commands/save.py:1.1 
gnue-dbtools/src/sql/commands/save.py:1.2
*** gnue-dbtools/src/sql/commands/save.py:1.1   Fri Sep 19 17:51:48 2003
--- gnue-dbtools/src/sql/commands/save.py       Fri Sep 26 00:28:40 2003
***************
*** 28,35 ****
  # NOTES:
  #
  
! from Base import BaseCommand
  
  class Command(BaseCommand):
    def call(self, args):
!     pass
--- 28,51 ----
  # NOTES:
  #
  
! from Base import BaseCommand, CommandError
  
  class Command(BaseCommand):
+   SHORT = "Saves your current buffer to a file"
    def call(self, args):
!     try:
!       file = args[0]
!     except:
!       raise CommandError,'SAVE requires a file name as its first argument'
! 
!     if '.' not in file[:]:
!       file = file + '.sql'
!     try:
!       f = open(file, 'w')
!       f.writelines(self.instance.lastbuffer)
!       f.close()
!     except (IOError, OSError), mesg:
!       raise CommandError,'Unable to open requested file:\n\n  %s' % mesg
!     return "Buffer written to %s" % file
! 
! 




reply via email to

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