Update of /cvsroot/freevo/kaa/base/src/notifier
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9534

Modified Files:
        popen.py 
Log Message:
Add start() method to Process -- process no longer gets automatically
started in constructor, it must be started explicitly.  The start()
method can take a list or string of parameters to get appended on the
command line.  Command lines passed as strings now get converted to a 
list of parameters (quoting is honored).  "completed" signal callbacks
are passed the exit code of the process.


Index: popen.py
===================================================================
RCS file: /cvsroot/freevo/kaa/base/src/notifier/popen.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** popen.py    5 Aug 2005 18:21:25 -0000       1.9
--- popen.py    5 Aug 2005 20:16:33 -0000       1.10
***************
*** 67,73 ****
      Base class for started child processes
      """
!     def __init__( self, app, debugname = None ):
          """
!         Init the child process 'app'. This can either be a string or a list
          of arguments (similar to popen2). If debugname is given, the stdout
          and stderr will also be written.
--- 67,73 ----
      Base class for started child processes
      """
!     def __init__( self, cmd, debugname = None ):
          """
!         Init the child process 'cmd'. This can either be a string or a list
          of arguments (similar to popen2). If debugname is given, the stdout
          and stderr will also be written.
***************
*** 82,104 ****
          }
  
!         if isinstance(app, str):
!             # app is a string to execute. It will be executed by 'sh -c '
!             # inside the popen code
!             self.binary = app.lstrip()
  
!             start_str = app
!         else:
!             # app is a list
!             while '' in app:
!                 app.remove( '' )
  
!             self.binary = str( ' ' ).join( app )
!             start_str = app
  
          self.__kill_timer = None
!         self.stopping = False
!         self.__dead = False
  
!         self.child = popen2.Popen3( start_str, True, 100 )
  
          log.info('running %s (pid=%s)' % ( self.binary, self.child.pid ) )
--- 82,145 ----
          }
  
!         self._cmd = self._normalize_cmd(cmd)
!         self._debugname = debugname
!         self.__dead = True
!         self.stopping = False
!         self.__kill_timer = None
  
!     def _normalize_cmd(self, cmd):
!         """
!         Converts a command string into a list while honoring quoting, or
!         removes empty strings if the cmd is a list.
!         """
!         if cmd == None:
!             return []
!         elif type(cmd) == list:
!             # Remove empty strings from argument list.
!             while '' in cmd:
!                 cmd.remove('')
!             return cmd
  
!         assert(type(cmd) == str)
! 
!         # This might be how you'd do it in C. :)
!         cmdlist = []
!         curarg = ""
!         waiting = None
!         last = None
!         for c in cmd:
!             if (c == ' ' and not waiting) or c == waiting:
!                 if curarg:
!                     cmdlist.append(curarg)
!                     curarg = ""
!                 waiting = None
!             elif c in ("'", '"') and not waiting and last != '\\':
!                 waiting = c
!             else:
!                 curarg += c
!             last = c
!     
!         if curarg:
!             cmdlist.append(curarg)
!     
!         return cmdlist
  
+ 
+     def start(self, args = None):
+         """
+         Starts the process.  If args is not None, it can be either a list or
+         string, as with the constructor, and is appended to the command line
+         specified in the constructor.
+         """
+         if not self.__dead:
+             raise SystemError, "Process is already running."
+         if self.stopping:
+             raise SystemError, "Process isn't done stopping yet."
+ 
+         cmd = self._cmd + self._normalize_cmd(args)
          self.__kill_timer = None
!         self.binary = cmd[0]
  
!         self.child = popen2.Popen3( cmd, True, 100 )
  
          log.info('running %s (pid=%s)' % ( self.binary, self.child.pid ) )
***************
*** 106,113 ****
          # IO_Handler for stdout
          self.stdout = IO_Handler( 'stdout', self.child.fromchild,
!                                   self.signals["stdout"].emit, debugname )
          # IO_Handler for stderr
          self.stderr = IO_Handler( 'stderr', self.child.childerr,
!                                   self.signals["stderr"].emit, debugname )
  
          # add child to watcher
--- 147,154 ----
          # IO_Handler for stdout
          self.stdout = IO_Handler( 'stdout', self.child.fromchild,
!                                   self.signals["stdout"].emit, 
self._debugname )
          # IO_Handler for stderr
          self.stderr = IO_Handler( 'stderr', self.child.childerr,
!                                   self.signals["stderr"].emit, 
self._debugname )
  
          # add child to watcher
***************
*** 167,170 ****
--- 208,212 ----
          if not self.is_alive():
              self.__dead = True
+             self.stopping = False
              return False
          # child needs some assistance with dying ...
***************
*** 189,192 ****
--- 231,235 ----
          if not self.is_alive():
              self.__dead = True
+             self.stopping = False
              return False
          # child needs some assistance with dying ...
***************
*** 227,235 ****
  
  
!     def __child_died( self ):
          """
          Callback from watcher when the child died.
          """
          self.__dead = True
          # close IO handler and kill timer
          self.stdout.close()
--- 270,279 ----
  
  
!     def __child_died( self, status ):
          """
          Callback from watcher when the child died.
          """
          self.__dead = True
+         self.stopping = False
          # close IO handler and kill timer
          self.stdout.close()
***************
*** 237,241 ****
          if self.__kill_timer:
              notifier.removeTimer( self.__kill_timer )
!         self.signals["completed"].emit()
  
  
--- 281,285 ----
          if self.__kill_timer:
              notifier.removeTimer( self.__kill_timer )
!         self.signals["completed"].emit(status >> 8)
  
  
***************
*** 366,371 ****
              if p in self.__processes:
                  # call stopped callback
!               self.__processes[ p ]()
!                 del self.__processes[ p ]
  
          # check if this function needs to be called again
--- 410,419 ----
              if p in self.__processes:
                  # call stopped callback
!                 callback = self.__processes[p]
!                 # Delete the callback from the processes list before calling
!                 # it, since it's possible the callback could call append 
!                 # again.
!                 del self.__processes[p]
!                 callback(status)
  
          # check if this function needs to be called again



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to