Shell:
authorMichael 'Mickey' Lauer <mickey@vanille-media.de>
Wed, 6 Jul 2005 18:24:16 +0000 (18:24 +0000)
committerMichael 'Mickey' Lauer <mickey@vanille-media.de>
Wed, 6 Jul 2005 18:24:16 +0000 (18:24 +0000)
- use shlex to parse command lines as a special service to hrw: Now you can say 'setvar FOO "this is a test"' :)
- use a command queue in the main loop to unify offline (from startup file) and online processing
- add some changes for 1.3.2. Could anyone fill in changes for 1.3.1 ?

ChangeLog
lib/bb/shell.py

index 921be23..7fdb698 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-Changes in bitbake 1.3.0:
+Changes in BitBake 1.3.2:
+       - reintegration of make.py into BitBake
+       - bbread is gone, use bitbake -e
+       - lots of shell updates and bugfixes
+
+Changes in BitBake 1.3.0:
        - add bitbake interactive shell (bitbake -i)
        - refactor bitbake utility in OO style
        - kill default arguments in methods in the bb.data module
@@ -14,13 +19,13 @@ Changes in bitbake 1.3.0:
          each data instance in memory when using a cache/persistent
          storage
 
-Changes in bitbake 1.2.1:
+Changes in BitBake 1.2.1:
        The 1.2.1 release is meant as a intermediate release to lay the
-ground for more radical changes. The most notable changes are:
+       ground for more radical changes. The most notable changes are:
 
-       -Do not hardcode {}, use bb.data.init() instead if you want to
-get a instance of a data class
-       -bb.data.init() is a factory and the old bb.data methods are delegates
-       -Do not use deepcopy use bb.data.createCopy() instead.
-       -Removed default arguments in bb.fetch
+       - Do not hardcode {}, use bb.data.init() instead if you want to
+         get a instance of a data class
+       - bb.data.init() is a factory and the old bb.data methods are delegates
+       - Do not use deepcopy use bb.data.createCopy() instead.
+       - Removed default arguments in bb.fetch
 
index 9a6c66f..13bf9f0 100644 (file)
@@ -30,14 +30,11 @@ IDEAS:
     * automatic check if reparsing is necessary (inotify?)
     * frontend for bb file manipulation
     * more shell-like features:
-        - shell lexer (shlex)
         - output control, i.e. pipe output into grep, sort, etc.
         - job control, i.e. bring running commands into background and foreground
         - wildcards for commands, i.e. build *opie*
     * start parsing in background right after startup
-    * print variable from package data
     * ncurses interface
-    * read some initial commands from startup file (batch)
 
 PROBLEMS:
     * force doesn't always work
@@ -53,11 +50,11 @@ try:
     set
 except NameError:
     from sets import Set as set
-import sys, os, imp, readline, socket, httplib, urllib, commands, popen2, copy
+import sys, os, imp, readline, socket, httplib, urllib, commands, popen2, copy, shlex, Queue
 imp.load_source( "bitbake", os.path.dirname( sys.argv[0] )+"/bitbake" )
 from bb import data, parse, build, fatal
 
-__version__ = "0.5.1"
+__version__ = "0.5.2"
 __credits__ = """BitBake Shell Version %s (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
 Type 'help' for more information, press CTRL-D to exit.""" % __version__
 
@@ -639,6 +636,7 @@ class BitBakeShell:
 
     def __init__( self ):
         """Register commands and set up readline"""
+        self.commandQ = Queue.Queue()
         self.commands = BitBakeShellCommands( self )
         self.myout = MemoryOutput( sys.stdout )
         self.historyfilename = os.path.expanduser( "~/.bbsh_history" )
@@ -693,33 +691,25 @@ class BitBakeShell:
         """Read and execute all commands found in $HOME/.bbsh_startup"""
         if os.path.exists( self.startupfilename ):
             startupfile = open( self.startupfilename, "r" )
-            # save_stdout = sys.stdout
-            # sys.stdout = open( "/dev/null", "w" )
-            numCommands = 0
-            for cmdline in startupfile.readlines():
-                cmdline = cmdline.strip()
+            for cmdline in startupfile:
                 debugOut( "processing startup line '%s'" % cmdline )
                 if not cmdline:
                     continue
                 if "|" in cmdline:
-                    print >>save_stdout, "ERROR: ';' in startup file is not allowed. Ignoring line"
+                    print "ERROR: '|' in startup file is not allowed. Ignoring line"
                     continue
-                allCommands = cmdline.split( ';' )
-                for command in allCommands:
-                    if ' ' in command:
-                        self.processCommand( command.split()[0], command.split()[1:] )
-                    else:
-                        self.processCommand( command, "" )
-                    numCommands += 1
-            print "SHELL: Processed %d commands from '%s'" % ( numCommands, self.startupfilename )
+                self.commandQ.put( cmdline.strip() )
 
     def main( self ):
         """The main command loop"""
         while not leave_mainloop:
             try:
-                sys.stdout = self.myout.delegate
-                cmdline = raw_input( "BB>> " )
-                sys.stdout = self.myout
+                if self.commandQ.empty():
+                    sys.stdout = self.myout.delegate
+                    cmdline = raw_input( "BB>> " )
+                    sys.stdout = self.myout
+                else:
+                    cmdline = self.commandQ.get()
                 if cmdline:
                     allCommands = cmdline.split( ';' )
                     for command in allCommands:
@@ -736,10 +726,8 @@ class BitBakeShell:
                                 command, pipecmd = command.split( '|' )
                                 delegate = self.myout.delegate
                                 self.myout.delegate = None
-                            if ' ' in command:
-                                self.processCommand( command.split()[0], command.split()[1:] )
-                            else:
-                                self.processCommand( command, "" )
+                            tokens = shlex.split( command, True )
+                            self.processCommand( tokens[0], tokens[1:] or "" )
                             self.myout.endCommand()
                             if pipecmd is not None: # restore output
                                 self.myout.delegate = delegate