本文整理汇总了Python中mozprocess.ProcessHandler类的典型用法代码示例。如果您正苦于以下问题:Python ProcessHandler类的具体用法?Python ProcessHandler怎么用?Python ProcessHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProcessHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_avds
def setup_avds(self):
'''
If tooltool cache mechanism is enabled, the cached version is used by
the fetch command. If the manifest includes an "unpack" field, tooltool
will unpack all compressed archives mentioned in the manifest.
'''
c = self.config
dirs = self.query_abs_dirs()
# FIXME
# Clobbering and re-unpacking would not be needed if we had a way to
# check whether the unpacked content already present match the
# contents of the tar ball
self.rmtree(dirs['abs_avds_dir'])
self.mkdir_p(dirs['abs_avds_dir'])
if 'avd_url' in c:
# Intended for experimental setups to evaluate an avd prior to
# tooltool deployment.
url = c['avd_url']
self.download_unpack(url, dirs['abs_avds_dir'])
else:
url = self._get_repo_url(c["tooltool_manifest_path"])
self._tooltool_fetch(url, dirs['abs_avds_dir'])
avd_home_dir = self.abs_dirs['abs_avds_dir']
if avd_home_dir != "/home/cltbld/.android":
# Modify the downloaded avds to point to the right directory.
cmd = [
'bash', '-c',
'sed -i "s|/home/cltbld/.android|%s|" %s/test-*.ini' %
(avd_home_dir, os.path.join(avd_home_dir, 'avd'))
]
proc = ProcessHandler(cmd)
proc.run()
proc.wait()
示例2: build_script
def build_script(self, modules=None, debug=False, profiling=False,
noftu=False, noopt=False, valgrind=False):
command = [os.path.join(self.b2g_home, 'build.sh')]
if modules:
command.extend(modules)
if debug:
command.insert(0, 'B2G_DEBUG=1')
if profiling:
command.insert(0, 'MOZ_PROFILING=1')
if noftu:
command.insert(0, 'NOFTU=1')
if noopt:
if profiling:
print("Can't perform profiling if optimizer is disabled")
return 1
command.insert(0, 'B2G_NOOPT=1')
if valgrind:
command.insert(0, 'B2G_VALGRIND=1')
p = ProcessHandler(command)
p.run()
#TODO: Error checking.
return p.wait()
示例3: test_relative_path
def test_relative_path(self):
tempdir = tempfile.mkdtemp()
# make a dummy profile
profile = FirefoxProfile(os.path.join(tempdir, 'testprofilepath'),
restore=False)
self.assertTrue(os.path.exists(os.path.join(tempdir,
'testprofilepath',
'user.js')))
# make a dummy test
test = """var test = function () { };"""
f = file(os.path.join(tempdir, 'test_dummy.js'), 'w')
f.write(test)
f.close()
# run mozmill on it
process = ProcessHandler(['mozmill',
'-t', 'test_dummy.js',
'--profile=testprofilepath'],
cwd=tempdir)
code = process.waitForFinish(timeout=120)
self.assertEqual(code, 0)
# cleanup
shutil.rmtree(tempdir)
示例4: flash
def flash(self):
command = os.path.join(self.b2g_home, 'flash.sh')
p = ProcessHandler(command)
if _is_device_attached():
p.run()
return p.wait()
return 1
示例5: test_relative_path
def test_relative_path(self):
tempdir = tempfile.mkdtemp()
# make a dummy profile
profile = FirefoxProfile(os.path.join(tempdir, 'testprofilepath'),
restore=False)
self.assertTrue(os.path.exists(os.path.join(tempdir,
'testprofilepath',
'user.js')))
# make a dummy test
test = """function test() { };"""
f = file(os.path.join(tempdir, 'test_dummy.js'), 'w')
f.write(test)
f.close()
# run mozmill on it
process = ProcessHandler(['mozmill',
'-t', 'test_dummy.js',
'--profile=testprofilepath'],
cwd=tempdir,
# stop mozmill from printing output to console
processOutputLine=[lambda line: None])
process.run()
process.wait()
self.assertNotEqual(process.proc.poll(), None)
# cleanup
shutil.rmtree(tempdir)
示例6: gdb
def gdb(self):
command = os.path.join(self.b2g_home, 'run-gdb.sh')
p = ProcessHandler(command)
p.run()
#TODO The emulator requires adb to run, we should check if that is
#running, catch that error or better yet, start adb.
return p.wait()
示例7: __init__
def __init__(self, cmd,
args=None, cwd=None,
env=os.environ.copy(),
ignore_children=False,
**kwargs):
ProcessHandler.__init__(self, cmd, args=args, cwd=cwd, env=env,
ignore_children=ignore_children, **kwargs)
self.logger = mozlog.getLogger('PEP')
示例8: pushDir
def pushDir(self, localDir, remoteDir, retryLimit=None, timeout=None):
# adb "push" accepts a directory as an argument, but if the directory
# contains symbolic links, the links are pushed, rather than the linked
# files; we either zip/unzip or re-copy the directory into a temporary
# one to get around this limitation
retryLimit = retryLimit or self.retryLimit
if self._useZip:
self.removeDir(remoteDir)
self.mkDirs(remoteDir + "/x")
try:
localZip = tempfile.mktemp() + ".zip"
remoteZip = remoteDir + "/adbdmtmp.zip"
proc = ProcessHandler(["zip", "-r", localZip, '.'], cwd=localDir,
processOutputLine=self._log)
proc.run()
proc.wait()
self.pushFile(localZip, remoteZip, retryLimit=retryLimit, createDir=False)
mozfile.remove(localZip)
data = self._runCmd(["shell", "unzip", "-o", remoteZip,
"-d", remoteDir]).output[0]
self._checkCmd(["shell", "rm", remoteZip],
retryLimit=retryLimit, timeout=self.short_timeout)
if re.search("unzip: exiting", data) or re.search("Operation not permitted", data):
raise Exception("unzip failed, or permissions error")
except Exception:
self._logger.warning(traceback.format_exc())
self._logger.warning("zip/unzip failure: falling back to normal push")
self._useZip = False
self.pushDir(localDir, remoteDir, retryLimit=retryLimit, timeout=timeout)
else:
localDir = os.path.normpath(localDir)
remoteDir = os.path.normpath(remoteDir)
tempParent = tempfile.mkdtemp()
remoteName = os.path.basename(remoteDir)
newLocal = os.path.join(tempParent, remoteName)
dir_util.copy_tree(localDir, newLocal)
# See do_sync_push in
# https://android.googlesource.com/platform/system/core/+/master/adb/file_sync_client.cpp
# Work around change in behavior in adb 1.0.36 where if
# the remote destination directory exists, adb push will
# copy the source directory *into* the destination
# directory otherwise it will copy the source directory
# *onto* the destination directory.
if self._adb_version >= '1.0.36':
remoteDir = '/'.join(remoteDir.rstrip('/').split('/')[:-1])
try:
if self._checkCmd(["push", newLocal, remoteDir],
retryLimit=retryLimit, timeout=timeout):
raise DMError("failed to push %s (copy of %s) to %s" %
(newLocal, localDir, remoteDir))
except BaseException:
raise
finally:
mozfile.remove(tempParent)
示例9: _isLocalZipAvailable
def _isLocalZipAvailable(self):
def _noOutput(line):
# suppress output from zip ProcessHandler
pass
try:
proc = ProcessHandler(["zip", "-?"], storeOutput=False, processOutputLine=_noOutput)
proc.run()
proc.wait()
except:
return False
return True
示例10: start_logcat
def start_logcat(self, serial, logfile=None, stream=None, filterspec=None):
logcat_args = [self.app_ctx.adb, '-s', '%s' % serial,
'logcat', '-v', 'time', '-b', 'main', '-b', 'radio']
# only log filterspec
if filterspec:
logcat_args.extend(['-s', filterspec])
process_args = {}
if logfile:
process_args['logfile'] = logfile
elif stream:
process_args['stream'] = stream
proc = ProcessHandler(logcat_args, **process_args)
proc.run()
return proc
示例11: test_no_option
def test_no_option(self):
process = ProcessHandler(['mozmill',
'-b', os.environ['BROWSER_PATH'],
'-t', os.path.join(testdir,
'useMozmill',
'testServerRoot.js')
],
# stop mozmill from printing output to console
processOutputLine=[lambda line: None])
process.run()
process.wait()
self.assertEqual(process.proc.poll(), 1,
'Test failed')
示例12: __init__
def __init__(self, cmd,
args=None, cwd=None,
env=None,
ignore_children=False,
logfile=None,
**kwargs):
self.firstTime = int(time.time()) * 1000
self.logfile = logfile
self.results_file = None
if env is None:
env = os.environ.copy()
ProcessHandler.__init__(self, cmd, args=args, cwd=cwd, env=env,
ignore_children=ignore_children, logfile=self.logfile, **kwargs)
示例13: test_options
def test_options(self):
absdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
testdir = os.path.join(absdir, 'js-tests')
process = ProcessHandler(['mozmill',
'-b', os.environ['BROWSER_PATH'],
'-t', os.path.join(testdir,
'test_module1.js'),
'-m', os.path.join(testdir, 'example.ini')
])
process.run()
process.waitForFinish()
self.assertNotEqual(process.proc.poll(), 0,
'Parser error due to -t and -m are mutually exclusive')
示例14: screenshot
def screenshot(self, test):
full_url = self.test_url(test)
with TempFilename(self.tempdir) as output_path:
debug_args, command = browser_command(
self.binary,
[
"--cpu",
"--hard-fail",
"--exit",
"-u",
"Servo/wptrunner",
"-Z",
"disable-text-aa",
"--output=%s" % output_path,
full_url,
],
self.debug_info,
)
for stylesheet in self.browser.user_stylesheets:
command += ["--user-stylesheet", stylesheet]
for pref in test.environment.get("prefs", {}):
command += ["--pref", pref]
self.command = debug_args + command
env = os.environ.copy()
env["HOST_FILE"] = self.hosts_path
if not self.interactive:
self.proc = ProcessHandler(self.command, processOutputLine=[self.on_output], env=env)
try:
self.proc.run()
timeout = test.timeout * self.timeout_multiplier + 5
rv = self.proc.wait(timeout=timeout)
except KeyboardInterrupt:
self.proc.kill()
raise
else:
self.proc = subprocess.Popen(self.command, env=env)
try:
rv = self.proc.wait()
except KeyboardInterrupt:
self.proc.kill()
raise
if rv is None:
self.proc.kill()
return False, ("EXTERNAL-TIMEOUT", None)
if rv != 0 or not os.path.exists(output_path):
return False, ("CRASH", None)
with open(output_path) as f:
# Might need to strip variable headers or something here
data = f.read()
return True, base64.b64encode(data)
示例15: start
def start(self):
"""
Starts a new emulator.
"""
if self.proc:
return
original_devices = set(self._get_online_devices())
qemu_log = None
qemu_proc_args = {}
if self.logdir:
# save output from qemu to logfile
qemu_log = os.path.join(self.logdir, 'qemu.log')
if os.path.isfile(qemu_log):
self._rotate_log(qemu_log)
qemu_proc_args['logfile'] = qemu_log
else:
qemu_proc_args['processOutputLine'] = lambda line: None
self.proc = ProcessHandler(self.args, **qemu_proc_args)
self.proc.run()
devices = set(self._get_online_devices())
now = datetime.datetime.now()
while (devices - original_devices) == set([]):
time.sleep(1)
if datetime.datetime.now() - now > datetime.timedelta(seconds=60):
raise TimeoutException('timed out waiting for emulator to start')
devices = set(self._get_online_devices())
devices = devices - original_devices
self.serial = devices.pop()
self.connect()