Merge pull request #4 from schoonc/typos-imports-pep8
fixed typos, imports; pep8
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#!/usr/bin/python2.7
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from Configuration import Configuration
|
||||
from Color import Color
|
||||
|
||||
from subprocess import Popen, call, PIPE
|
||||
import time
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from Color import Color
|
||||
from Configuration import Configuration
|
||||
|
||||
|
||||
class Process(object):
|
||||
''' Represents a running/ran process '''
|
||||
@@ -16,7 +17,7 @@ class Process(object):
|
||||
return open('/dev/null', 'w')
|
||||
|
||||
@staticmethod
|
||||
def call(command, cwd=None,shell=False):
|
||||
def call(command, cwd=None, shell=False):
|
||||
'''
|
||||
Calls a command (either string or list of args).
|
||||
Returns tuple:
|
||||
@@ -49,7 +50,7 @@ class Process(object):
|
||||
stdout = p.stdout().strip()
|
||||
stderr = p.stderr().strip()
|
||||
|
||||
if stdout == '' and err == '':
|
||||
if stdout == '' and stderr == '':
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -131,7 +132,7 @@ class Process(object):
|
||||
pid = self.pid.pid
|
||||
kill(pid, SIGINT)
|
||||
|
||||
wait_time = 0 # Time since Interrupt was sent
|
||||
wait_time = 0 # Time since Interrupt was sent
|
||||
while self.pid.poll() == None:
|
||||
# Process is still running
|
||||
wait_time += 0.1
|
||||
@@ -142,26 +143,27 @@ class Process(object):
|
||||
kill(pid, SIGTERM)
|
||||
self.pid.terminate()
|
||||
break
|
||||
|
||||
|
||||
except OSError, e:
|
||||
if 'No such process' in e.__str__():
|
||||
return
|
||||
raise e # process cannot be killed
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = Process('ls')
|
||||
print p.stdout(), p.stderr()
|
||||
p.interrupt()
|
||||
|
||||
# Calling as list of arguments
|
||||
(out,err) = Process.call(['ls', '-lah'])
|
||||
print out,err
|
||||
(out, err) = Process.call(['ls', '-lah'])
|
||||
print out, err
|
||||
|
||||
print '\n---------------------\n'
|
||||
|
||||
# Calling as string
|
||||
(out,err) = Process.call('ls -l | head -2')
|
||||
print out,err
|
||||
(out, err) = Process.call('ls -l | head -2')
|
||||
print out, err
|
||||
|
||||
print '"reaver" exists:', Process.exists('reaver')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user