本文整理汇总了Python中easyprocess.EasyProcess类的典型用法代码示例。如果您正苦于以下问题:Python EasyProcess类的具体用法?Python EasyProcess怎么用?Python EasyProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EasyProcess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getRainTicks
def getRainTicks():
global ticks
global temperature
os.system('rm -Rf '+json_rain_sensor)
time.sleep(0.5)
cmd = "rtl_433 -R 37 -E -F json:"+json_rain_sensor
try:
stdout=Proc(cmd).call(timeout=120).stdout
time.sleep(0.5)
with open(json_rain_sensor) as f:
data = json.loads(f.readline())
if "temperature_C" in data:
temperature = float(data["temperature_C"])
if "rain" in data:
ticks = int(data["rain"])
except:
print(CRED+'[NOK] rtl_433 timed out'+CEND)
from easyprocess import EasyProcess
s=EasyProcess("lsusb").call().stdout
for line in s.splitlines():
if line.find('Realtek')!=-1:
cmd = "sudo usb_reset /dev/bus/usb/"+line[4:7]+"/"+line[15:18]
stdout=Proc(cmd).call().stdout
print(cmd + ' ' +stdout)
return ticks, temperature
示例2: test_slowshot_wrap
def test_slowshot_wrap(self):
disp = SmartDisplay(visible=0)
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py)
f = disp.wrap(proc.wrap(disp.waitgrab))
img = f()
eq_(img is not None, True)
示例3: prog_shot
def prog_shot(cmd, f, wait, timeout, screen_size, visible, bgcolor, cwd=None):
'''start process in headless X and create screenshot after 'wait' sec.
Repeats screenshot until it is not empty if 'repeat_if_empty'=True.
wait: wait at least N seconds after first window is displayed,
it can be used to skip splash screen
:param enable_crop: True -> crop screenshot
:param wait: int
'''
disp = SmartDisplay(visible=visible, size=screen_size, bgcolor=bgcolor)
disp.pyscreenshot_backend = None
disp.pyscreenshot_childprocess = True
proc = EasyProcess(cmd, cwd=cwd)
def func():
try:
img = disp.waitgrab(timeout=timeout)
except DisplayTimeoutError as e:
raise DisplayTimeoutError(str(e) + ' ' + str(proc))
if wait:
proc.sleep(wait)
img = disp.grab()
return img
img = disp.wrap(proc.wrap(func))()
if img:
img.save(f)
return (proc.stdout, proc.stderr)
示例4: test_timeout_out
def test_timeout_out(self):
p = EasyProcess(
[python, '-c', "import time;print( 'start');time.sleep(5);print( 'end')"]).call(timeout=1)
eq_(p.is_alive(), False)
eq_(p.timeout_happened, True)
ok_(p.return_code < 0)
eq_(p.stdout, '')
示例5: test_slowshot
def test_slowshot(self):
disp = SmartDisplay(visible=0).start()
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py).start()
img = disp.waitgrab()
proc.stop()
disp.stop()
eq_(img is not None, True)
示例6: stop
def stop(self):
'''
stop display
:rtype: self
'''
self.redirect_display(False)
EasyProcess.stop(self)
return self
示例7: __init__
def __init__(self):
mutex.acquire()
try:
self.display = self.search_for_display()
while self.display in USED_DISPLAY_NR_LIST:
self.display+=1
USED_DISPLAY_NR_LIST.append(self.display)
finally:
mutex.release()
EasyProcess.__init__(self, self._cmd)
示例8: stop
def stop(self):
'''
stop display
:rtype: self
'''
self.redirect_display(False)
EasyProcess.stop(self)
if self.use_xauth:
self._clear_xauth()
return self
示例9: generate
def generate():
#get the query
if request.method == 'POST':
query = request.form['query']
else:
query = request.args.get('query')
query = query.replace("\"","\\\"")
command = "java -jar g.jar -qs \""+query+"\""
command_results = EasyProcess(command).call().stdout
result = command_results.split("RDF Output:")[1]
return str(result)
示例10: display
def display(self, zipfilename='', block=True):
fig = plt.figure()
self.create(fig, zipfilename)
if block:
plt.show()
else:
p = EasyProcess([sys.executable,
'-m', 'elme.start.plot',
self.project.name,
'--plot', self.name,
'--zipfilename', zipfilename
])
p.start()
示例11: __init__
def __init__(self, use_xauth=False):
mutex.acquire()
try:
self.display = self.search_for_display()
while self.display in USED_DISPLAY_NR_LIST:
self.display+=1
USED_DISPLAY_NR_LIST.append(self.display)
finally:
mutex.release()
if use_xauth and not xauth.is_installed():
raise xauth.NotFoundError()
self.use_xauth = use_xauth
self._old_xauth = None
self._xauth_filename = None
EasyProcess.__init__(self, self._cmd)
示例12: check_buttons
def check_buttons(cmd, expect):
with SmartDisplay(visible=VISIBLE) as disp:
with EasyProcess(cmd):
disp.waitgrab(timeout=TIMEOUT)
buttons = discover_buttons()
eq_(len(buttons), len(expect),
msg='dialog does not have expected buttons %s!=%s' % (buttons,expect))
mouse = PyMouse()
print 'buttons:',buttons
for v, b in zip(expect, buttons):
process = EasyProcess(cmd).start().sleep(1)
mouse.click(*b.center)
process.wait()
eq_(process.stdout, str(v)) #dialog does not return expected value
示例13: test_timeout
def test_timeout(self):
p = EasyProcess('sleep 1').start()
p.wait(0.2)
eq_(p.is_alive(), True)
p.wait(0.2)
eq_(p.is_alive(), True)
p.wait(2)
eq_(p.is_alive(), False)
eq_(EasyProcess('sleep 0.3').call().return_code == 0, True)
eq_(EasyProcess('sleep 0.3').call(timeout=0.1).return_code == 0, False)
eq_(EasyProcess('sleep 0.3').call(timeout=1).return_code == 0, True)
eq_(EasyProcess('sleep 0.3').call().timeout_happened, False)
eq_(EasyProcess('sleep 0.3').call(timeout=0.1).timeout_happened, True)
eq_(EasyProcess('sleep 0.3').call(timeout=1).timeout_happened, False)
示例14: start
def start(self):
'''
start display
:rtype: self
'''
EasyProcess.start(self)
# https://github.com/ponty/PyVirtualDisplay/issues/2
self.old_display_var = os.environ[
'DISPLAY'] if 'DISPLAY' in os.environ else ':0'
self.redirect_display(True)
# wait until X server is active
# TODO: better method
time.sleep(0.1)
return self
示例15: service
def service(request, service_mock):
port = random.randint(30000, 40000)
p = EasyProcess('python3.4 src/service.py {}'
'http://localhost:{}/tests/html1'
.format(port, service_mock.port))
def turn_off():
print("DOWN")
p.stop()
print("STDOUT: " + p.stdout)
print("STDERROR: " + p.stderr)
print("CODE: " + str(p.return_code))
request.addfinalizer(turn_off)
p.start()
time.sleep(0.5)
p.port = port
return p