~ubuntu-branches/ubuntu/trusty/autokey/trusty

« back to all changes in this revision

Viewing changes to src/lib/scripting.py

  • Committer: Bazaar Package Importer
  • Author(s): Luke Faraone
  • Date: 2010-04-05 08:38:03 UTC
  • mfrom: (8.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100405083803-213ntib1b3208oq0
Tags: 0.61.7-2
Fix dependency substitution for Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
291
291
    Simplified access to some system commands.
292
292
    """    
293
293
    
294
 
    def exec_command(self, command):
 
294
    def exec_command(self, command, getOutput=True):
295
295
        """
296
296
        Execute a shell command
 
297
 
 
298
        Set getOutput to False if the command does not exit and return immediately. Otherwise
 
299
        AutoKey will not respond to any hotkeys/abbreviations etc until the process started
 
300
        by the command exits.
297
301
        
298
 
        Usage: C{system.exec_command(command)}
 
302
        Usage: C{system.exec_command(command, getOutput=True)}
299
303
        
300
304
        @param command: command to be executed (including any arguments) - e.g. "ls -l"
 
305
        @param getOutput: whether to capture the (stdout) output of the command
301
306
        @raises subprocess.CalledProcessError: if the command returns a non-zero exit code
302
307
        """
303
 
        p = subprocess.Popen(command, shell=True, bufsize=-1, stdout=subprocess.PIPE)
304
 
        retCode = p.wait()
305
 
        output = p.stdout.read()[:-1]
306
 
        if retCode != 0:
307
 
            raise subprocess.CalledProcessError(retCode, output)
 
308
        if getOutput:
 
309
            p = subprocess.Popen(command, shell=True, bufsize=-1, stdout=subprocess.PIPE)
 
310
            retCode = p.wait()
 
311
            output = p.stdout.read()[:-1]
 
312
            if retCode != 0:
 
313
                raise subprocess.CalledProcessError(retCode, output)
 
314
            else:
 
315
                return output
308
316
        else:
309
 
            return output
 
317
            subprocess.Popen(command, shell=True, bufsize=-1)
310
318
    
311
319
    def create_file(self, fileName, contents=""):
312
320
        """