device
index
/home/aki/wrk/git-mozharness-ro/mozharness/mozilla/testing/device.py

Interact with a device via ADB or SUT.
 
This code is largely from
http://hg.mozilla.org/build/tools/file/default/sut_tools

 
Modules
       
datetime
os
re
subprocess
sys
time

 
Classes
       
__builtin__.object
DeviceMixin
exceptions.Exception(exceptions.BaseException)
DeviceException
mozharness.base.log.LogMixin(__builtin__.object)
BaseDeviceHandler(mozharness.base.script.ScriptMixin, mozharness.base.log.LogMixin)
ADBDeviceHandler
SUTDeviceHandler
SUTDeviceMozdeviceMixin
mozharness.base.script.ScriptMixin(__builtin__.object)
BaseDeviceHandler(mozharness.base.script.ScriptMixin, mozharness.base.log.LogMixin)
ADBDeviceHandler
SUTDeviceHandler
SUTDeviceMozdeviceMixin

 
class ADBDeviceHandler(BaseDeviceHandler)
    ADBDeviceHandler {{{1
 
 
Method resolution order:
ADBDeviceHandler
BaseDeviceHandler
mozharness.base.script.ScriptMixin
mozharness.base.log.LogMixin
__builtin__.object

Methods defined here:
__init__(self, **kwargs)
check_device(self)
cleanup_device(self, reboot=False)
connect_device(self)
disconnect_device(self)
install_app(self, file_path)
ping_device(self, auto_connect=False, silent=False)
# maintenance {{{2
query_device_exe(self, exe_name)
query_device_file_exists(self, file_name)
query_device_id(self, auto_connect=True)
query_device_root(self, silent=False)
# device calls {{{2
query_device_time(self)
reboot_device(self)
remove_device_root(self, error_level='error')
remove_etc_hosts(self, hosts_file='/system/etc/hosts')
# Device-type-specific. {{{2
set_device_time(self, device_time=None, error_level='error')
uninstall_app(self, package_name, package_root='/data/data', error_level='error')
wait_for_device(self, interval=60, max_attempts=20)
# TODO from here on down needs to be copied to Base+SUT

Methods inherited from BaseDeviceHandler:
add_device_flag(self, flag)
query_download_filename(self, file_id=None)

Data and other attributes inherited from BaseDeviceHandler:
default_port = None
device_flags = []
device_id = None
device_root = None

Methods inherited from mozharness.base.script.ScriptMixin:
chdir(self, dir_name)
chmod(self, path, mode)
copyfile(self, src, dest, log_level='info', error_level='error', copystat=False)
copytree(self, src, dest, overwrite='no_overwrite', log_level='info', error_level='error')
an implementation of shutil.copytree however it allows for
dest to exist and implements different overwrite levels.
overwrite uses:
'no_overwrite' will keep all(any) existing files in destination tree
'overwrite_if_exists' will only overwrite destination paths that have
           the same path names relative to the root of the src and
           destination tree
'clobber' will replace the whole destination tree(clobber) if it exists
download_file(self, url, file_name=None, parent_dir=None, create_parent_dir=True, error_level='error', exit_code=-1)
Python wget.
get_filename_from_url(self, url)
get_output_from_command(self, command, cwd=None, halt_on_failure=False, env=None, silent=False, log_level='info', tmpfile_base_path='tmpfile', return_type='output', save_tmpfiles=False, throw_exception=False)
Similar to run_command, but where run_command is an
os.system(command) analog, get_output_from_command is a `command`
analog.
 
Less error checking by design, though if we figure out how to
do it without borking the output, great.
 
TODO: binary mode? silent is kinda like that.
TODO: since p.wait() can take a long time, optionally log something
every N seconds?
TODO: optionally only keep the first or last (N) line(s) of output?
TODO: optionally only return the tmp_stdout_filename?
mkdir_p(self, path, error_level='error')
Returns None for success, not None for failure
move(self, src, dest, log_level='info', error_level='error', exit_code=-1)
query_env(self, partial_env=None, replace_dict=None, set_self_env=None, log_level='debug')
Environment query/generation method.
 
The default, query_env(), will look for self.config['env']
and replace any special strings in there ( %(PATH)s ).
It will then store it as self.env for speeding things up later.
 
If you specify partial_env, partial_env will be used instead of
self.config['env'], and we don't save self.env as it's a one-off.
query_exe(self, exe_name, exe_dict='exes', default=None, return_type=None, error_level='fatal')
One way to work around PATH rewrites.
 
By default, return exe_name, and we'll fall through to searching
os.environ["PATH"].
However, if self.config[exe_dict][exe_name] exists, return that.
This lets us override exe paths via config file.
 
'return_type' can be None (don't do anything to the value),
'list' (return a list), or 'string' (return a string).
 
If we need runtime setting, we can build in self.exes support later.
query_msys_path(self, path)
read_from_file(self, file_path, verbose=True, open_mode='r', error_level='error')
Reads from file_path.
 
Returns contents if successful, None if not.
retry(self, action, attempts=None, sleeptime=60, max_sleeptime=300, retry_exceptions=(<type 'exceptions.Exception'>,), good_statuses=None, cleanup=None, error_level='error', error_message='%(action)s failed after %(attempts)d tries!', failure_status=-1, args=(), kwargs={})
Generic retry command.
Ported from tools util.retry.
 
Call `action' a maximum of `attempts' times until it succeeds,
defaulting to self.config.get('global_retries', 5).
 
`sleeptime' is the number of seconds to wait between attempts,
defaulting to 60 and doubling each retry attempt, to a maximum of
`max_sleeptime'.
 
`retry_exceptions' is a tuple of Exceptions that should be caught.
If exceptions other than those listed in `retry_exceptions' are
raised from `action', they will be raised immediately.
 
`good_statuses' is a tuple of return values which, if specified,
will result in retrying if the return value isn't listed.
 
If `cleanup' is provided and callable it will be called immediately
after an Exception is caught.  No arguments will be passed to it.
If your cleanup function requires arguments it is recommended that
you wrap it in an argumentless function.
 
`args' and `kwargs' are a tuple and dict of arguments to pass onto
to `callable'.
rmtree(self, path, log_level='info', error_level='error', exit_code=-1)
Returns None for success, not None for failure
run_command(self, command, cwd=None, error_list=None, parse_at_end=False, halt_on_failure=False, success_codes=None, env=None, return_type='status', throw_exception=False, output_parser=None)
Run a command, with logging and error parsing.
 
TODO: parse_at_end, context_lines
TODO: retry_interval?
TODO: error_level_override?
TODO: Add a copy-pastable version of |command| if it's a list.
TODO: print env if set
 
output_parser lets you provide an instance of your own OutputParser
subclass, or pass None to use OutputParser.
 
error_list example:
[{'regex': re.compile('^Error: LOL J/K'), level=IGNORE},
 {'regex': re.compile('^Error:'), level=ERROR, contextLines='5:5'},
 {'substr': 'THE WORLD IS ENDING', level=FATAL, contextLines='20:'}
]
(context_lines isn't written yet)
which(self, program)
OS independent implementation of Unix's which command
Takes in a program name
Returns path to executable or None
write_to_file(self, file_path, contents, verbose=True, open_mode='w', create_parent_dir=False, error_level='error')
Write contents to file_path.
 
This doesn't currently create the parent_dir or translate into
abs_path; that needs to be done beforehand, since ScriptMixin doesn't
necessarily have access to query_abs_dirs().
 
Returns file_path if successful, None if not.

Data descriptors inherited from mozharness.base.script.ScriptMixin:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from mozharness.base.script.ScriptMixin:
env = None

Methods inherited from mozharness.base.log.LogMixin:
critical(self, message)
debug(self, message)
error(self, message)
exception(self, message=None, level='error')
# Copying Bear's dumpException():
http://hg.mozilla.org/build/tools/annotate/1485f23c38e0/sut_tools/sut_lib.py#l23
fatal(self, message, exit_code=-1)
info(self, message)
log(self, message, level='info', exit_code=-1)
warning(self, message)

 
class BaseDeviceHandler(mozharness.base.script.ScriptMixin, mozharness.base.log.LogMixin)
    BaseDeviceHandler {{{1
 
 
Method resolution order:
BaseDeviceHandler
mozharness.base.script.ScriptMixin
mozharness.base.log.LogMixin
__builtin__.object

Methods defined here:
__init__(self, log_obj=None, config=None, script_obj=None)
add_device_flag(self, flag)
check_device(self)
cleanup_device(self, reboot=False)
install_app(self, file_path)
ping_device(self)
query_device_id(self)
query_device_root(self)
query_download_filename(self, file_id=None)
reboot_device(self)
wait_for_device(self, interval=60, max_attempts=20)

Data and other attributes defined here:
default_port = None
device_flags = []
device_id = None
device_root = None

Methods inherited from mozharness.base.script.ScriptMixin:
chdir(self, dir_name)
chmod(self, path, mode)
copyfile(self, src, dest, log_level='info', error_level='error', copystat=False)
copytree(self, src, dest, overwrite='no_overwrite', log_level='info', error_level='error')
an implementation of shutil.copytree however it allows for
dest to exist and implements different overwrite levels.
overwrite uses:
'no_overwrite' will keep all(any) existing files in destination tree
'overwrite_if_exists' will only overwrite destination paths that have
           the same path names relative to the root of the src and
           destination tree
'clobber' will replace the whole destination tree(clobber) if it exists
download_file(self, url, file_name=None, parent_dir=None, create_parent_dir=True, error_level='error', exit_code=-1)
Python wget.
get_filename_from_url(self, url)
get_output_from_command(self, command, cwd=None, halt_on_failure=False, env=None, silent=False, log_level='info', tmpfile_base_path='tmpfile', return_type='output', save_tmpfiles=False, throw_exception=False)
Similar to run_command, but where run_command is an
os.system(command) analog, get_output_from_command is a `command`
analog.
 
Less error checking by design, though if we figure out how to
do it without borking the output, great.
 
TODO: binary mode? silent is kinda like that.
TODO: since p.wait() can take a long time, optionally log something
every N seconds?
TODO: optionally only keep the first or last (N) line(s) of output?
TODO: optionally only return the tmp_stdout_filename?
mkdir_p(self, path, error_level='error')
Returns None for success, not None for failure
move(self, src, dest, log_level='info', error_level='error', exit_code=-1)
query_env(self, partial_env=None, replace_dict=None, set_self_env=None, log_level='debug')
Environment query/generation method.
 
The default, query_env(), will look for self.config['env']
and replace any special strings in there ( %(PATH)s ).
It will then store it as self.env for speeding things up later.
 
If you specify partial_env, partial_env will be used instead of
self.config['env'], and we don't save self.env as it's a one-off.
query_exe(self, exe_name, exe_dict='exes', default=None, return_type=None, error_level='fatal')
One way to work around PATH rewrites.
 
By default, return exe_name, and we'll fall through to searching
os.environ["PATH"].
However, if self.config[exe_dict][exe_name] exists, return that.
This lets us override exe paths via config file.
 
'return_type' can be None (don't do anything to the value),
'list' (return a list), or 'string' (return a string).
 
If we need runtime setting, we can build in self.exes support later.
query_msys_path(self, path)
read_from_file(self, file_path, verbose=True, open_mode='r', error_level='error')
Reads from file_path.
 
Returns contents if successful, None if not.
retry(self, action, attempts=None, sleeptime=60, max_sleeptime=300, retry_exceptions=(<type 'exceptions.Exception'>,), good_statuses=None, cleanup=None, error_level='error', error_message='%(action)s failed after %(attempts)d tries!', failure_status=-1, args=(), kwargs={})
Generic retry command.
Ported from tools util.retry.
 
Call `action' a maximum of `attempts' times until it succeeds,
defaulting to self.config.get('global_retries', 5).
 
`sleeptime' is the number of seconds to wait between attempts,
defaulting to 60 and doubling each retry attempt, to a maximum of
`max_sleeptime'.
 
`retry_exceptions' is a tuple of Exceptions that should be caught.
If exceptions other than those listed in `retry_exceptions' are
raised from `action', they will be raised immediately.
 
`good_statuses' is a tuple of return values which, if specified,
will result in retrying if the return value isn't listed.
 
If `cleanup' is provided and callable it will be called immediately
after an Exception is caught.  No arguments will be passed to it.
If your cleanup function requires arguments it is recommended that
you wrap it in an argumentless function.
 
`args' and `kwargs' are a tuple and dict of arguments to pass onto
to `callable'.
rmtree(self, path, log_level='info', error_level='error', exit_code=-1)
Returns None for success, not None for failure
run_command(self, command, cwd=None, error_list=None, parse_at_end=False, halt_on_failure=False, success_codes=None, env=None, return_type='status', throw_exception=False, output_parser=None)
Run a command, with logging and error parsing.
 
TODO: parse_at_end, context_lines
TODO: retry_interval?
TODO: error_level_override?
TODO: Add a copy-pastable version of |command| if it's a list.
TODO: print env if set
 
output_parser lets you provide an instance of your own OutputParser
subclass, or pass None to use OutputParser.
 
error_list example:
[{'regex': re.compile('^Error: LOL J/K'), level=IGNORE},
 {'regex': re.compile('^Error:'), level=ERROR, contextLines='5:5'},
 {'substr': 'THE WORLD IS ENDING', level=FATAL, contextLines='20:'}
]
(context_lines isn't written yet)
which(self, program)
OS independent implementation of Unix's which command
Takes in a program name
Returns path to executable or None
write_to_file(self, file_path, contents, verbose=True, open_mode='w', create_parent_dir=False, error_level='error')
Write contents to file_path.
 
This doesn't currently create the parent_dir or translate into
abs_path; that needs to be done beforehand, since ScriptMixin doesn't
necessarily have access to query_abs_dirs().
 
Returns file_path if successful, None if not.

Data descriptors inherited from mozharness.base.script.ScriptMixin:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from mozharness.base.script.ScriptMixin:
env = None

Methods inherited from mozharness.base.log.LogMixin:
critical(self, message)
debug(self, message)
error(self, message)
exception(self, message=None, level='error')
# Copying Bear's dumpException():
http://hg.mozilla.org/build/tools/annotate/1485f23c38e0/sut_tools/sut_lib.py#l23
fatal(self, message, exit_code=-1)
info(self, message)
log(self, message, level='info', exit_code=-1)
warning(self, message)

 
class DeviceException(exceptions.Exception)
    
Method resolution order:
DeviceException
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object at 0x8162d20>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
__unicode__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message

 
class DeviceMixin(__builtin__.object)
    BaseScript mixin, designed to interface with the device.
 
  Methods defined here:
check_device(self)
cleanup_device(self, **kwargs)
install_app(self)
query_device_handler(self)
reboot_device(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
device_handler = None
device_root = None

 
class SUTDeviceHandler(BaseDeviceHandler)
    SUTDeviceHandler {{{1
 
 
Method resolution order:
SUTDeviceHandler
BaseDeviceHandler
mozharness.base.script.ScriptMixin
mozharness.base.log.LogMixin
__builtin__.object

Methods defined here:
__init__(self, **kwargs)
check_device(self)
cleanup_device(self, reboot=False)
install_app(self, file_path)
ping_device(self)
# maintenance {{{2
query_device_root(self, strict=False)
# device calls {{{2
query_device_time(self)
query_devicemanager(self)
reboot_device(self)
remove_etc_hosts(self, hosts_file='/system/etc/hosts')
# device type specific {{{2
set_device_time(self)
wait_for_device(self, interval=60, max_attempts=20)

Methods inherited from BaseDeviceHandler:
add_device_flag(self, flag)
query_device_id(self)
query_download_filename(self, file_id=None)

Data and other attributes inherited from BaseDeviceHandler:
default_port = None
device_flags = []
device_id = None
device_root = None

Methods inherited from mozharness.base.script.ScriptMixin:
chdir(self, dir_name)
chmod(self, path, mode)
copyfile(self, src, dest, log_level='info', error_level='error', copystat=False)
copytree(self, src, dest, overwrite='no_overwrite', log_level='info', error_level='error')
an implementation of shutil.copytree however it allows for
dest to exist and implements different overwrite levels.
overwrite uses:
'no_overwrite' will keep all(any) existing files in destination tree
'overwrite_if_exists' will only overwrite destination paths that have
           the same path names relative to the root of the src and
           destination tree
'clobber' will replace the whole destination tree(clobber) if it exists
download_file(self, url, file_name=None, parent_dir=None, create_parent_dir=True, error_level='error', exit_code=-1)
Python wget.
get_filename_from_url(self, url)
get_output_from_command(self, command, cwd=None, halt_on_failure=False, env=None, silent=False, log_level='info', tmpfile_base_path='tmpfile', return_type='output', save_tmpfiles=False, throw_exception=False)
Similar to run_command, but where run_command is an
os.system(command) analog, get_output_from_command is a `command`
analog.
 
Less error checking by design, though if we figure out how to
do it without borking the output, great.
 
TODO: binary mode? silent is kinda like that.
TODO: since p.wait() can take a long time, optionally log something
every N seconds?
TODO: optionally only keep the first or last (N) line(s) of output?
TODO: optionally only return the tmp_stdout_filename?
mkdir_p(self, path, error_level='error')
Returns None for success, not None for failure
move(self, src, dest, log_level='info', error_level='error', exit_code=-1)
query_env(self, partial_env=None, replace_dict=None, set_self_env=None, log_level='debug')
Environment query/generation method.
 
The default, query_env(), will look for self.config['env']
and replace any special strings in there ( %(PATH)s ).
It will then store it as self.env for speeding things up later.
 
If you specify partial_env, partial_env will be used instead of
self.config['env'], and we don't save self.env as it's a one-off.
query_exe(self, exe_name, exe_dict='exes', default=None, return_type=None, error_level='fatal')
One way to work around PATH rewrites.
 
By default, return exe_name, and we'll fall through to searching
os.environ["PATH"].
However, if self.config[exe_dict][exe_name] exists, return that.
This lets us override exe paths via config file.
 
'return_type' can be None (don't do anything to the value),
'list' (return a list), or 'string' (return a string).
 
If we need runtime setting, we can build in self.exes support later.
query_msys_path(self, path)
read_from_file(self, file_path, verbose=True, open_mode='r', error_level='error')
Reads from file_path.
 
Returns contents if successful, None if not.
retry(self, action, attempts=None, sleeptime=60, max_sleeptime=300, retry_exceptions=(<type 'exceptions.Exception'>,), good_statuses=None, cleanup=None, error_level='error', error_message='%(action)s failed after %(attempts)d tries!', failure_status=-1, args=(), kwargs={})
Generic retry command.
Ported from tools util.retry.
 
Call `action' a maximum of `attempts' times until it succeeds,
defaulting to self.config.get('global_retries', 5).
 
`sleeptime' is the number of seconds to wait between attempts,
defaulting to 60 and doubling each retry attempt, to a maximum of
`max_sleeptime'.
 
`retry_exceptions' is a tuple of Exceptions that should be caught.
If exceptions other than those listed in `retry_exceptions' are
raised from `action', they will be raised immediately.
 
`good_statuses' is a tuple of return values which, if specified,
will result in retrying if the return value isn't listed.
 
If `cleanup' is provided and callable it will be called immediately
after an Exception is caught.  No arguments will be passed to it.
If your cleanup function requires arguments it is recommended that
you wrap it in an argumentless function.
 
`args' and `kwargs' are a tuple and dict of arguments to pass onto
to `callable'.
rmtree(self, path, log_level='info', error_level='error', exit_code=-1)
Returns None for success, not None for failure
run_command(self, command, cwd=None, error_list=None, parse_at_end=False, halt_on_failure=False, success_codes=None, env=None, return_type='status', throw_exception=False, output_parser=None)
Run a command, with logging and error parsing.
 
TODO: parse_at_end, context_lines
TODO: retry_interval?
TODO: error_level_override?
TODO: Add a copy-pastable version of |command| if it's a list.
TODO: print env if set
 
output_parser lets you provide an instance of your own OutputParser
subclass, or pass None to use OutputParser.
 
error_list example:
[{'regex': re.compile('^Error: LOL J/K'), level=IGNORE},
 {'regex': re.compile('^Error:'), level=ERROR, contextLines='5:5'},
 {'substr': 'THE WORLD IS ENDING', level=FATAL, contextLines='20:'}
]
(context_lines isn't written yet)
which(self, program)
OS independent implementation of Unix's which command
Takes in a program name
Returns path to executable or None
write_to_file(self, file_path, contents, verbose=True, open_mode='w', create_parent_dir=False, error_level='error')
Write contents to file_path.
 
This doesn't currently create the parent_dir or translate into
abs_path; that needs to be done beforehand, since ScriptMixin doesn't
necessarily have access to query_abs_dirs().
 
Returns file_path if successful, None if not.

Data descriptors inherited from mozharness.base.script.ScriptMixin:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from mozharness.base.script.ScriptMixin:
env = None

Methods inherited from mozharness.base.log.LogMixin:
critical(self, message)
debug(self, message)
error(self, message)
exception(self, message=None, level='error')
# Copying Bear's dumpException():
http://hg.mozilla.org/build/tools/annotate/1485f23c38e0/sut_tools/sut_lib.py#l23
fatal(self, message, exit_code=-1)
info(self, message)
log(self, message, level='info', exit_code=-1)
warning(self, message)

 
class SUTDeviceMozdeviceMixin(SUTDeviceHandler)
    This SUT device manager class makes calls through mozdevice (from mozbase) [1]
directly rather than calling SUT tools.
 
[1] https://github.com/mozilla/mozbase/blob/master/mozdevice/mozdevice/devicemanagerSUT.py
 
 
Method resolution order:
SUTDeviceMozdeviceMixin
SUTDeviceHandler
BaseDeviceHandler
mozharness.base.script.ScriptMixin
mozharness.base.log.LogMixin
__builtin__.object

Methods defined here:
get_logcat(self)
query_devicemanager(self)
query_file(self, filename)
set_device_epoch_time(self, timestamp=1369026004)

Data and other attributes defined here:
dm = None

Methods inherited from SUTDeviceHandler:
__init__(self, **kwargs)
check_device(self)
cleanup_device(self, reboot=False)
install_app(self, file_path)
ping_device(self)
# maintenance {{{2
query_device_root(self, strict=False)
# device calls {{{2
query_device_time(self)
reboot_device(self)
remove_etc_hosts(self, hosts_file='/system/etc/hosts')
# device type specific {{{2
set_device_time(self)
wait_for_device(self, interval=60, max_attempts=20)

Methods inherited from BaseDeviceHandler:
add_device_flag(self, flag)
query_device_id(self)
query_download_filename(self, file_id=None)

Data and other attributes inherited from BaseDeviceHandler:
default_port = None
device_flags = []
device_id = None
device_root = None

Methods inherited from mozharness.base.script.ScriptMixin:
chdir(self, dir_name)
chmod(self, path, mode)
copyfile(self, src, dest, log_level='info', error_level='error', copystat=False)
copytree(self, src, dest, overwrite='no_overwrite', log_level='info', error_level='error')
an implementation of shutil.copytree however it allows for
dest to exist and implements different overwrite levels.
overwrite uses:
'no_overwrite' will keep all(any) existing files in destination tree
'overwrite_if_exists' will only overwrite destination paths that have
           the same path names relative to the root of the src and
           destination tree
'clobber' will replace the whole destination tree(clobber) if it exists
download_file(self, url, file_name=None, parent_dir=None, create_parent_dir=True, error_level='error', exit_code=-1)
Python wget.
get_filename_from_url(self, url)
get_output_from_command(self, command, cwd=None, halt_on_failure=False, env=None, silent=False, log_level='info', tmpfile_base_path='tmpfile', return_type='output', save_tmpfiles=False, throw_exception=False)
Similar to run_command, but where run_command is an
os.system(command) analog, get_output_from_command is a `command`
analog.
 
Less error checking by design, though if we figure out how to
do it without borking the output, great.
 
TODO: binary mode? silent is kinda like that.
TODO: since p.wait() can take a long time, optionally log something
every N seconds?
TODO: optionally only keep the first or last (N) line(s) of output?
TODO: optionally only return the tmp_stdout_filename?
mkdir_p(self, path, error_level='error')
Returns None for success, not None for failure
move(self, src, dest, log_level='info', error_level='error', exit_code=-1)
query_env(self, partial_env=None, replace_dict=None, set_self_env=None, log_level='debug')
Environment query/generation method.
 
The default, query_env(), will look for self.config['env']
and replace any special strings in there ( %(PATH)s ).
It will then store it as self.env for speeding things up later.
 
If you specify partial_env, partial_env will be used instead of
self.config['env'], and we don't save self.env as it's a one-off.
query_exe(self, exe_name, exe_dict='exes', default=None, return_type=None, error_level='fatal')
One way to work around PATH rewrites.
 
By default, return exe_name, and we'll fall through to searching
os.environ["PATH"].
However, if self.config[exe_dict][exe_name] exists, return that.
This lets us override exe paths via config file.
 
'return_type' can be None (don't do anything to the value),
'list' (return a list), or 'string' (return a string).
 
If we need runtime setting, we can build in self.exes support later.
query_msys_path(self, path)
read_from_file(self, file_path, verbose=True, open_mode='r', error_level='error')
Reads from file_path.
 
Returns contents if successful, None if not.
retry(self, action, attempts=None, sleeptime=60, max_sleeptime=300, retry_exceptions=(<type 'exceptions.Exception'>,), good_statuses=None, cleanup=None, error_level='error', error_message='%(action)s failed after %(attempts)d tries!', failure_status=-1, args=(), kwargs={})
Generic retry command.
Ported from tools util.retry.
 
Call `action' a maximum of `attempts' times until it succeeds,
defaulting to self.config.get('global_retries', 5).
 
`sleeptime' is the number of seconds to wait between attempts,
defaulting to 60 and doubling each retry attempt, to a maximum of
`max_sleeptime'.
 
`retry_exceptions' is a tuple of Exceptions that should be caught.
If exceptions other than those listed in `retry_exceptions' are
raised from `action', they will be raised immediately.
 
`good_statuses' is a tuple of return values which, if specified,
will result in retrying if the return value isn't listed.
 
If `cleanup' is provided and callable it will be called immediately
after an Exception is caught.  No arguments will be passed to it.
If your cleanup function requires arguments it is recommended that
you wrap it in an argumentless function.
 
`args' and `kwargs' are a tuple and dict of arguments to pass onto
to `callable'.
rmtree(self, path, log_level='info', error_level='error', exit_code=-1)
Returns None for success, not None for failure
run_command(self, command, cwd=None, error_list=None, parse_at_end=False, halt_on_failure=False, success_codes=None, env=None, return_type='status', throw_exception=False, output_parser=None)
Run a command, with logging and error parsing.
 
TODO: parse_at_end, context_lines
TODO: retry_interval?
TODO: error_level_override?
TODO: Add a copy-pastable version of |command| if it's a list.
TODO: print env if set
 
output_parser lets you provide an instance of your own OutputParser
subclass, or pass None to use OutputParser.
 
error_list example:
[{'regex': re.compile('^Error: LOL J/K'), level=IGNORE},
 {'regex': re.compile('^Error:'), level=ERROR, contextLines='5:5'},
 {'substr': 'THE WORLD IS ENDING', level=FATAL, contextLines='20:'}
]
(context_lines isn't written yet)
which(self, program)
OS independent implementation of Unix's which command
Takes in a program name
Returns path to executable or None
write_to_file(self, file_path, contents, verbose=True, open_mode='w', create_parent_dir=False, error_level='error')
Write contents to file_path.
 
This doesn't currently create the parent_dir or translate into
abs_path; that needs to be done beforehand, since ScriptMixin doesn't
necessarily have access to query_abs_dirs().
 
Returns file_path if successful, None if not.

Data descriptors inherited from mozharness.base.script.ScriptMixin:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from mozharness.base.script.ScriptMixin:
env = None

Methods inherited from mozharness.base.log.LogMixin:
critical(self, message)
debug(self, message)
error(self, message)
exception(self, message=None, level='error')
# Copying Bear's dumpException():
http://hg.mozilla.org/build/tools/annotate/1485f23c38e0/sut_tools/sut_lib.py#l23
fatal(self, message, exit_code=-1)
info(self, message)
log(self, message, level='info', exit_code=-1)
warning(self, message)

 
Data
        ADBErrorList = [{'level': 'error', 'substr': 'command not found'}, {'level': 'error', 'substr': 'INSTALL_FAILED_INSUFFICIENT_STORAGE'}, {'level': 'error', 'substr': 'Android Debug Bridge version'}, {'level': 'error', 'substr': 'error: protocol fault'}, {'level': 'error', 'substr': 'unable to connect to '}]
DEBUG = 'debug'
DEVICE_CANT_REMOVE_DEVROOT = 6
DEVICE_CANT_REMOVE_ETC_HOSTS = 7
DEVICE_CANT_SET_TIME = 8
DEVICE_HOST_ERROR = 4
DEVICE_MISSING_SDCARD = 3
DEVICE_NOT_CONNECTED = 2
DEVICE_NOT_REBOOTED = 5
DEVICE_PROTOCOL_DICT = {'adb': <class 'device.ADBDeviceHandler'>, 'sut': <class 'device.SUTDeviceHandler'>}
DEVICE_UNREACHABLE = 1
device_config_options = [[['--device-ip'], {'action': 'store', 'dest': 'device_ip', 'help': 'Specify the IP address of the device.'}], [['--device-port'], {'action': 'store', 'dest': 'device_port', 'help': 'Specify the IP port of the device.'}], [['--device-heartbeat-port'], {'action': 'store', 'dest': 'device_heartbeat_port', 'help': 'Specify the heartbeat port of the SUT device.'}], [['--device-protocol'], {'action': 'store', 'choices': ['sut', 'adb'], 'dest': 'device_protocol', 'help': 'Specify the device communication protocol.', 'type': 'choice'}], [['--device-type'], {'action': 'store', 'choices': ['non-tegra', 'tegra250'], 'default': 'non-tegra', 'dest': 'device_type', 'help': 'Specify the device type.', 'type': 'choice'}], [['--devicemanager-path'], {'action': 'store', 'dest': 'devicemanager_path', 'help': 'Specify the parent dir of devicemanagerSUT.py.'}]]