repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
danielhrisca/asammdf | asammdf/blocks/utils.py | count_channel_groups | def count_channel_groups(stream, include_channels=False):
""" count all channel groups as fast as possible. This is used to provide
reliable progress information when loading a file using the GUI
Parameters
----------
stream : file handle
opened file handle
include_channels : bool
... | python | def count_channel_groups(stream, include_channels=False):
""" count all channel groups as fast as possible. This is used to provide
reliable progress information when loading a file using the GUI
Parameters
----------
stream : file handle
opened file handle
include_channels : bool
... | [
"def",
"count_channel_groups",
"(",
"stream",
",",
"include_channels",
"=",
"False",
")",
":",
"count",
"=",
"0",
"ch_count",
"=",
"0",
"stream",
".",
"seek",
"(",
"64",
")",
"blk_id",
"=",
"stream",
".",
"read",
"(",
"2",
")",
"if",
"blk_id",
"==",
... | count all channel groups as fast as possible. This is used to provide
reliable progress information when loading a file using the GUI
Parameters
----------
stream : file handle
opened file handle
include_channels : bool
also count channels
Returns
-------
count : int
... | [
"count",
"all",
"channel",
"groups",
"as",
"fast",
"as",
"possible",
".",
"This",
"is",
"used",
"to",
"provide",
"reliable",
"progress",
"information",
"when",
"loading",
"a",
"file",
"using",
"the",
"GUI"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/utils.py#L646-L720 | train |
danielhrisca/asammdf | asammdf/blocks/utils.py | validate_version_argument | def validate_version_argument(version, hint=4):
""" validate the version argument against the supported MDF versions. The
default version used depends on the hint MDF major revision
Parameters
----------
version : str
requested MDF version
hint : int
MDF revision hint
Retur... | python | def validate_version_argument(version, hint=4):
""" validate the version argument against the supported MDF versions. The
default version used depends on the hint MDF major revision
Parameters
----------
version : str
requested MDF version
hint : int
MDF revision hint
Retur... | [
"def",
"validate_version_argument",
"(",
"version",
",",
"hint",
"=",
"4",
")",
":",
"if",
"version",
"not",
"in",
"SUPPORTED_VERSIONS",
":",
"if",
"hint",
"==",
"2",
":",
"valid_version",
"=",
"\"2.14\"",
"elif",
"hint",
"==",
"3",
":",
"valid_version",
"... | validate the version argument against the supported MDF versions. The
default version used depends on the hint MDF major revision
Parameters
----------
version : str
requested MDF version
hint : int
MDF revision hint
Returns
-------
valid_version : str
valid ver... | [
"validate",
"the",
"version",
"argument",
"against",
"the",
"supported",
"MDF",
"versions",
".",
"The",
"default",
"version",
"used",
"depends",
"on",
"the",
"hint",
"MDF",
"major",
"revision"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/utils.py#L723-L756 | train |
danielhrisca/asammdf | asammdf/blocks/utils.py | cut_video_stream | def cut_video_stream(stream, start, end, fmt):
""" cut video stream from `start` to `end` time
Parameters
----------
stream : bytes
video file content
start : float
start time
end : float
end time
Returns
-------
result : bytes
content of cut video
... | python | def cut_video_stream(stream, start, end, fmt):
""" cut video stream from `start` to `end` time
Parameters
----------
stream : bytes
video file content
start : float
start time
end : float
end time
Returns
-------
result : bytes
content of cut video
... | [
"def",
"cut_video_stream",
"(",
"stream",
",",
"start",
",",
"end",
",",
"fmt",
")",
":",
"with",
"TemporaryDirectory",
"(",
")",
"as",
"tmp",
":",
"in_file",
"=",
"Path",
"(",
"tmp",
")",
"/",
"f\"in{fmt}\"",
"out_file",
"=",
"Path",
"(",
"tmp",
")",
... | cut video stream from `start` to `end` time
Parameters
----------
stream : bytes
video file content
start : float
start time
end : float
end time
Returns
-------
result : bytes
content of cut video | [
"cut",
"video",
"stream",
"from",
"start",
"to",
"end",
"time"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/utils.py#L878-L926 | train |
danielhrisca/asammdf | asammdf/blocks/utils.py | components | def components(channel, channel_name, unique_names, prefix="", master=None):
""" yield pandas Series and unique name based on the ndarray object
Parameters
----------
channel : numpy.ndarray
channel to be used foir Series
channel_name : str
channel name
unique_names : UniqueDB
... | python | def components(channel, channel_name, unique_names, prefix="", master=None):
""" yield pandas Series and unique name based on the ndarray object
Parameters
----------
channel : numpy.ndarray
channel to be used foir Series
channel_name : str
channel name
unique_names : UniqueDB
... | [
"def",
"components",
"(",
"channel",
",",
"channel_name",
",",
"unique_names",
",",
"prefix",
"=",
"\"\"",
",",
"master",
"=",
"None",
")",
":",
"names",
"=",
"channel",
".",
"dtype",
".",
"names",
"# channel arrays",
"if",
"names",
"[",
"0",
"]",
"==",
... | yield pandas Series and unique name based on the ndarray object
Parameters
----------
channel : numpy.ndarray
channel to be used foir Series
channel_name : str
channel name
unique_names : UniqueDB
unique names object
prefix : str
prefix used in case of nested rec... | [
"yield",
"pandas",
"Series",
"and",
"unique",
"name",
"based",
"on",
"the",
"ndarray",
"object"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/utils.py#L1035-L1104 | train |
danielhrisca/asammdf | asammdf/blocks/utils.py | master_using_raster | def master_using_raster(mdf, raster, endpoint=False):
""" get single master based on the raster
Parameters
----------
mdf : asammdf.MDF
measurement object
raster : float
new raster
endpoint=False : bool
include maximum time stamp in the new master
Returns
------... | python | def master_using_raster(mdf, raster, endpoint=False):
""" get single master based on the raster
Parameters
----------
mdf : asammdf.MDF
measurement object
raster : float
new raster
endpoint=False : bool
include maximum time stamp in the new master
Returns
------... | [
"def",
"master_using_raster",
"(",
"mdf",
",",
"raster",
",",
"endpoint",
"=",
"False",
")",
":",
"if",
"not",
"raster",
":",
"master",
"=",
"np",
".",
"array",
"(",
"[",
"]",
",",
"dtype",
"=",
"'<f8'",
")",
"else",
":",
"t_min",
"=",
"[",
"]",
... | get single master based on the raster
Parameters
----------
mdf : asammdf.MDF
measurement object
raster : float
new raster
endpoint=False : bool
include maximum time stamp in the new master
Returns
-------
master : np.array
new master | [
"get",
"single",
"master",
"based",
"on",
"the",
"raster"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/utils.py#L1178-L1237 | train |
danielhrisca/asammdf | asammdf/blocks/utils.py | ChannelsDB.add | def add(self, channel_name, entry):
""" add name to channels database and check if it contains a source
path
Parameters
----------
channel_name : str
name that needs to be added to the database
entry : tuple
(group index, channel index) pair
... | python | def add(self, channel_name, entry):
""" add name to channels database and check if it contains a source
path
Parameters
----------
channel_name : str
name that needs to be added to the database
entry : tuple
(group index, channel index) pair
... | [
"def",
"add",
"(",
"self",
",",
"channel_name",
",",
"entry",
")",
":",
"if",
"channel_name",
":",
"if",
"channel_name",
"not",
"in",
"self",
":",
"self",
"[",
"channel_name",
"]",
"=",
"[",
"entry",
"]",
"else",
":",
"self",
"[",
"channel_name",
"]",
... | add name to channels database and check if it contains a source
path
Parameters
----------
channel_name : str
name that needs to be added to the database
entry : tuple
(group index, channel index) pair | [
"add",
"name",
"to",
"channels",
"database",
"and",
"check",
"if",
"it",
"contains",
"a",
"source",
"path"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/utils.py#L768-L792 | train |
danielhrisca/asammdf | asammdf/blocks/utils.py | UniqueDB.get_unique_name | def get_unique_name(self, name):
""" returns an available unique name
Parameters
----------
name : str
name to be made unique
Returns
-------
unique_name : str
new unique name
"""
if name not in self._db:
sel... | python | def get_unique_name(self, name):
""" returns an available unique name
Parameters
----------
name : str
name to be made unique
Returns
-------
unique_name : str
new unique name
"""
if name not in self._db:
sel... | [
"def",
"get_unique_name",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"_db",
":",
"self",
".",
"_db",
"[",
"name",
"]",
"=",
"0",
"return",
"name",
"else",
":",
"index",
"=",
"self",
".",
"_db",
"[",
"name",
"]",
... | returns an available unique name
Parameters
----------
name : str
name to be made unique
Returns
-------
unique_name : str
new unique name | [
"returns",
"an",
"available",
"unique",
"name"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/utils.py#L854-L875 | train |
danielhrisca/asammdf | asammdf/mdf.py | MDF.iter_get | def iter_get(
self,
name=None,
group=None,
index=None,
raster=None,
samples_only=False,
raw=False,
):
""" iterator over a channel
This is usefull in case of large files with a small number of channels.
If the *raster* keyword argument... | python | def iter_get(
self,
name=None,
group=None,
index=None,
raster=None,
samples_only=False,
raw=False,
):
""" iterator over a channel
This is usefull in case of large files with a small number of channels.
If the *raster* keyword argument... | [
"def",
"iter_get",
"(",
"self",
",",
"name",
"=",
"None",
",",
"group",
"=",
"None",
",",
"index",
"=",
"None",
",",
"raster",
"=",
"None",
",",
"samples_only",
"=",
"False",
",",
"raw",
"=",
"False",
",",
")",
":",
"gp_nr",
",",
"ch_nr",
"=",
"s... | iterator over a channel
This is usefull in case of large files with a small number of channels.
If the *raster* keyword argument is not *None* the output is
interpolated accordingly
Parameters
----------
name : string
name of channel
group : int
... | [
"iterator",
"over",
"a",
"channel"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/mdf.py#L1770-L1818 | train |
danielhrisca/asammdf | asammdf/mdf.py | MDF.whereis | def whereis(self, channel):
""" get ocurrences of channel name in the file
Parameters
----------
channel : str
channel name string
Returns
-------
ocurrences : tuple
Examples
--------
>>> mdf = MDF(file_name)
>>> mdf... | python | def whereis(self, channel):
""" get ocurrences of channel name in the file
Parameters
----------
channel : str
channel name string
Returns
-------
ocurrences : tuple
Examples
--------
>>> mdf = MDF(file_name)
>>> mdf... | [
"def",
"whereis",
"(",
"self",
",",
"channel",
")",
":",
"if",
"channel",
"in",
"self",
":",
"return",
"tuple",
"(",
"self",
".",
"channels_db",
"[",
"channel",
"]",
")",
"else",
":",
"return",
"tuple",
"(",
")"
] | get ocurrences of channel name in the file
Parameters
----------
channel : str
channel name string
Returns
-------
ocurrences : tuple
Examples
--------
>>> mdf = MDF(file_name)
>>> mdf.whereis('VehicleSpeed') # "VehicleSpeed... | [
"get",
"ocurrences",
"of",
"channel",
"name",
"in",
"the",
"file"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/mdf.py#L2966-L2991 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v4.py | MDF4.get_invalidation_bits | def get_invalidation_bits(self, group_index, channel, fragment):
""" get invalidation indexes for the channel
Parameters
----------
group_index : int
group index
channel : Channel
channel object
fragment : (bytes, int)
(fragment bytes,... | python | def get_invalidation_bits(self, group_index, channel, fragment):
""" get invalidation indexes for the channel
Parameters
----------
group_index : int
group index
channel : Channel
channel object
fragment : (bytes, int)
(fragment bytes,... | [
"def",
"get_invalidation_bits",
"(",
"self",
",",
"group_index",
",",
"channel",
",",
"fragment",
")",
":",
"group",
"=",
"self",
".",
"groups",
"[",
"group_index",
"]",
"dtypes",
"=",
"group",
".",
"types",
"data_bytes",
",",
"offset",
",",
"_count",
"=",... | get invalidation indexes for the channel
Parameters
----------
group_index : int
group index
channel : Channel
channel object
fragment : (bytes, int)
(fragment bytes, fragment offset)
Returns
-------
invalidation_bits ... | [
"get",
"invalidation",
"indexes",
"for",
"the",
"channel"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v4.py#L2182-L2227 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v4.py | MDF4.configure | def configure(
self,
*,
read_fragment_size=None,
write_fragment_size=None,
use_display_names=None,
single_bit_uint_as_bool=None,
integer_interpolation=None,
):
""" configure MDF parameters
Parameters
----------
read_fragment_si... | python | def configure(
self,
*,
read_fragment_size=None,
write_fragment_size=None,
use_display_names=None,
single_bit_uint_as_bool=None,
integer_interpolation=None,
):
""" configure MDF parameters
Parameters
----------
read_fragment_si... | [
"def",
"configure",
"(",
"self",
",",
"*",
",",
"read_fragment_size",
"=",
"None",
",",
"write_fragment_size",
"=",
"None",
",",
"use_display_names",
"=",
"None",
",",
"single_bit_uint_as_bool",
"=",
"None",
",",
"integer_interpolation",
"=",
"None",
",",
")",
... | configure MDF parameters
Parameters
----------
read_fragment_size : int
size hint of split data blocks, default 8MB; if the initial size is
smaller, then no data list is used. The actual split size depends on
the data groups' records size
write_fragme... | [
"configure",
"MDF",
"parameters"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v4.py#L2229-L2276 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v4.py | MDF4.extract_attachment | def extract_attachment(self, address=None, index=None):
""" extract attachment data by original address or by index. If it is an embedded attachment,
then this method creates the new file according to the attachment file
name information
Parameters
----------
address : i... | python | def extract_attachment(self, address=None, index=None):
""" extract attachment data by original address or by index. If it is an embedded attachment,
then this method creates the new file according to the attachment file
name information
Parameters
----------
address : i... | [
"def",
"extract_attachment",
"(",
"self",
",",
"address",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"if",
"address",
"is",
"None",
"and",
"index",
"is",
"None",
":",
"return",
"b\"\"",
",",
"Path",
"(",
"\"\"",
")",
"if",
"address",
"is",
"no... | extract attachment data by original address or by index. If it is an embedded attachment,
then this method creates the new file according to the attachment file
name information
Parameters
----------
address : int
attachment index; default *None*
index : int
... | [
"extract",
"attachment",
"data",
"by",
"original",
"address",
"or",
"by",
"index",
".",
"If",
"it",
"is",
"an",
"embedded",
"attachment",
"then",
"this",
"method",
"creates",
"the",
"new",
"file",
"according",
"to",
"the",
"attachment",
"file",
"name",
"info... | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v4.py#L3567-L3637 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v4.py | MDF4.get_channel_name | def get_channel_name(self, group, index):
"""Gets channel name.
Parameters
----------
group : int
0-based group index
index : int
0-based channel index
Returns
-------
name : str
found channel name
"""
... | python | def get_channel_name(self, group, index):
"""Gets channel name.
Parameters
----------
group : int
0-based group index
index : int
0-based channel index
Returns
-------
name : str
found channel name
"""
... | [
"def",
"get_channel_name",
"(",
"self",
",",
"group",
",",
"index",
")",
":",
"gp_nr",
",",
"ch_nr",
"=",
"self",
".",
"_validate_channel_selection",
"(",
"None",
",",
"group",
",",
"index",
")",
"return",
"self",
".",
"groups",
"[",
"gp_nr",
"]",
".",
... | Gets channel name.
Parameters
----------
group : int
0-based group index
index : int
0-based channel index
Returns
-------
name : str
found channel name | [
"Gets",
"channel",
"name",
"."
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v4.py#L5803-L5821 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v4.py | MDF4.get_channel_unit | def get_channel_unit(self, name=None, group=None, index=None):
"""Gets channel unit.
Channel can be specified in two ways:
* using the first positional argument *name*
* if there are multiple occurrences for this channel then the
*group* and *index* arguments can be ... | python | def get_channel_unit(self, name=None, group=None, index=None):
"""Gets channel unit.
Channel can be specified in two ways:
* using the first positional argument *name*
* if there are multiple occurrences for this channel then the
*group* and *index* arguments can be ... | [
"def",
"get_channel_unit",
"(",
"self",
",",
"name",
"=",
"None",
",",
"group",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"gp_nr",
",",
"ch_nr",
"=",
"self",
".",
"_validate_channel_selection",
"(",
"name",
",",
"group",
",",
"index",
")",
"grp... | Gets channel unit.
Channel can be specified in two ways:
* using the first positional argument *name*
* if there are multiple occurrences for this channel then the
*group* and *index* arguments can be used to select a specific
group.
* if there are ... | [
"Gets",
"channel",
"unit",
"."
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v4.py#L5835-L5881 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v4.py | MDF4.get_channel_comment | def get_channel_comment(self, name=None, group=None, index=None):
"""Gets channel comment.
Channel can be specified in two ways:
* using the first positional argument *name*
* if there are multiple occurrences for this channel then the
*group* and *index* arguments c... | python | def get_channel_comment(self, name=None, group=None, index=None):
"""Gets channel comment.
Channel can be specified in two ways:
* using the first positional argument *name*
* if there are multiple occurrences for this channel then the
*group* and *index* arguments c... | [
"def",
"get_channel_comment",
"(",
"self",
",",
"name",
"=",
"None",
",",
"group",
"=",
"None",
",",
"index",
"=",
"None",
")",
":",
"gp_nr",
",",
"ch_nr",
"=",
"self",
".",
"_validate_channel_selection",
"(",
"name",
",",
"group",
",",
"index",
")",
"... | Gets channel comment.
Channel can be specified in two ways:
* using the first positional argument *name*
* if there are multiple occurrences for this channel then the
*group* and *index* arguments can be used to select a specific
group.
* if there a... | [
"Gets",
"channel",
"comment",
"."
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v4.py#L5883-L5925 | train |
danielhrisca/asammdf | benchmarks/bench.py | _cmd_line_parser | def _cmd_line_parser():
'''
return a command line parser. It is used when generating the documentation
'''
parser = argparse.ArgumentParser()
parser.add_argument('--path',
help=('path to test files, '
'if not provided the script folder is used')... | python | def _cmd_line_parser():
'''
return a command line parser. It is used when generating the documentation
'''
parser = argparse.ArgumentParser()
parser.add_argument('--path',
help=('path to test files, '
'if not provided the script folder is used')... | [
"def",
"_cmd_line_parser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'--path'",
",",
"help",
"=",
"(",
"'path to test files, '",
"'if not provided the script folder is used'",
")",
")",
"parser",
... | return a command line parser. It is used when generating the documentation | [
"return",
"a",
"command",
"line",
"parser",
".",
"It",
"is",
"used",
"when",
"generating",
"the",
"documentation"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/benchmarks/bench.py#L1100-L1118 | train |
danielhrisca/asammdf | benchmarks/bench.py | MyList.append | def append(self, item):
""" append item and print it to stdout """
print(item)
super(MyList, self).append(item) | python | def append(self, item):
""" append item and print it to stdout """
print(item)
super(MyList, self).append(item) | [
"def",
"append",
"(",
"self",
",",
"item",
")",
":",
"print",
"(",
"item",
")",
"super",
"(",
"MyList",
",",
"self",
")",
".",
"append",
"(",
"item",
")"
] | append item and print it to stdout | [
"append",
"item",
"and",
"print",
"it",
"to",
"stdout"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/benchmarks/bench.py#L42-L45 | train |
danielhrisca/asammdf | benchmarks/bench.py | MyList.extend | def extend(self, items):
""" extend items and print them to stdout
using the new line separator
"""
print('\n'.join(items))
super(MyList, self).extend(items) | python | def extend(self, items):
""" extend items and print them to stdout
using the new line separator
"""
print('\n'.join(items))
super(MyList, self).extend(items) | [
"def",
"extend",
"(",
"self",
",",
"items",
")",
":",
"print",
"(",
"'\\n'",
".",
"join",
"(",
"items",
")",
")",
"super",
"(",
"MyList",
",",
"self",
")",
".",
"extend",
"(",
"items",
")"
] | extend items and print them to stdout
using the new line separator | [
"extend",
"items",
"and",
"print",
"them",
"to",
"stdout",
"using",
"the",
"new",
"line",
"separator"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/benchmarks/bench.py#L47-L52 | train |
danielhrisca/asammdf | asammdf/signal.py | Signal.extend | def extend(self, other):
""" extend signal with samples from another signal
Parameters
----------
other : Signal
Returns
-------
signal : Signal
new extended *Signal*
"""
if len(self.timestamps):
last_stamp = self.timesta... | python | def extend(self, other):
""" extend signal with samples from another signal
Parameters
----------
other : Signal
Returns
-------
signal : Signal
new extended *Signal*
"""
if len(self.timestamps):
last_stamp = self.timesta... | [
"def",
"extend",
"(",
"self",
",",
"other",
")",
":",
"if",
"len",
"(",
"self",
".",
"timestamps",
")",
":",
"last_stamp",
"=",
"self",
".",
"timestamps",
"[",
"-",
"1",
"]",
"else",
":",
"last_stamp",
"=",
"0",
"if",
"len",
"(",
"other",
")",
":... | extend signal with samples from another signal
Parameters
----------
other : Signal
Returns
-------
signal : Signal
new extended *Signal* | [
"extend",
"signal",
"with",
"samples",
"from",
"another",
"signal"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/signal.py#L670-L729 | train |
danielhrisca/asammdf | asammdf/signal.py | Signal.physical | def physical(self):
"""
get the physical samples values
Returns
-------
phys : Signal
new *Signal* with physical values
"""
if not self.raw or self.conversion is None:
samples = self.samples.copy()
else:
samples = sel... | python | def physical(self):
"""
get the physical samples values
Returns
-------
phys : Signal
new *Signal* with physical values
"""
if not self.raw or self.conversion is None:
samples = self.samples.copy()
else:
samples = sel... | [
"def",
"physical",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"raw",
"or",
"self",
".",
"conversion",
"is",
"None",
":",
"samples",
"=",
"self",
".",
"samples",
".",
"copy",
"(",
")",
"else",
":",
"samples",
"=",
"self",
".",
"conversion",
".... | get the physical samples values
Returns
-------
phys : Signal
new *Signal* with physical values | [
"get",
"the",
"physical",
"samples",
"values"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/signal.py#L1094-L1124 | train |
danielhrisca/asammdf | asammdf/blocks/v4_blocks.py | AttachmentBlock.extract | def extract(self):
"""extract attachment data
Returns
-------
data : bytes
"""
if self.flags & v4c.FLAG_AT_EMBEDDED:
if self.flags & v4c.FLAG_AT_COMPRESSED_EMBEDDED:
data = decompress(self.embedded_data)
else:
data ... | python | def extract(self):
"""extract attachment data
Returns
-------
data : bytes
"""
if self.flags & v4c.FLAG_AT_EMBEDDED:
if self.flags & v4c.FLAG_AT_COMPRESSED_EMBEDDED:
data = decompress(self.embedded_data)
else:
data ... | [
"def",
"extract",
"(",
"self",
")",
":",
"if",
"self",
".",
"flags",
"&",
"v4c",
".",
"FLAG_AT_EMBEDDED",
":",
"if",
"self",
".",
"flags",
"&",
"v4c",
".",
"FLAG_AT_COMPRESSED_EMBEDDED",
":",
"data",
"=",
"decompress",
"(",
"self",
".",
"embedded_data",
... | extract attachment data
Returns
-------
data : bytes | [
"extract",
"attachment",
"data"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/v4_blocks.py#L236-L260 | train |
danielhrisca/asammdf | asammdf/blocks/v4_blocks.py | HeaderBlock.start_time | def start_time(self):
""" getter and setter the measurement start timestamp
Returns
-------
timestamp : datetime.datetime
start timestamp
"""
timestamp = self.abs_time / 10 ** 9
if self.time_flags & v4c.FLAG_HD_LOCAL_TIME:
timestamp = da... | python | def start_time(self):
""" getter and setter the measurement start timestamp
Returns
-------
timestamp : datetime.datetime
start timestamp
"""
timestamp = self.abs_time / 10 ** 9
if self.time_flags & v4c.FLAG_HD_LOCAL_TIME:
timestamp = da... | [
"def",
"start_time",
"(",
"self",
")",
":",
"timestamp",
"=",
"self",
".",
"abs_time",
"/",
"10",
"**",
"9",
"if",
"self",
".",
"time_flags",
"&",
"v4c",
".",
"FLAG_HD_LOCAL_TIME",
":",
"timestamp",
"=",
"datetime",
".",
"fromtimestamp",
"(",
"timestamp",
... | getter and setter the measurement start timestamp
Returns
-------
timestamp : datetime.datetime
start timestamp | [
"getter",
"and",
"setter",
"the",
"measurement",
"start",
"timestamp"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/v4_blocks.py#L4366-L4382 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v3.py | MDF3._prepare_record | def _prepare_record(self, group):
""" compute record dtype and parents dict for this group
Parameters
----------
group : dict
MDF group dict
Returns
-------
parents, dtypes : dict, numpy.dtype
mapping of channels to records fields, record... | python | def _prepare_record(self, group):
""" compute record dtype and parents dict for this group
Parameters
----------
group : dict
MDF group dict
Returns
-------
parents, dtypes : dict, numpy.dtype
mapping of channels to records fields, record... | [
"def",
"_prepare_record",
"(",
"self",
",",
"group",
")",
":",
"parents",
",",
"dtypes",
"=",
"group",
".",
"parents",
",",
"group",
".",
"types",
"if",
"parents",
"is",
"None",
":",
"if",
"group",
".",
"data_location",
"==",
"v23c",
".",
"LOCATION_ORIGI... | compute record dtype and parents dict for this group
Parameters
----------
group : dict
MDF group dict
Returns
-------
parents, dtypes : dict, numpy.dtype
mapping of channels to records fields, records fiels dtype | [
"compute",
"record",
"dtype",
"and",
"parents",
"dict",
"for",
"this",
"group"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v3.py#L346-L475 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v3.py | MDF3.close | def close(self):
""" if the MDF was created with memory='minimum' and new
channels have been appended, then this must be called just before the
object is not used anymore to clean-up the temporary file
"""
if self._tempfile is not None:
self._tempfile.close()
... | python | def close(self):
""" if the MDF was created with memory='minimum' and new
channels have been appended, then this must be called just before the
object is not used anymore to clean-up the temporary file
"""
if self._tempfile is not None:
self._tempfile.close()
... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_tempfile",
"is",
"not",
"None",
":",
"self",
".",
"_tempfile",
".",
"close",
"(",
")",
"if",
"self",
".",
"_file",
"is",
"not",
"None",
"and",
"not",
"self",
".",
"_from_filelike",
":",
"s... | if the MDF was created with memory='minimum' and new
channels have been appended, then this must be called just before the
object is not used anymore to clean-up the temporary file | [
"if",
"the",
"MDF",
"was",
"created",
"with",
"memory",
"=",
"minimum",
"and",
"new",
"channels",
"have",
"been",
"appended",
"then",
"this",
"must",
"be",
"called",
"just",
"before",
"the",
"object",
"is",
"not",
"used",
"anymore",
"to",
"clean",
"-",
"... | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v3.py#L2114-L2123 | train |
danielhrisca/asammdf | asammdf/blocks/mdf_v3.py | MDF3.iter_get_triggers | def iter_get_triggers(self):
""" generator that yields triggers
Returns
-------
trigger_info : dict
trigger information with the following keys:
* comment : trigger comment
* time : trigger time
* pre_time : trigger pre time
... | python | def iter_get_triggers(self):
""" generator that yields triggers
Returns
-------
trigger_info : dict
trigger information with the following keys:
* comment : trigger comment
* time : trigger time
* pre_time : trigger pre time
... | [
"def",
"iter_get_triggers",
"(",
"self",
")",
":",
"for",
"i",
",",
"gp",
"in",
"enumerate",
"(",
"self",
".",
"groups",
")",
":",
"trigger",
"=",
"gp",
".",
"trigger",
"if",
"trigger",
":",
"for",
"j",
"in",
"range",
"(",
"trigger",
"[",
"\"trigger_... | generator that yields triggers
Returns
-------
trigger_info : dict
trigger information with the following keys:
* comment : trigger comment
* time : trigger time
* pre_time : trigger pre time
* post_time : trigger post... | [
"generator",
"that",
"yields",
"triggers"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/blocks/mdf_v3.py#L3069-L3097 | train |
danielhrisca/asammdf | asammdf/gui/widgets/formated_axis.py | FormatedAxis.setLabel | def setLabel(self, text=None, units=None, unitPrefix=None, **args):
""" overwrites pyqtgraph setLabel
"""
show_label = False
if text is not None:
self.labelText = text
show_label = True
if units is not None:
self.labelUnits = units
... | python | def setLabel(self, text=None, units=None, unitPrefix=None, **args):
""" overwrites pyqtgraph setLabel
"""
show_label = False
if text is not None:
self.labelText = text
show_label = True
if units is not None:
self.labelUnits = units
... | [
"def",
"setLabel",
"(",
"self",
",",
"text",
"=",
"None",
",",
"units",
"=",
"None",
",",
"unitPrefix",
"=",
"None",
",",
"*",
"*",
"args",
")",
":",
"show_label",
"=",
"False",
"if",
"text",
"is",
"not",
"None",
":",
"self",
".",
"labelText",
"=",... | overwrites pyqtgraph setLabel | [
"overwrites",
"pyqtgraph",
"setLabel"
] | 3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66 | https://github.com/danielhrisca/asammdf/blob/3c7a1fd19c957ceebe4dcdbb2abf00806c2bdb66/asammdf/gui/widgets/formated_axis.py#L52-L72 | train |
bernardopires/django-tenant-schemas | tenant_schemas/utils.py | clean_tenant_url | def clean_tenant_url(url_string):
"""
Removes the TENANT_TOKEN from a particular string
"""
if hasattr(settings, 'PUBLIC_SCHEMA_URLCONF'):
if (settings.PUBLIC_SCHEMA_URLCONF and
url_string.startswith(settings.PUBLIC_SCHEMA_URLCONF)):
url_string = url_string[len(settin... | python | def clean_tenant_url(url_string):
"""
Removes the TENANT_TOKEN from a particular string
"""
if hasattr(settings, 'PUBLIC_SCHEMA_URLCONF'):
if (settings.PUBLIC_SCHEMA_URLCONF and
url_string.startswith(settings.PUBLIC_SCHEMA_URLCONF)):
url_string = url_string[len(settin... | [
"def",
"clean_tenant_url",
"(",
"url_string",
")",
":",
"if",
"hasattr",
"(",
"settings",
",",
"'PUBLIC_SCHEMA_URLCONF'",
")",
":",
"if",
"(",
"settings",
".",
"PUBLIC_SCHEMA_URLCONF",
"and",
"url_string",
".",
"startswith",
"(",
"settings",
".",
"PUBLIC_SCHEMA_UR... | Removes the TENANT_TOKEN from a particular string | [
"Removes",
"the",
"TENANT_TOKEN",
"from",
"a",
"particular",
"string"
] | 75faf00834e1fb7ed017949bfb54531f6329a8dd | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/utils.py#L53-L61 | train |
bernardopires/django-tenant-schemas | tenant_schemas/utils.py | app_labels | def app_labels(apps_list):
"""
Returns a list of app labels of the given apps_list, now properly handles
new Django 1.7+ application registry.
https://docs.djangoproject.com/en/1.8/ref/applications/#django.apps.AppConfig.label
"""
if AppConfig is None:
return [app.split('.')[-1] for ap... | python | def app_labels(apps_list):
"""
Returns a list of app labels of the given apps_list, now properly handles
new Django 1.7+ application registry.
https://docs.djangoproject.com/en/1.8/ref/applications/#django.apps.AppConfig.label
"""
if AppConfig is None:
return [app.split('.')[-1] for ap... | [
"def",
"app_labels",
"(",
"apps_list",
")",
":",
"if",
"AppConfig",
"is",
"None",
":",
"return",
"[",
"app",
".",
"split",
"(",
"'.'",
")",
"[",
"-",
"1",
"]",
"for",
"app",
"in",
"apps_list",
"]",
"return",
"[",
"AppConfig",
".",
"create",
"(",
"a... | Returns a list of app labels of the given apps_list, now properly handles
new Django 1.7+ application registry.
https://docs.djangoproject.com/en/1.8/ref/applications/#django.apps.AppConfig.label | [
"Returns",
"a",
"list",
"of",
"app",
"labels",
"of",
"the",
"given",
"apps_list",
"now",
"properly",
"handles",
"new",
"Django",
"1",
".",
"7",
"+",
"application",
"registry",
"."
] | 75faf00834e1fb7ed017949bfb54531f6329a8dd | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/utils.py#L109-L118 | train |
bernardopires/django-tenant-schemas | tenant_schemas/storage.py | TenantStorageMixin.path | def path(self, name):
"""
Look for files in subdirectory of MEDIA_ROOT using the tenant's
domain_url value as the specifier.
"""
if name is None:
name = ''
try:
location = safe_join(self.location, connection.tenant.domain_url)
except Attrib... | python | def path(self, name):
"""
Look for files in subdirectory of MEDIA_ROOT using the tenant's
domain_url value as the specifier.
"""
if name is None:
name = ''
try:
location = safe_join(self.location, connection.tenant.domain_url)
except Attrib... | [
"def",
"path",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"''",
"try",
":",
"location",
"=",
"safe_join",
"(",
"self",
".",
"location",
",",
"connection",
".",
"tenant",
".",
"domain_url",
")",
"except",
"Attrib... | Look for files in subdirectory of MEDIA_ROOT using the tenant's
domain_url value as the specifier. | [
"Look",
"for",
"files",
"in",
"subdirectory",
"of",
"MEDIA_ROOT",
"using",
"the",
"tenant",
"s",
"domain_url",
"value",
"as",
"the",
"specifier",
"."
] | 75faf00834e1fb7ed017949bfb54531f6329a8dd | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/storage.py#L27-L43 | train |
bernardopires/django-tenant-schemas | tenant_schemas/management/commands/tenant_command.py | Command.run_from_argv | def run_from_argv(self, argv):
"""
Changes the option_list to use the options from the wrapped command.
Adds schema parameter to specify which schema will be used when
executing the wrapped command.
"""
# load the command object.
try:
app_name = get_co... | python | def run_from_argv(self, argv):
"""
Changes the option_list to use the options from the wrapped command.
Adds schema parameter to specify which schema will be used when
executing the wrapped command.
"""
# load the command object.
try:
app_name = get_co... | [
"def",
"run_from_argv",
"(",
"self",
",",
"argv",
")",
":",
"# load the command object.",
"try",
":",
"app_name",
"=",
"get_commands",
"(",
")",
"[",
"argv",
"[",
"2",
"]",
"]",
"except",
"KeyError",
":",
"raise",
"CommandError",
"(",
"\"Unknown command: %r\""... | Changes the option_list to use the options from the wrapped command.
Adds schema parameter to specify which schema will be used when
executing the wrapped command. | [
"Changes",
"the",
"option_list",
"to",
"use",
"the",
"options",
"from",
"the",
"wrapped",
"command",
".",
"Adds",
"schema",
"parameter",
"to",
"specify",
"which",
"schema",
"will",
"be",
"used",
"when",
"executing",
"the",
"wrapped",
"command",
"."
] | 75faf00834e1fb7ed017949bfb54531f6329a8dd | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/management/commands/tenant_command.py#L11-L38 | train |
bernardopires/django-tenant-schemas | tenant_schemas/management/commands/__init__.py | BaseTenantCommand.handle | def handle(self, *args, **options):
"""
Iterates a command over all registered schemata.
"""
if options['schema_name']:
# only run on a particular schema
connection.set_schema_to_public()
self.execute_command(get_tenant_model().objects.get(schema_name=... | python | def handle(self, *args, **options):
"""
Iterates a command over all registered schemata.
"""
if options['schema_name']:
# only run on a particular schema
connection.set_schema_to_public()
self.execute_command(get_tenant_model().objects.get(schema_name=... | [
"def",
"handle",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"if",
"options",
"[",
"'schema_name'",
"]",
":",
"# only run on a particular schema",
"connection",
".",
"set_schema_to_public",
"(",
")",
"self",
".",
"execute_command",
"(",
... | Iterates a command over all registered schemata. | [
"Iterates",
"a",
"command",
"over",
"all",
"registered",
"schemata",
"."
] | 75faf00834e1fb7ed017949bfb54531f6329a8dd | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/management/commands/__init__.py#L69-L81 | train |
bernardopires/django-tenant-schemas | tenant_schemas/postgresql_backend/base.py | DatabaseWrapper._cursor | def _cursor(self, name=None):
"""
Here it happens. We hope every Django db operation using PostgreSQL
must go through this to get the cursor handle. We change the path.
"""
if name:
# Only supported and required by Django 1.11 (server-side cursor)
cursor =... | python | def _cursor(self, name=None):
"""
Here it happens. We hope every Django db operation using PostgreSQL
must go through this to get the cursor handle. We change the path.
"""
if name:
# Only supported and required by Django 1.11 (server-side cursor)
cursor =... | [
"def",
"_cursor",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
":",
"# Only supported and required by Django 1.11 (server-side cursor)",
"cursor",
"=",
"super",
"(",
"DatabaseWrapper",
",",
"self",
")",
".",
"_cursor",
"(",
"name",
"=",
"name",... | Here it happens. We hope every Django db operation using PostgreSQL
must go through this to get the cursor handle. We change the path. | [
"Here",
"it",
"happens",
".",
"We",
"hope",
"every",
"Django",
"db",
"operation",
"using",
"PostgreSQL",
"must",
"go",
"through",
"this",
"to",
"get",
"the",
"cursor",
"handle",
".",
"We",
"change",
"the",
"path",
"."
] | 75faf00834e1fb7ed017949bfb54531f6329a8dd | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/postgresql_backend/base.py#L112-L166 | train |
bernardopires/django-tenant-schemas | tenant_schemas/apps.py | best_practice | def best_practice(app_configs, **kwargs):
"""
Test for configuration recommendations. These are best practices, they
avoid hard to find bugs and unexpected behaviour.
"""
if app_configs is None:
app_configs = apps.get_app_configs()
# Take the app_configs and turn them into *old style* a... | python | def best_practice(app_configs, **kwargs):
"""
Test for configuration recommendations. These are best practices, they
avoid hard to find bugs and unexpected behaviour.
"""
if app_configs is None:
app_configs = apps.get_app_configs()
# Take the app_configs and turn them into *old style* a... | [
"def",
"best_practice",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"app_configs",
"is",
"None",
":",
"app_configs",
"=",
"apps",
".",
"get_app_configs",
"(",
")",
"# Take the app_configs and turn them into *old style* application names.",
"# This is wh... | Test for configuration recommendations. These are best practices, they
avoid hard to find bugs and unexpected behaviour. | [
"Test",
"for",
"configuration",
"recommendations",
".",
"These",
"are",
"best",
"practices",
"they",
"avoid",
"hard",
"to",
"find",
"bugs",
"and",
"unexpected",
"behaviour",
"."
] | 75faf00834e1fb7ed017949bfb54531f6329a8dd | https://github.com/bernardopires/django-tenant-schemas/blob/75faf00834e1fb7ed017949bfb54531f6329a8dd/tenant_schemas/apps.py#L14-L104 | train |
google/openhtf | openhtf/plugs/device_wrapping.py | short_repr | def short_repr(obj, max_len=40):
"""Returns a short, term-friendly string representation of the object.
Args:
obj: An object for which to return a string representation.
max_len: Maximum length of the returned string. Longer reprs will be turned
into a brief descriptive string giving the type and l... | python | def short_repr(obj, max_len=40):
"""Returns a short, term-friendly string representation of the object.
Args:
obj: An object for which to return a string representation.
max_len: Maximum length of the returned string. Longer reprs will be turned
into a brief descriptive string giving the type and l... | [
"def",
"short_repr",
"(",
"obj",
",",
"max_len",
"=",
"40",
")",
":",
"obj_repr",
"=",
"repr",
"(",
"obj",
")",
"if",
"len",
"(",
"obj_repr",
")",
"<=",
"max_len",
":",
"return",
"obj_repr",
"return",
"'<{} of length {}>'",
".",
"format",
"(",
"type",
... | Returns a short, term-friendly string representation of the object.
Args:
obj: An object for which to return a string representation.
max_len: Maximum length of the returned string. Longer reprs will be turned
into a brief descriptive string giving the type and length of obj. | [
"Returns",
"a",
"short",
"term",
"-",
"friendly",
"string",
"representation",
"of",
"the",
"object",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/device_wrapping.py#L29-L40 | train |
google/openhtf | openhtf/core/measurements.py | measures | def measures(*measurements, **kwargs):
"""Decorator-maker used to declare measurements for phases.
See the measurements module docstring for examples of usage.
Args:
measurements: Measurement objects to declare, or a string name from which
to create a Measurement.
kwargs: Keyword arguments to pa... | python | def measures(*measurements, **kwargs):
"""Decorator-maker used to declare measurements for phases.
See the measurements module docstring for examples of usage.
Args:
measurements: Measurement objects to declare, or a string name from which
to create a Measurement.
kwargs: Keyword arguments to pa... | [
"def",
"measures",
"(",
"*",
"measurements",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"_maybe_make",
"(",
"meas",
")",
":",
"\"\"\"Turn strings into Measurement objects if necessary.\"\"\"",
"if",
"isinstance",
"(",
"meas",
",",
"Measurement",
")",
":",
"return",... | Decorator-maker used to declare measurements for phases.
See the measurements module docstring for examples of usage.
Args:
measurements: Measurement objects to declare, or a string name from which
to create a Measurement.
kwargs: Keyword arguments to pass to Measurement constructor if we're
... | [
"Decorator",
"-",
"maker",
"used",
"to",
"declare",
"measurements",
"for",
"phases",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L614-L662 | train |
google/openhtf | openhtf/core/measurements.py | Measurement.set_notification_callback | def set_notification_callback(self, notification_cb):
"""Set the notifier we'll call when measurements are set."""
self._notification_cb = notification_cb
if not notification_cb and self.dimensions:
self.measured_value.notify_value_set = None
return self | python | def set_notification_callback(self, notification_cb):
"""Set the notifier we'll call when measurements are set."""
self._notification_cb = notification_cb
if not notification_cb and self.dimensions:
self.measured_value.notify_value_set = None
return self | [
"def",
"set_notification_callback",
"(",
"self",
",",
"notification_cb",
")",
":",
"self",
".",
"_notification_cb",
"=",
"notification_cb",
"if",
"not",
"notification_cb",
"and",
"self",
".",
"dimensions",
":",
"self",
".",
"measured_value",
".",
"notify_value_set",... | Set the notifier we'll call when measurements are set. | [
"Set",
"the",
"notifier",
"we",
"ll",
"call",
"when",
"measurements",
"are",
"set",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L171-L176 | train |
google/openhtf | openhtf/core/measurements.py | Measurement._maybe_make_unit_desc | def _maybe_make_unit_desc(self, unit_desc):
"""Return the UnitDescriptor or convert a string to one."""
if isinstance(unit_desc, str) or unit_desc is None:
unit_desc = units.Unit(unit_desc)
if not isinstance(unit_desc, units.UnitDescriptor):
raise TypeError('Invalid units for measurement %s: %s'... | python | def _maybe_make_unit_desc(self, unit_desc):
"""Return the UnitDescriptor or convert a string to one."""
if isinstance(unit_desc, str) or unit_desc is None:
unit_desc = units.Unit(unit_desc)
if not isinstance(unit_desc, units.UnitDescriptor):
raise TypeError('Invalid units for measurement %s: %s'... | [
"def",
"_maybe_make_unit_desc",
"(",
"self",
",",
"unit_desc",
")",
":",
"if",
"isinstance",
"(",
"unit_desc",
",",
"str",
")",
"or",
"unit_desc",
"is",
"None",
":",
"unit_desc",
"=",
"units",
".",
"Unit",
"(",
"unit_desc",
")",
"if",
"not",
"isinstance",
... | Return the UnitDescriptor or convert a string to one. | [
"Return",
"the",
"UnitDescriptor",
"or",
"convert",
"a",
"string",
"to",
"one",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L191-L198 | train |
google/openhtf | openhtf/core/measurements.py | Measurement._maybe_make_dimension | def _maybe_make_dimension(self, dimension):
"""Return a `measurements.Dimension` instance."""
# For backwards compatibility the argument can be either a Dimension, a
# string or a `units.UnitDescriptor`.
if isinstance(dimension, Dimension):
return dimension
if isinstance(dimension, units.UnitD... | python | def _maybe_make_dimension(self, dimension):
"""Return a `measurements.Dimension` instance."""
# For backwards compatibility the argument can be either a Dimension, a
# string or a `units.UnitDescriptor`.
if isinstance(dimension, Dimension):
return dimension
if isinstance(dimension, units.UnitD... | [
"def",
"_maybe_make_dimension",
"(",
"self",
",",
"dimension",
")",
":",
"# For backwards compatibility the argument can be either a Dimension, a",
"# string or a `units.UnitDescriptor`.",
"if",
"isinstance",
"(",
"dimension",
",",
"Dimension",
")",
":",
"return",
"dimension",
... | Return a `measurements.Dimension` instance. | [
"Return",
"a",
"measurements",
".",
"Dimension",
"instance",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L200-L211 | train |
google/openhtf | openhtf/core/measurements.py | Measurement.with_dimensions | def with_dimensions(self, *dimensions):
"""Declare dimensions for this Measurement, returns self for chaining."""
self.dimensions = tuple(
self._maybe_make_dimension(dim) for dim in dimensions)
self._cached = None
return self | python | def with_dimensions(self, *dimensions):
"""Declare dimensions for this Measurement, returns self for chaining."""
self.dimensions = tuple(
self._maybe_make_dimension(dim) for dim in dimensions)
self._cached = None
return self | [
"def",
"with_dimensions",
"(",
"self",
",",
"*",
"dimensions",
")",
":",
"self",
".",
"dimensions",
"=",
"tuple",
"(",
"self",
".",
"_maybe_make_dimension",
"(",
"dim",
")",
"for",
"dim",
"in",
"dimensions",
")",
"self",
".",
"_cached",
"=",
"None",
"ret... | Declare dimensions for this Measurement, returns self for chaining. | [
"Declare",
"dimensions",
"for",
"this",
"Measurement",
"returns",
"self",
"for",
"chaining",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L218-L223 | train |
google/openhtf | openhtf/core/measurements.py | Measurement.with_validator | def with_validator(self, validator):
"""Add a validator callback to this Measurement, chainable."""
if not callable(validator):
raise ValueError('Validator must be callable', validator)
self.validators.append(validator)
self._cached = None
return self | python | def with_validator(self, validator):
"""Add a validator callback to this Measurement, chainable."""
if not callable(validator):
raise ValueError('Validator must be callable', validator)
self.validators.append(validator)
self._cached = None
return self | [
"def",
"with_validator",
"(",
"self",
",",
"validator",
")",
":",
"if",
"not",
"callable",
"(",
"validator",
")",
":",
"raise",
"ValueError",
"(",
"'Validator must be callable'",
",",
"validator",
")",
"self",
".",
"validators",
".",
"append",
"(",
"validator"... | Add a validator callback to this Measurement, chainable. | [
"Add",
"a",
"validator",
"callback",
"to",
"this",
"Measurement",
"chainable",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L225-L231 | train |
google/openhtf | openhtf/core/measurements.py | Measurement.with_args | def with_args(self, **kwargs):
"""String substitution for names and docstrings."""
validators = [
validator.with_args(**kwargs)
if hasattr(validator, 'with_args') else validator
for validator in self.validators
]
return mutablerecords.CopyRecord(
self, name=util.format_st... | python | def with_args(self, **kwargs):
"""String substitution for names and docstrings."""
validators = [
validator.with_args(**kwargs)
if hasattr(validator, 'with_args') else validator
for validator in self.validators
]
return mutablerecords.CopyRecord(
self, name=util.format_st... | [
"def",
"with_args",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"validators",
"=",
"[",
"validator",
".",
"with_args",
"(",
"*",
"*",
"kwargs",
")",
"if",
"hasattr",
"(",
"validator",
",",
"'with_args'",
")",
"else",
"validator",
"for",
"validator",
... | String substitution for names and docstrings. | [
"String",
"substitution",
"for",
"names",
"and",
"docstrings",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L233-L245 | train |
google/openhtf | openhtf/core/measurements.py | Measurement.validate | def validate(self):
"""Validate this measurement and update its 'outcome' field."""
# PASS if all our validators return True, otherwise FAIL.
try:
if all(v(self.measured_value.value) for v in self.validators):
self.outcome = Outcome.PASS
else:
self.outcome = Outcome.FAIL
re... | python | def validate(self):
"""Validate this measurement and update its 'outcome' field."""
# PASS if all our validators return True, otherwise FAIL.
try:
if all(v(self.measured_value.value) for v in self.validators):
self.outcome = Outcome.PASS
else:
self.outcome = Outcome.FAIL
re... | [
"def",
"validate",
"(",
"self",
")",
":",
"# PASS if all our validators return True, otherwise FAIL.",
"try",
":",
"if",
"all",
"(",
"v",
"(",
"self",
".",
"measured_value",
".",
"value",
")",
"for",
"v",
"in",
"self",
".",
"validators",
")",
":",
"self",
".... | Validate this measurement and update its 'outcome' field. | [
"Validate",
"this",
"measurement",
"and",
"update",
"its",
"outcome",
"field",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L260-L276 | train |
google/openhtf | openhtf/core/measurements.py | Measurement.as_base_types | def as_base_types(self):
"""Convert this measurement to a dict of basic types."""
if not self._cached:
# Create the single cache file the first time this is called.
self._cached = {
'name': self.name,
'outcome': self.outcome.name,
}
if self.validators:
self._c... | python | def as_base_types(self):
"""Convert this measurement to a dict of basic types."""
if not self._cached:
# Create the single cache file the first time this is called.
self._cached = {
'name': self.name,
'outcome': self.outcome.name,
}
if self.validators:
self._c... | [
"def",
"as_base_types",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_cached",
":",
"# Create the single cache file the first time this is called.",
"self",
".",
"_cached",
"=",
"{",
"'name'",
":",
"self",
".",
"name",
",",
"'outcome'",
":",
"self",
".",
... | Convert this measurement to a dict of basic types. | [
"Convert",
"this",
"measurement",
"to",
"a",
"dict",
"of",
"basic",
"types",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L278-L297 | train |
google/openhtf | openhtf/core/measurements.py | Measurement.to_dataframe | def to_dataframe(self, columns=None):
"""Convert a multi-dim to a pandas dataframe."""
if not isinstance(self.measured_value, DimensionedMeasuredValue):
raise TypeError(
'Only a dimensioned measurement can be converted to a DataFrame')
if columns is None:
columns = [d.name for d in self... | python | def to_dataframe(self, columns=None):
"""Convert a multi-dim to a pandas dataframe."""
if not isinstance(self.measured_value, DimensionedMeasuredValue):
raise TypeError(
'Only a dimensioned measurement can be converted to a DataFrame')
if columns is None:
columns = [d.name for d in self... | [
"def",
"to_dataframe",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"measured_value",
",",
"DimensionedMeasuredValue",
")",
":",
"raise",
"TypeError",
"(",
"'Only a dimensioned measurement can be converted to a DataF... | Convert a multi-dim to a pandas dataframe. | [
"Convert",
"a",
"multi",
"-",
"dim",
"to",
"a",
"pandas",
"dataframe",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L299-L311 | train |
google/openhtf | openhtf/core/measurements.py | MeasuredValue.set | def set(self, value):
"""Set the value for this measurement, with some sanity checks."""
if self.is_value_set:
# While we want to *allow* re-setting previously set measurements, we'd
# rather promote the use of multidimensional measurements instead of
# discarding data, so we make this somewha... | python | def set(self, value):
"""Set the value for this measurement, with some sanity checks."""
if self.is_value_set:
# While we want to *allow* re-setting previously set measurements, we'd
# rather promote the use of multidimensional measurements instead of
# discarding data, so we make this somewha... | [
"def",
"set",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"is_value_set",
":",
"# While we want to *allow* re-setting previously set measurements, we'd",
"# rather promote the use of multidimensional measurements instead of",
"# discarding data, so we make this somewhat cha... | Set the value for this measurement, with some sanity checks. | [
"Set",
"the",
"value",
"for",
"this",
"measurement",
"with",
"some",
"sanity",
"checks",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L354-L368 | train |
google/openhtf | openhtf/core/measurements.py | Dimension.from_string | def from_string(cls, string):
"""Convert a string into a Dimension"""
# Note: There is some ambiguity as to whether the string passed is intended
# to become a unit looked up by name or suffix, or a Dimension descriptor.
if string in units.UNITS_BY_ALL:
return cls(description=string, unit=units.Un... | python | def from_string(cls, string):
"""Convert a string into a Dimension"""
# Note: There is some ambiguity as to whether the string passed is intended
# to become a unit looked up by name or suffix, or a Dimension descriptor.
if string in units.UNITS_BY_ALL:
return cls(description=string, unit=units.Un... | [
"def",
"from_string",
"(",
"cls",
",",
"string",
")",
":",
"# Note: There is some ambiguity as to whether the string passed is intended",
"# to become a unit looked up by name or suffix, or a Dimension descriptor.",
"if",
"string",
"in",
"units",
".",
"UNITS_BY_ALL",
":",
"return",... | Convert a string into a Dimension | [
"Convert",
"a",
"string",
"into",
"a",
"Dimension"
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L404-L411 | train |
google/openhtf | openhtf/core/measurements.py | DimensionedMeasuredValue.value | def value(self):
"""The values stored in this record.
Returns:
A list of tuples; the last element of each tuple will be the measured
value, the other elements will be the associated coordinates. The tuples
are output in the order in which they were set.
"""
if not self.is_value_set:
... | python | def value(self):
"""The values stored in this record.
Returns:
A list of tuples; the last element of each tuple will be the measured
value, the other elements will be the associated coordinates. The tuples
are output in the order in which they were set.
"""
if not self.is_value_set:
... | [
"def",
"value",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_value_set",
":",
"raise",
"MeasurementNotSetError",
"(",
"'Measurement not yet set'",
",",
"self",
".",
"name",
")",
"return",
"[",
"dimensions",
"+",
"(",
"value",
",",
")",
"for",
"dime... | The values stored in this record.
Returns:
A list of tuples; the last element of each tuple will be the measured
value, the other elements will be the associated coordinates. The tuples
are output in the order in which they were set. | [
"The",
"values",
"stored",
"in",
"this",
"record",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L505-L516 | train |
google/openhtf | openhtf/core/measurements.py | DimensionedMeasuredValue.to_dataframe | def to_dataframe(self, columns=None):
"""Converts to a `pandas.DataFrame`"""
if not self.is_value_set:
raise ValueError('Value must be set before converting to a DataFrame.')
if not pandas:
raise RuntimeError('Install pandas to convert to pandas.DataFrame')
return pandas.DataFrame.from_recor... | python | def to_dataframe(self, columns=None):
"""Converts to a `pandas.DataFrame`"""
if not self.is_value_set:
raise ValueError('Value must be set before converting to a DataFrame.')
if not pandas:
raise RuntimeError('Install pandas to convert to pandas.DataFrame')
return pandas.DataFrame.from_recor... | [
"def",
"to_dataframe",
"(",
"self",
",",
"columns",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"is_value_set",
":",
"raise",
"ValueError",
"(",
"'Value must be set before converting to a DataFrame.'",
")",
"if",
"not",
"pandas",
":",
"raise",
"RuntimeError",... | Converts to a `pandas.DataFrame` | [
"Converts",
"to",
"a",
"pandas",
".",
"DataFrame"
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L525-L531 | train |
google/openhtf | openhtf/core/measurements.py | Collection._assert_valid_key | def _assert_valid_key(self, name):
"""Raises if name is not a valid measurement."""
if name not in self._measurements:
raise NotAMeasurementError('Not a measurement', name, self._measurements) | python | def _assert_valid_key(self, name):
"""Raises if name is not a valid measurement."""
if name not in self._measurements:
raise NotAMeasurementError('Not a measurement', name, self._measurements) | [
"def",
"_assert_valid_key",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"_measurements",
":",
"raise",
"NotAMeasurementError",
"(",
"'Not a measurement'",
",",
"name",
",",
"self",
".",
"_measurements",
")"
] | Raises if name is not a valid measurement. | [
"Raises",
"if",
"name",
"is",
"not",
"a",
"valid",
"measurement",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/core/measurements.py#L579-L582 | train |
google/openhtf | openhtf/plugs/usb/adb_device.py | AdbDevice.install | def install(self, apk_path, destination_dir=None, timeout_ms=None):
"""Install apk to device.
Doesn't support verifier file, instead allows destination directory to be
overridden.
Arguments:
apk_path: Local path to apk to install.
destination_dir: Optional destination directory. Use /syste... | python | def install(self, apk_path, destination_dir=None, timeout_ms=None):
"""Install apk to device.
Doesn't support verifier file, instead allows destination directory to be
overridden.
Arguments:
apk_path: Local path to apk to install.
destination_dir: Optional destination directory. Use /syste... | [
"def",
"install",
"(",
"self",
",",
"apk_path",
",",
"destination_dir",
"=",
"None",
",",
"timeout_ms",
"=",
"None",
")",
":",
"if",
"not",
"destination_dir",
":",
"destination_dir",
"=",
"'/data/local/tmp/'",
"basename",
"=",
"os",
".",
"path",
".",
"basena... | Install apk to device.
Doesn't support verifier file, instead allows destination directory to be
overridden.
Arguments:
apk_path: Local path to apk to install.
destination_dir: Optional destination directory. Use /system/app/ for
persistent applications.
timeout_ms: Expected time... | [
"Install",
"apk",
"to",
"device",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_device.py#L111-L132 | train |
google/openhtf | openhtf/plugs/usb/adb_device.py | AdbDevice.push | def push(self, source_file, device_filename, timeout_ms=None):
"""Push source_file to file on device.
Arguments:
source_file: Either a filename or file-like object to push to the device.
If a filename, will set the remote mtime to match the local mtime,
otherwise will use the current time... | python | def push(self, source_file, device_filename, timeout_ms=None):
"""Push source_file to file on device.
Arguments:
source_file: Either a filename or file-like object to push to the device.
If a filename, will set the remote mtime to match the local mtime,
otherwise will use the current time... | [
"def",
"push",
"(",
"self",
",",
"source_file",
",",
"device_filename",
",",
"timeout_ms",
"=",
"None",
")",
":",
"mtime",
"=",
"0",
"if",
"isinstance",
"(",
"source_file",
",",
"six",
".",
"string_types",
")",
":",
"mtime",
"=",
"os",
".",
"path",
"."... | Push source_file to file on device.
Arguments:
source_file: Either a filename or file-like object to push to the device.
If a filename, will set the remote mtime to match the local mtime,
otherwise will use the current time.
device_filename: The filename on the device to write to.
... | [
"Push",
"source_file",
"to",
"file",
"on",
"device",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_device.py#L134-L151 | train |
google/openhtf | openhtf/plugs/usb/adb_device.py | AdbDevice.pull | def pull(self, device_filename, dest_file=None, timeout_ms=None):
"""Pull file from device.
Arguments:
device_filename: The filename on the device to pull.
dest_file: If set, a filename or writable file-like object.
timeout_ms: Expected timeout for the pull.
Returns:
The file data ... | python | def pull(self, device_filename, dest_file=None, timeout_ms=None):
"""Pull file from device.
Arguments:
device_filename: The filename on the device to pull.
dest_file: If set, a filename or writable file-like object.
timeout_ms: Expected timeout for the pull.
Returns:
The file data ... | [
"def",
"pull",
"(",
"self",
",",
"device_filename",
",",
"dest_file",
"=",
"None",
",",
"timeout_ms",
"=",
"None",
")",
":",
"should_return_data",
"=",
"dest_file",
"is",
"None",
"if",
"isinstance",
"(",
"dest_file",
",",
"six",
".",
"string_types",
")",
"... | Pull file from device.
Arguments:
device_filename: The filename on the device to pull.
dest_file: If set, a filename or writable file-like object.
timeout_ms: Expected timeout for the pull.
Returns:
The file data if dest_file is not set, None otherwise. | [
"Pull",
"file",
"from",
"device",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_device.py#L153-L172 | train |
google/openhtf | openhtf/plugs/usb/adb_device.py | AdbDevice.list | def list(self, device_path, timeout_ms=None):
"""Yield filesync_service.DeviceFileStat objects for directory contents."""
return self.filesync_service.list(
device_path, timeouts.PolledTimeout.from_millis(timeout_ms)) | python | def list(self, device_path, timeout_ms=None):
"""Yield filesync_service.DeviceFileStat objects for directory contents."""
return self.filesync_service.list(
device_path, timeouts.PolledTimeout.from_millis(timeout_ms)) | [
"def",
"list",
"(",
"self",
",",
"device_path",
",",
"timeout_ms",
"=",
"None",
")",
":",
"return",
"self",
".",
"filesync_service",
".",
"list",
"(",
"device_path",
",",
"timeouts",
".",
"PolledTimeout",
".",
"from_millis",
"(",
"timeout_ms",
")",
")"
] | Yield filesync_service.DeviceFileStat objects for directory contents. | [
"Yield",
"filesync_service",
".",
"DeviceFileStat",
"objects",
"for",
"directory",
"contents",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_device.py#L174-L177 | train |
google/openhtf | openhtf/plugs/usb/adb_device.py | AdbDevice._check_remote_command | def _check_remote_command(self, destination, timeout_ms, success_msgs=None):
"""Open a stream to destination, check for remote errors.
Used for reboot, remount, and root services. If this method returns, the
command was successful, otherwise an appropriate error will have been
raised.
Args:
... | python | def _check_remote_command(self, destination, timeout_ms, success_msgs=None):
"""Open a stream to destination, check for remote errors.
Used for reboot, remount, and root services. If this method returns, the
command was successful, otherwise an appropriate error will have been
raised.
Args:
... | [
"def",
"_check_remote_command",
"(",
"self",
",",
"destination",
",",
"timeout_ms",
",",
"success_msgs",
"=",
"None",
")",
":",
"timeout",
"=",
"timeouts",
".",
"PolledTimeout",
".",
"from_millis",
"(",
"timeout_ms",
")",
"stream",
"=",
"self",
".",
"_adb_conn... | Open a stream to destination, check for remote errors.
Used for reboot, remount, and root services. If this method returns, the
command was successful, otherwise an appropriate error will have been
raised.
Args:
destination: Stream destination to open.
timeout_ms: Timeout in milliseconds ... | [
"Open",
"a",
"stream",
"to",
"destination",
"check",
"for",
"remote",
"errors",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_device.py#L191-L224 | train |
google/openhtf | openhtf/util/multicast.py | send | def send(query,
address=DEFAULT_ADDRESS,
port=DEFAULT_PORT,
ttl=DEFAULT_TTL,
local_only=False,
timeout_s=2):
"""Sends a query to the given multicast socket and returns responses.
Args:
query: The string query to send.
address: Multicast IP address component of t... | python | def send(query,
address=DEFAULT_ADDRESS,
port=DEFAULT_PORT,
ttl=DEFAULT_TTL,
local_only=False,
timeout_s=2):
"""Sends a query to the given multicast socket and returns responses.
Args:
query: The string query to send.
address: Multicast IP address component of t... | [
"def",
"send",
"(",
"query",
",",
"address",
"=",
"DEFAULT_ADDRESS",
",",
"port",
"=",
"DEFAULT_PORT",
",",
"ttl",
"=",
"DEFAULT_TTL",
",",
"local_only",
"=",
"False",
",",
"timeout_s",
"=",
"2",
")",
":",
"# Set up the socket as a UDP Multicast socket with the gi... | Sends a query to the given multicast socket and returns responses.
Args:
query: The string query to send.
address: Multicast IP address component of the socket to send to.
port: Multicast UDP port component of the socket to send to.
ttl: TTL for multicast messages. 1 to keep traffic in-network.
t... | [
"Sends",
"a",
"query",
"to",
"the",
"given",
"multicast",
"socket",
"and",
"returns",
"responses",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/util/multicast.py#L135-L188 | train |
google/openhtf | openhtf/util/multicast.py | MulticastListener.run | def run(self):
"""Listen for pings until stopped."""
self._live = True
self._sock.settimeout(self.LISTEN_TIMEOUT_S)
# Passing in INADDR_ANY means the kernel will choose the default interface.
# The localhost address is used to receive messages sent in "local_only"
# mode and the default address... | python | def run(self):
"""Listen for pings until stopped."""
self._live = True
self._sock.settimeout(self.LISTEN_TIMEOUT_S)
# Passing in INADDR_ANY means the kernel will choose the default interface.
# The localhost address is used to receive messages sent in "local_only"
# mode and the default address... | [
"def",
"run",
"(",
"self",
")",
":",
"self",
".",
"_live",
"=",
"True",
"self",
".",
"_sock",
".",
"settimeout",
"(",
"self",
".",
"LISTEN_TIMEOUT_S",
")",
"# Passing in INADDR_ANY means the kernel will choose the default interface.",
"# The localhost address is used to r... | Listen for pings until stopped. | [
"Listen",
"for",
"pings",
"until",
"stopped",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/util/multicast.py#L87-L132 | train |
google/openhtf | openhtf/plugs/usb/fastboot_protocol.py | FastbootProtocol._handle_progress | def _handle_progress(self, total, progress_callback): # pylint: disable=no-self-use
"""Calls the callback with the current progress and total ."""
current = 0
while True:
current += yield
try:
progress_callback(current, total)
except Exception: # pylint: disable=broad-except
... | python | def _handle_progress(self, total, progress_callback): # pylint: disable=no-self-use
"""Calls the callback with the current progress and total ."""
current = 0
while True:
current += yield
try:
progress_callback(current, total)
except Exception: # pylint: disable=broad-except
... | [
"def",
"_handle_progress",
"(",
"self",
",",
"total",
",",
"progress_callback",
")",
":",
"# pylint: disable=no-self-use",
"current",
"=",
"0",
"while",
"True",
":",
"current",
"+=",
"yield",
"try",
":",
"progress_callback",
"(",
"current",
",",
"total",
")",
... | Calls the callback with the current progress and total . | [
"Calls",
"the",
"callback",
"with",
"the",
"current",
"progress",
"and",
"total",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/fastboot_protocol.py#L162-L172 | train |
google/openhtf | openhtf/plugs/usb/fastboot_protocol.py | FastbootCommands._simple_command | def _simple_command(self, command, arg=None, **kwargs):
"""Send a simple command."""
self._protocol.send_command(command, arg)
return self._protocol.handle_simple_responses(**kwargs) | python | def _simple_command(self, command, arg=None, **kwargs):
"""Send a simple command."""
self._protocol.send_command(command, arg)
return self._protocol.handle_simple_responses(**kwargs) | [
"def",
"_simple_command",
"(",
"self",
",",
"command",
",",
"arg",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_protocol",
".",
"send_command",
"(",
"command",
",",
"arg",
")",
"return",
"self",
".",
"_protocol",
".",
"handle_simple_res... | Send a simple command. | [
"Send",
"a",
"simple",
"command",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/fastboot_protocol.py#L210-L213 | train |
google/openhtf | openhtf/output/servers/dashboard_server.py | _discover | def _discover(**kwargs):
"""Yields info about station servers announcing themselves via multicast."""
query = station_server.MULTICAST_QUERY
for host, response in multicast.send(query, **kwargs):
try:
result = json.loads(response)
except ValueError:
_LOG.warn('Received bad JSON over multicast ... | python | def _discover(**kwargs):
"""Yields info about station servers announcing themselves via multicast."""
query = station_server.MULTICAST_QUERY
for host, response in multicast.send(query, **kwargs):
try:
result = json.loads(response)
except ValueError:
_LOG.warn('Received bad JSON over multicast ... | [
"def",
"_discover",
"(",
"*",
"*",
"kwargs",
")",
":",
"query",
"=",
"station_server",
".",
"MULTICAST_QUERY",
"for",
"host",
",",
"response",
"in",
"multicast",
".",
"send",
"(",
"query",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"result",
"=",
... | Yields info about station servers announcing themselves via multicast. | [
"Yields",
"info",
"about",
"station",
"servers",
"announcing",
"themselves",
"via",
"multicast",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/servers/dashboard_server.py#L35-L52 | train |
google/openhtf | openhtf/output/servers/dashboard_server.py | DashboardPubSub.update_stations | def update_stations(cls, station_info_list):
"""Called by the station discovery loop to update the station map."""
with cls.station_map_lock:
# By default, assume old stations are unreachable.
for host_port, station_info in six.iteritems(cls.station_map):
cls.station_map[host_port] = statio... | python | def update_stations(cls, station_info_list):
"""Called by the station discovery loop to update the station map."""
with cls.station_map_lock:
# By default, assume old stations are unreachable.
for host_port, station_info in six.iteritems(cls.station_map):
cls.station_map[host_port] = statio... | [
"def",
"update_stations",
"(",
"cls",
",",
"station_info_list",
")",
":",
"with",
"cls",
".",
"station_map_lock",
":",
"# By default, assume old stations are unreachable.",
"for",
"host_port",
",",
"station_info",
"in",
"six",
".",
"iteritems",
"(",
"cls",
".",
"sta... | Called by the station discovery loop to update the station map. | [
"Called",
"by",
"the",
"station",
"discovery",
"loop",
"to",
"update",
"the",
"station",
"map",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/servers/dashboard_server.py#L79-L89 | train |
google/openhtf | openhtf/output/servers/dashboard_server.py | DashboardPubSub.publish_if_new | def publish_if_new(cls):
"""If the station map has changed, publish the new information."""
message = cls.make_message()
if message != cls.last_message:
super(DashboardPubSub, cls).publish(message)
cls.last_message = message | python | def publish_if_new(cls):
"""If the station map has changed, publish the new information."""
message = cls.make_message()
if message != cls.last_message:
super(DashboardPubSub, cls).publish(message)
cls.last_message = message | [
"def",
"publish_if_new",
"(",
"cls",
")",
":",
"message",
"=",
"cls",
".",
"make_message",
"(",
")",
"if",
"message",
"!=",
"cls",
".",
"last_message",
":",
"super",
"(",
"DashboardPubSub",
",",
"cls",
")",
".",
"publish",
"(",
"message",
")",
"cls",
"... | If the station map has changed, publish the new information. | [
"If",
"the",
"station",
"map",
"has",
"changed",
"publish",
"the",
"new",
"information",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/servers/dashboard_server.py#L92-L97 | train |
google/openhtf | examples/phase_groups.py | run_basic_group | def run_basic_group():
"""Run the basic phase group example.
In this example, there are no terminal phases; all phases are run.
"""
test = htf.Test(htf.PhaseGroup(
setup=[setup_phase],
main=[main_phase],
teardown=[teardown_phase],
))
test.execute() | python | def run_basic_group():
"""Run the basic phase group example.
In this example, there are no terminal phases; all phases are run.
"""
test = htf.Test(htf.PhaseGroup(
setup=[setup_phase],
main=[main_phase],
teardown=[teardown_phase],
))
test.execute() | [
"def",
"run_basic_group",
"(",
")",
":",
"test",
"=",
"htf",
".",
"Test",
"(",
"htf",
".",
"PhaseGroup",
"(",
"setup",
"=",
"[",
"setup_phase",
"]",
",",
"main",
"=",
"[",
"main_phase",
"]",
",",
"teardown",
"=",
"[",
"teardown_phase",
"]",
",",
")",... | Run the basic phase group example.
In this example, there are no terminal phases; all phases are run. | [
"Run",
"the",
"basic",
"phase",
"group",
"example",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/examples/phase_groups.py#L54-L64 | train |
google/openhtf | examples/phase_groups.py | run_setup_error_group | def run_setup_error_group():
"""Run the phase group example where an error occurs in a setup phase.
The terminal setup phase shortcuts the test. The main phases are
skipped. The PhaseGroup is not entered, so the teardown phases are also
skipped.
"""
test = htf.Test(htf.PhaseGroup(
setup=[error_setu... | python | def run_setup_error_group():
"""Run the phase group example where an error occurs in a setup phase.
The terminal setup phase shortcuts the test. The main phases are
skipped. The PhaseGroup is not entered, so the teardown phases are also
skipped.
"""
test = htf.Test(htf.PhaseGroup(
setup=[error_setu... | [
"def",
"run_setup_error_group",
"(",
")",
":",
"test",
"=",
"htf",
".",
"Test",
"(",
"htf",
".",
"PhaseGroup",
"(",
"setup",
"=",
"[",
"error_setup_phase",
"]",
",",
"main",
"=",
"[",
"main_phase",
"]",
",",
"teardown",
"=",
"[",
"teardown_phase",
"]",
... | Run the phase group example where an error occurs in a setup phase.
The terminal setup phase shortcuts the test. The main phases are
skipped. The PhaseGroup is not entered, so the teardown phases are also
skipped. | [
"Run",
"the",
"phase",
"group",
"example",
"where",
"an",
"error",
"occurs",
"in",
"a",
"setup",
"phase",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/examples/phase_groups.py#L67-L79 | train |
google/openhtf | examples/phase_groups.py | run_main_error_group | def run_main_error_group():
"""Run the phase group example where an error occurs in a main phase.
The main phase in this example is terminal. The PhaseGroup was entered
because the setup phases ran without error, so the teardown phases are run.
The other main phase is skipped.
"""
test = htf.Test(htf.Phas... | python | def run_main_error_group():
"""Run the phase group example where an error occurs in a main phase.
The main phase in this example is terminal. The PhaseGroup was entered
because the setup phases ran without error, so the teardown phases are run.
The other main phase is skipped.
"""
test = htf.Test(htf.Phas... | [
"def",
"run_main_error_group",
"(",
")",
":",
"test",
"=",
"htf",
".",
"Test",
"(",
"htf",
".",
"PhaseGroup",
"(",
"setup",
"=",
"[",
"setup_phase",
"]",
",",
"main",
"=",
"[",
"error_main_phase",
",",
"main_phase",
"]",
",",
"teardown",
"=",
"[",
"tea... | Run the phase group example where an error occurs in a main phase.
The main phase in this example is terminal. The PhaseGroup was entered
because the setup phases ran without error, so the teardown phases are run.
The other main phase is skipped. | [
"Run",
"the",
"phase",
"group",
"example",
"where",
"an",
"error",
"occurs",
"in",
"a",
"main",
"phase",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/examples/phase_groups.py#L82-L94 | train |
google/openhtf | examples/phase_groups.py | run_nested_groups | def run_nested_groups():
"""Run the nested groups example.
This example shows a PhaseGroup in a PhaseGroup. No phase is terminal, so all
are run in the order;
main_phase
inner_main_phase
inner_teardown_phase
teardown_phase
"""
test = htf.Test(
htf.PhaseGroup(
main=[
... | python | def run_nested_groups():
"""Run the nested groups example.
This example shows a PhaseGroup in a PhaseGroup. No phase is terminal, so all
are run in the order;
main_phase
inner_main_phase
inner_teardown_phase
teardown_phase
"""
test = htf.Test(
htf.PhaseGroup(
main=[
... | [
"def",
"run_nested_groups",
"(",
")",
":",
"test",
"=",
"htf",
".",
"Test",
"(",
"htf",
".",
"PhaseGroup",
"(",
"main",
"=",
"[",
"main_phase",
",",
"htf",
".",
"PhaseGroup",
".",
"with_teardown",
"(",
"inner_teardown_phase",
")",
"(",
"inner_main_phase",
... | Run the nested groups example.
This example shows a PhaseGroup in a PhaseGroup. No phase is terminal, so all
are run in the order;
main_phase
inner_main_phase
inner_teardown_phase
teardown_phase | [
"Run",
"the",
"nested",
"groups",
"example",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/examples/phase_groups.py#L97-L117 | train |
google/openhtf | examples/phase_groups.py | run_nested_error_groups | def run_nested_error_groups():
"""Run nested groups example where an error occurs in nested main phase.
In this example, the first main phase in the nested PhaseGroup errors out.
The other inner main phase is skipped, as is the outer main phase. Both
PhaseGroups were entered, so both teardown phases are run.
... | python | def run_nested_error_groups():
"""Run nested groups example where an error occurs in nested main phase.
In this example, the first main phase in the nested PhaseGroup errors out.
The other inner main phase is skipped, as is the outer main phase. Both
PhaseGroups were entered, so both teardown phases are run.
... | [
"def",
"run_nested_error_groups",
"(",
")",
":",
"test",
"=",
"htf",
".",
"Test",
"(",
"htf",
".",
"PhaseGroup",
"(",
"main",
"=",
"[",
"htf",
".",
"PhaseGroup",
".",
"with_teardown",
"(",
"inner_teardown_phase",
")",
"(",
"error_main_phase",
",",
"main_phas... | Run nested groups example where an error occurs in nested main phase.
In this example, the first main phase in the nested PhaseGroup errors out.
The other inner main phase is skipped, as is the outer main phase. Both
PhaseGroups were entered, so both teardown phases are run. | [
"Run",
"nested",
"groups",
"example",
"where",
"an",
"error",
"occurs",
"in",
"nested",
"main",
"phase",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/examples/phase_groups.py#L120-L137 | train |
google/openhtf | bin/units_from_xls.py | main | def main():
"""Main entry point for UNECE code .xls parsing."""
parser = argparse.ArgumentParser(
description='Reads in a .xls file and generates a units module for '
'OpenHTF.',
prog='python units_from_xls.py')
parser.add_argument('xlsfile', type=str,
help='the... | python | def main():
"""Main entry point for UNECE code .xls parsing."""
parser = argparse.ArgumentParser(
description='Reads in a .xls file and generates a units module for '
'OpenHTF.',
prog='python units_from_xls.py')
parser.add_argument('xlsfile', type=str,
help='the... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Reads in a .xls file and generates a units module for '",
"'OpenHTF.'",
",",
"prog",
"=",
"'python units_from_xls.py'",
")",
"parser",
".",
"add_argument",
"(",
... | Main entry point for UNECE code .xls parsing. | [
"Main",
"entry",
"point",
"for",
"UNECE",
"code",
".",
"xls",
"parsing",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/bin/units_from_xls.py#L169-L203 | train |
google/openhtf | bin/units_from_xls.py | unit_defs_from_sheet | def unit_defs_from_sheet(sheet, column_names):
"""A generator that parses a worksheet containing UNECE code definitions.
Args:
sheet: An xldr.sheet object representing a UNECE code worksheet.
column_names: A list/tuple with the expected column names corresponding to
the unit name, code an... | python | def unit_defs_from_sheet(sheet, column_names):
"""A generator that parses a worksheet containing UNECE code definitions.
Args:
sheet: An xldr.sheet object representing a UNECE code worksheet.
column_names: A list/tuple with the expected column names corresponding to
the unit name, code an... | [
"def",
"unit_defs_from_sheet",
"(",
"sheet",
",",
"column_names",
")",
":",
"seen",
"=",
"set",
"(",
")",
"try",
":",
"col_indices",
"=",
"{",
"}",
"rows",
"=",
"sheet",
".",
"get_rows",
"(",
")",
"# Find the indices for the columns we care about.",
"for",
"id... | A generator that parses a worksheet containing UNECE code definitions.
Args:
sheet: An xldr.sheet object representing a UNECE code worksheet.
column_names: A list/tuple with the expected column names corresponding to
the unit name, code and suffix in that order.
Yields: Lines of Python so... | [
"A",
"generator",
"that",
"parses",
"a",
"worksheet",
"containing",
"UNECE",
"code",
"definitions",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/bin/units_from_xls.py#L206-L242 | train |
google/openhtf | bin/units_from_xls.py | unit_key_from_name | def unit_key_from_name(name):
"""Return a legal python name for the given name for use as a unit key."""
result = name
for old, new in six.iteritems(UNIT_KEY_REPLACEMENTS):
result = result.replace(old, new)
# Collapse redundant underscores and convert to uppercase.
result = re.sub(r'_+', '_', result.upp... | python | def unit_key_from_name(name):
"""Return a legal python name for the given name for use as a unit key."""
result = name
for old, new in six.iteritems(UNIT_KEY_REPLACEMENTS):
result = result.replace(old, new)
# Collapse redundant underscores and convert to uppercase.
result = re.sub(r'_+', '_', result.upp... | [
"def",
"unit_key_from_name",
"(",
"name",
")",
":",
"result",
"=",
"name",
"for",
"old",
",",
"new",
"in",
"six",
".",
"iteritems",
"(",
"UNIT_KEY_REPLACEMENTS",
")",
":",
"result",
"=",
"result",
".",
"replace",
"(",
"old",
",",
"new",
")",
"# Collapse ... | Return a legal python name for the given name for use as a unit key. | [
"Return",
"a",
"legal",
"python",
"name",
"for",
"the",
"given",
"name",
"for",
"use",
"as",
"a",
"unit",
"key",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/bin/units_from_xls.py#L245-L255 | train |
google/openhtf | openhtf/plugs/usb/adb_message.py | make_wire_commands | def make_wire_commands(*ids):
"""Assemble the commands."""
cmd_to_wire = {
cmd: sum(ord(c) << (i * 8) for i, c in enumerate(cmd)) for cmd in ids
}
wire_to_cmd = {wire: cmd for cmd, wire in six.iteritems(cmd_to_wire)}
return cmd_to_wire, wire_to_cmd | python | def make_wire_commands(*ids):
"""Assemble the commands."""
cmd_to_wire = {
cmd: sum(ord(c) << (i * 8) for i, c in enumerate(cmd)) for cmd in ids
}
wire_to_cmd = {wire: cmd for cmd, wire in six.iteritems(cmd_to_wire)}
return cmd_to_wire, wire_to_cmd | [
"def",
"make_wire_commands",
"(",
"*",
"ids",
")",
":",
"cmd_to_wire",
"=",
"{",
"cmd",
":",
"sum",
"(",
"ord",
"(",
"c",
")",
"<<",
"(",
"i",
"*",
"8",
")",
"for",
"i",
",",
"c",
"in",
"enumerate",
"(",
"cmd",
")",
")",
"for",
"cmd",
"in",
"... | Assemble the commands. | [
"Assemble",
"the",
"commands",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_message.py#L55-L61 | train |
google/openhtf | openhtf/plugs/usb/adb_message.py | RawAdbMessage.to_adb_message | def to_adb_message(self, data):
"""Turn the data into an ADB message."""
message = AdbMessage(AdbMessage.WIRE_TO_CMD.get(self.cmd),
self.arg0, self.arg1, data)
if (len(data) != self.data_length or
message.data_crc32 != self.data_checksum):
raise usb_exceptions.AdbDataI... | python | def to_adb_message(self, data):
"""Turn the data into an ADB message."""
message = AdbMessage(AdbMessage.WIRE_TO_CMD.get(self.cmd),
self.arg0, self.arg1, data)
if (len(data) != self.data_length or
message.data_crc32 != self.data_checksum):
raise usb_exceptions.AdbDataI... | [
"def",
"to_adb_message",
"(",
"self",
",",
"data",
")",
":",
"message",
"=",
"AdbMessage",
"(",
"AdbMessage",
".",
"WIRE_TO_CMD",
".",
"get",
"(",
"self",
".",
"cmd",
")",
",",
"self",
".",
"arg0",
",",
"self",
".",
"arg1",
",",
"data",
")",
"if",
... | Turn the data into an ADB message. | [
"Turn",
"the",
"data",
"into",
"an",
"ADB",
"message",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_message.py#L70-L78 | train |
google/openhtf | openhtf/plugs/usb/adb_message.py | AdbTransportAdapter.write_message | def write_message(self, message, timeout):
"""Send the given message over this transport.
Args:
message: The AdbMessage to send.
timeout: Use this timeout for the entire write operation, it should be an
instance of timeouts.PolledTimeout.
"""
with self._writer_lock:
self._tran... | python | def write_message(self, message, timeout):
"""Send the given message over this transport.
Args:
message: The AdbMessage to send.
timeout: Use this timeout for the entire write operation, it should be an
instance of timeouts.PolledTimeout.
"""
with self._writer_lock:
self._tran... | [
"def",
"write_message",
"(",
"self",
",",
"message",
",",
"timeout",
")",
":",
"with",
"self",
".",
"_writer_lock",
":",
"self",
".",
"_transport",
".",
"write",
"(",
"message",
".",
"header",
",",
"timeout",
".",
"remaining_ms",
")",
"# Use any remaining ti... | Send the given message over this transport.
Args:
message: The AdbMessage to send.
timeout: Use this timeout for the entire write operation, it should be an
instance of timeouts.PolledTimeout. | [
"Send",
"the",
"given",
"message",
"over",
"this",
"transport",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_message.py#L109-L128 | train |
google/openhtf | openhtf/plugs/usb/adb_message.py | AdbTransportAdapter.read_message | def read_message(self, timeout):
"""Read an AdbMessage from this transport.
Args:
timeout: Timeout for the entire read operation, in the form of a
timeouts.PolledTimeout instance. Note that for packets with a data
payload, two USB reads are performed.
Returns:
The ADB message ... | python | def read_message(self, timeout):
"""Read an AdbMessage from this transport.
Args:
timeout: Timeout for the entire read operation, in the form of a
timeouts.PolledTimeout instance. Note that for packets with a data
payload, two USB reads are performed.
Returns:
The ADB message ... | [
"def",
"read_message",
"(",
"self",
",",
"timeout",
")",
":",
"with",
"self",
".",
"_reader_lock",
":",
"raw_header",
"=",
"self",
".",
"_transport",
".",
"read",
"(",
"struct",
".",
"calcsize",
"(",
"AdbMessage",
".",
"HEADER_STRUCT_FORMAT",
")",
",",
"ti... | Read an AdbMessage from this transport.
Args:
timeout: Timeout for the entire read operation, in the form of a
timeouts.PolledTimeout instance. Note that for packets with a data
payload, two USB reads are performed.
Returns:
The ADB message read from the device.
Raises:
... | [
"Read",
"an",
"AdbMessage",
"from",
"this",
"transport",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_message.py#L130-L172 | train |
google/openhtf | openhtf/plugs/usb/adb_message.py | AdbTransportAdapter.read_until | def read_until(self, expected_commands, timeout):
"""Read AdbMessages from this transport until we get an expected command.
The ADB protocol specifies that before a successful CNXN handshake, any
other packets must be ignored, so this method provides the ability to
ignore unwanted commands. It's prima... | python | def read_until(self, expected_commands, timeout):
"""Read AdbMessages from this transport until we get an expected command.
The ADB protocol specifies that before a successful CNXN handshake, any
other packets must be ignored, so this method provides the ability to
ignore unwanted commands. It's prima... | [
"def",
"read_until",
"(",
"self",
",",
"expected_commands",
",",
"timeout",
")",
":",
"msg",
"=",
"timeouts",
".",
"loop_until_timeout_or_valid",
"(",
"timeout",
",",
"lambda",
":",
"self",
".",
"read_message",
"(",
"timeout",
")",
",",
"lambda",
"m",
":",
... | Read AdbMessages from this transport until we get an expected command.
The ADB protocol specifies that before a successful CNXN handshake, any
other packets must be ignored, so this method provides the ability to
ignore unwanted commands. It's primarily used during the initial
connection to the device... | [
"Read",
"AdbMessages",
"from",
"this",
"transport",
"until",
"we",
"get",
"an",
"expected",
"command",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_message.py#L174-L202 | train |
google/openhtf | openhtf/plugs/usb/adb_message.py | AdbMessage.header | def header(self):
"""The message header."""
return struct.pack(
self.HEADER_STRUCT_FORMAT, self._command, self.arg0, self.arg1,
len(self.data), self.data_crc32, self.magic) | python | def header(self):
"""The message header."""
return struct.pack(
self.HEADER_STRUCT_FORMAT, self._command, self.arg0, self.arg1,
len(self.data), self.data_crc32, self.magic) | [
"def",
"header",
"(",
"self",
")",
":",
"return",
"struct",
".",
"pack",
"(",
"self",
".",
"HEADER_STRUCT_FORMAT",
",",
"self",
".",
"_command",
",",
"self",
".",
"arg0",
",",
"self",
".",
"arg1",
",",
"len",
"(",
"self",
".",
"data",
")",
",",
"se... | The message header. | [
"The",
"message",
"header",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_message.py#L276-L280 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | _make_message_type | def _make_message_type(name, attributes, has_data=True):
"""Make a message type for the AdbTransport subclasses."""
def assert_command_is(self, command): # pylint: disable=invalid-name
"""Assert that a message's command matches the given command."""
if self.command != command:
raise usb_exceptions.A... | python | def _make_message_type(name, attributes, has_data=True):
"""Make a message type for the AdbTransport subclasses."""
def assert_command_is(self, command): # pylint: disable=invalid-name
"""Assert that a message's command matches the given command."""
if self.command != command:
raise usb_exceptions.A... | [
"def",
"_make_message_type",
"(",
"name",
",",
"attributes",
",",
"has_data",
"=",
"True",
")",
":",
"def",
"assert_command_is",
"(",
"self",
",",
"command",
")",
":",
"# pylint: disable=invalid-name",
"\"\"\"Assert that a message's command matches the given command.\"\"\""... | Make a message type for the AdbTransport subclasses. | [
"Make",
"a",
"message",
"type",
"for",
"the",
"AdbTransport",
"subclasses",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L130-L145 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | FilesyncService.stat | def stat(self, filename, timeout=None):
"""Return device file stat."""
transport = StatFilesyncTransport(self.stream)
transport.write_data('STAT', filename, timeout)
stat_msg = transport.read_message(timeout)
stat_msg.assert_command_is('STAT')
return DeviceFileStat(filename, stat_msg.mode, stat_... | python | def stat(self, filename, timeout=None):
"""Return device file stat."""
transport = StatFilesyncTransport(self.stream)
transport.write_data('STAT', filename, timeout)
stat_msg = transport.read_message(timeout)
stat_msg.assert_command_is('STAT')
return DeviceFileStat(filename, stat_msg.mode, stat_... | [
"def",
"stat",
"(",
"self",
",",
"filename",
",",
"timeout",
"=",
"None",
")",
":",
"transport",
"=",
"StatFilesyncTransport",
"(",
"self",
".",
"stream",
")",
"transport",
".",
"write_data",
"(",
"'STAT'",
",",
"filename",
",",
"timeout",
")",
"stat_msg",... | Return device file stat. | [
"Return",
"device",
"file",
"stat",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L173-L179 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | FilesyncService.list | def list(self, path, timeout=None):
"""List directory contents on the device.
Args:
path: List the contents of this directory.
timeout: Timeout to use for this operation.
Returns:
Generator yielding DeviceFileStat tuples representing the contents of
the requested path.
"""
tr... | python | def list(self, path, timeout=None):
"""List directory contents on the device.
Args:
path: List the contents of this directory.
timeout: Timeout to use for this operation.
Returns:
Generator yielding DeviceFileStat tuples representing the contents of
the requested path.
"""
tr... | [
"def",
"list",
"(",
"self",
",",
"path",
",",
"timeout",
"=",
"None",
")",
":",
"transport",
"=",
"DentFilesyncTransport",
"(",
"self",
".",
"stream",
")",
"transport",
".",
"write_data",
"(",
"'LIST'",
",",
"path",
",",
"timeout",
")",
"return",
"(",
... | List directory contents on the device.
Args:
path: List the contents of this directory.
timeout: Timeout to use for this operation.
Returns:
Generator yielding DeviceFileStat tuples representing the contents of
the requested path. | [
"List",
"directory",
"contents",
"on",
"the",
"device",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L181-L196 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | FilesyncService.recv | def recv(self, filename, dest_file, timeout=None):
"""Retrieve a file from the device into the file-like dest_file."""
transport = DataFilesyncTransport(self.stream)
transport.write_data('RECV', filename, timeout)
for data_msg in transport.read_until_done('DATA', timeout):
dest_file.write(data_msg... | python | def recv(self, filename, dest_file, timeout=None):
"""Retrieve a file from the device into the file-like dest_file."""
transport = DataFilesyncTransport(self.stream)
transport.write_data('RECV', filename, timeout)
for data_msg in transport.read_until_done('DATA', timeout):
dest_file.write(data_msg... | [
"def",
"recv",
"(",
"self",
",",
"filename",
",",
"dest_file",
",",
"timeout",
"=",
"None",
")",
":",
"transport",
"=",
"DataFilesyncTransport",
"(",
"self",
".",
"stream",
")",
"transport",
".",
"write_data",
"(",
"'RECV'",
",",
"filename",
",",
"timeout"... | Retrieve a file from the device into the file-like dest_file. | [
"Retrieve",
"a",
"file",
"from",
"the",
"device",
"into",
"the",
"file",
"-",
"like",
"dest_file",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L198-L203 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | FilesyncService._check_for_fail_message | def _check_for_fail_message(self, transport, exc_info, timeout): # pylint: disable=no-self-use
"""Check for a 'FAIL' message from transport.
This method always raises, if 'FAIL' was read, it will raise an
AdbRemoteError with the message, otherwise it will raise based on
exc_info, which should be a tup... | python | def _check_for_fail_message(self, transport, exc_info, timeout): # pylint: disable=no-self-use
"""Check for a 'FAIL' message from transport.
This method always raises, if 'FAIL' was read, it will raise an
AdbRemoteError with the message, otherwise it will raise based on
exc_info, which should be a tup... | [
"def",
"_check_for_fail_message",
"(",
"self",
",",
"transport",
",",
"exc_info",
",",
"timeout",
")",
":",
"# pylint: disable=no-self-use",
"try",
":",
"transport",
".",
"read_message",
"(",
"timeout",
")",
"except",
"usb_exceptions",
".",
"CommonUsbError",
":",
... | Check for a 'FAIL' message from transport.
This method always raises, if 'FAIL' was read, it will raise an
AdbRemoteError with the message, otherwise it will raise based on
exc_info, which should be a tuple as per sys.exc_info().
Args:
transport: Transport from which to read for a 'FAIL' message... | [
"Check",
"for",
"a",
"FAIL",
"message",
"from",
"transport",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L205-L227 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | AbstractFilesyncTransport.write_data | def write_data(self, command, data, timeout=None):
"""Shortcut for writing specifically a DataMessage."""
self.write_message(FilesyncMessageTypes.DataMessage(command, data), timeout) | python | def write_data(self, command, data, timeout=None):
"""Shortcut for writing specifically a DataMessage."""
self.write_message(FilesyncMessageTypes.DataMessage(command, data), timeout) | [
"def",
"write_data",
"(",
"self",
",",
"command",
",",
"data",
",",
"timeout",
"=",
"None",
")",
":",
"self",
".",
"write_message",
"(",
"FilesyncMessageTypes",
".",
"DataMessage",
"(",
"command",
",",
"data",
")",
",",
"timeout",
")"
] | Shortcut for writing specifically a DataMessage. | [
"Shortcut",
"for",
"writing",
"specifically",
"a",
"DataMessage",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L362-L364 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | AbstractFilesyncTransport.read_until_done | def read_until_done(self, command, timeout=None):
"""Yield messages read until we receive a 'DONE' command.
Read messages of the given command until we receive a 'DONE' command. If a
command different than the requested one is received, an AdbProtocolError
is raised.
Args:
command: The comm... | python | def read_until_done(self, command, timeout=None):
"""Yield messages read until we receive a 'DONE' command.
Read messages of the given command until we receive a 'DONE' command. If a
command different than the requested one is received, an AdbProtocolError
is raised.
Args:
command: The comm... | [
"def",
"read_until_done",
"(",
"self",
",",
"command",
",",
"timeout",
"=",
"None",
")",
":",
"message",
"=",
"self",
".",
"read_message",
"(",
"timeout",
")",
"while",
"message",
".",
"command",
"!=",
"'DONE'",
":",
"message",
".",
"assert_command_is",
"(... | Yield messages read until we receive a 'DONE' command.
Read messages of the given command until we receive a 'DONE' command. If a
command different than the requested one is received, an AdbProtocolError
is raised.
Args:
command: The command to expect, like 'DENT' or 'DATA'.
timeout: The ... | [
"Yield",
"messages",
"read",
"until",
"we",
"receive",
"a",
"DONE",
"command",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L391-L413 | train |
google/openhtf | openhtf/plugs/usb/filesync_service.py | AbstractFilesyncTransport.read_message | def read_message(self, timeout=None):
"""Read a message from this transport and return it.
Reads a message of RECV_MSG_TYPE and returns it. Note that this method
abstracts the data length and data read so that the caller simply gets the
data along with the header in the returned message.
Args:
... | python | def read_message(self, timeout=None):
"""Read a message from this transport and return it.
Reads a message of RECV_MSG_TYPE and returns it. Note that this method
abstracts the data length and data read so that the caller simply gets the
data along with the header in the returned message.
Args:
... | [
"def",
"read_message",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"raw_data",
"=",
"self",
".",
"stream",
".",
"read",
"(",
"struct",
".",
"calcsize",
"(",
"self",
".",
"RECV_MSG_TYPE",
".",
"struct_format",
")",
",",
"timeout",
")",
"try",
":... | Read a message from this transport and return it.
Reads a message of RECV_MSG_TYPE and returns it. Note that this method
abstracts the data length and data read so that the caller simply gets the
data along with the header in the returned message.
Args:
timeout: timeouts.PolledTimeout to use fo... | [
"Read",
"a",
"message",
"from",
"this",
"transport",
"and",
"return",
"it",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/filesync_service.py#L415-L461 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | _lazy_load_units_by_code | def _lazy_load_units_by_code():
"""Populate dict of units by code iff UNITS_BY_CODE is empty."""
if UNITS_BY_CODE:
# already populated
return
for unit in units.UNITS_BY_NAME.values():
UNITS_BY_CODE[unit.code] = unit | python | def _lazy_load_units_by_code():
"""Populate dict of units by code iff UNITS_BY_CODE is empty."""
if UNITS_BY_CODE:
# already populated
return
for unit in units.UNITS_BY_NAME.values():
UNITS_BY_CODE[unit.code] = unit | [
"def",
"_lazy_load_units_by_code",
"(",
")",
":",
"if",
"UNITS_BY_CODE",
":",
"# already populated",
"return",
"for",
"unit",
"in",
"units",
".",
"UNITS_BY_NAME",
".",
"values",
"(",
")",
":",
"UNITS_BY_CODE",
"[",
"unit",
".",
"code",
"]",
"=",
"unit"
] | Populate dict of units by code iff UNITS_BY_CODE is empty. | [
"Populate",
"dict",
"of",
"units",
"by",
"code",
"iff",
"UNITS_BY_CODE",
"is",
"empty",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L52-L59 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | _populate_basic_data | def _populate_basic_data(mfg_event, record):
"""Copies data from the OpenHTF TestRecord to the MfgEvent proto."""
# TODO:
# * Missing in proto: set run name from metadata.
# * `part_tags` field on proto is unused
# * `timings` field on proto is unused.
# * Handle arbitrary units as uom_code/uom_suff... | python | def _populate_basic_data(mfg_event, record):
"""Copies data from the OpenHTF TestRecord to the MfgEvent proto."""
# TODO:
# * Missing in proto: set run name from metadata.
# * `part_tags` field on proto is unused
# * `timings` field on proto is unused.
# * Handle arbitrary units as uom_code/uom_suff... | [
"def",
"_populate_basic_data",
"(",
"mfg_event",
",",
"record",
")",
":",
"# TODO:",
"# * Missing in proto: set run name from metadata.",
"# * `part_tags` field on proto is unused",
"# * `timings` field on proto is unused.",
"# * Handle arbitrary units as uom_code/uom_suffix.",
"# ... | Copies data from the OpenHTF TestRecord to the MfgEvent proto. | [
"Copies",
"data",
"from",
"the",
"OpenHTF",
"TestRecord",
"to",
"the",
"MfgEvent",
"proto",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L105-L159 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | _attach_record_as_json | def _attach_record_as_json(mfg_event, record):
"""Attach a copy of the record as JSON so we have an un-mangled copy."""
attachment = mfg_event.attachment.add()
attachment.name = TEST_RECORD_ATTACHMENT_NAME
test_record_dict = htf_data.convert_to_base_types(record)
attachment.value_binary = _convert_object_to_j... | python | def _attach_record_as_json(mfg_event, record):
"""Attach a copy of the record as JSON so we have an un-mangled copy."""
attachment = mfg_event.attachment.add()
attachment.name = TEST_RECORD_ATTACHMENT_NAME
test_record_dict = htf_data.convert_to_base_types(record)
attachment.value_binary = _convert_object_to_j... | [
"def",
"_attach_record_as_json",
"(",
"mfg_event",
",",
"record",
")",
":",
"attachment",
"=",
"mfg_event",
".",
"attachment",
".",
"add",
"(",
")",
"attachment",
".",
"name",
"=",
"TEST_RECORD_ATTACHMENT_NAME",
"test_record_dict",
"=",
"htf_data",
".",
"convert_t... | Attach a copy of the record as JSON so we have an un-mangled copy. | [
"Attach",
"a",
"copy",
"of",
"the",
"record",
"as",
"JSON",
"so",
"we",
"have",
"an",
"un",
"-",
"mangled",
"copy",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L162-L168 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | _attach_config | def _attach_config(mfg_event, record):
"""Attaches the OpenHTF config file as JSON."""
if 'config' not in record.metadata:
return
attachment = mfg_event.attachment.add()
attachment.name = 'config'
attachment.value_binary = _convert_object_to_json(record.metadata['config'])
attachment.type = test_runs_pb... | python | def _attach_config(mfg_event, record):
"""Attaches the OpenHTF config file as JSON."""
if 'config' not in record.metadata:
return
attachment = mfg_event.attachment.add()
attachment.name = 'config'
attachment.value_binary = _convert_object_to_json(record.metadata['config'])
attachment.type = test_runs_pb... | [
"def",
"_attach_config",
"(",
"mfg_event",
",",
"record",
")",
":",
"if",
"'config'",
"not",
"in",
"record",
".",
"metadata",
":",
"return",
"attachment",
"=",
"mfg_event",
".",
"attachment",
".",
"add",
"(",
")",
"attachment",
".",
"name",
"=",
"'config'"... | Attaches the OpenHTF config file as JSON. | [
"Attaches",
"the",
"OpenHTF",
"config",
"file",
"as",
"JSON",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L186-L193 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | phase_uniquizer | def phase_uniquizer(all_phases):
"""Makes the names of phase measurement and attachments unique.
This function will make the names of measurements and attachments unique.
It modifies the input all_phases.
Args:
all_phases: the phases to make unique
Returns:
the phases now modified.
"""
measurem... | python | def phase_uniquizer(all_phases):
"""Makes the names of phase measurement and attachments unique.
This function will make the names of measurements and attachments unique.
It modifies the input all_phases.
Args:
all_phases: the phases to make unique
Returns:
the phases now modified.
"""
measurem... | [
"def",
"phase_uniquizer",
"(",
"all_phases",
")",
":",
"measurement_name_maker",
"=",
"UniqueNameMaker",
"(",
"itertools",
".",
"chain",
".",
"from_iterable",
"(",
"phase",
".",
"measurements",
".",
"keys",
"(",
")",
"for",
"phase",
"in",
"all_phases",
"if",
"... | Makes the names of phase measurement and attachments unique.
This function will make the names of measurements and attachments unique.
It modifies the input all_phases.
Args:
all_phases: the phases to make unique
Returns:
the phases now modified. | [
"Makes",
"the",
"names",
"of",
"phase",
"measurement",
"and",
"attachments",
"unique",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L224-L261 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | multidim_measurement_to_attachment | def multidim_measurement_to_attachment(name, measurement):
"""Convert a multi-dim measurement to an `openhtf.test_record.Attachment`."""
dimensions = list(measurement.dimensions)
if measurement.units:
dimensions.append(
measurements.Dimension.from_unit_descriptor(measurement.units))
dims = []
fo... | python | def multidim_measurement_to_attachment(name, measurement):
"""Convert a multi-dim measurement to an `openhtf.test_record.Attachment`."""
dimensions = list(measurement.dimensions)
if measurement.units:
dimensions.append(
measurements.Dimension.from_unit_descriptor(measurement.units))
dims = []
fo... | [
"def",
"multidim_measurement_to_attachment",
"(",
"name",
",",
"measurement",
")",
":",
"dimensions",
"=",
"list",
"(",
"measurement",
".",
"dimensions",
")",
"if",
"measurement",
".",
"units",
":",
"dimensions",
".",
"append",
"(",
"measurements",
".",
"Dimensi... | Convert a multi-dim measurement to an `openhtf.test_record.Attachment`. | [
"Convert",
"a",
"multi",
"-",
"dim",
"measurement",
"to",
"an",
"openhtf",
".",
"test_record",
".",
"Attachment",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L264-L300 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | convert_multidim_measurements | def convert_multidim_measurements(all_phases):
"""Converts each multidim measurements into attachments for all phases.."""
# Combine actual attachments with attachments we make from multi-dim
# measurements.
attachment_names = list(itertools.chain.from_iterable(
phase.attachments.keys() for phase in all_p... | python | def convert_multidim_measurements(all_phases):
"""Converts each multidim measurements into attachments for all phases.."""
# Combine actual attachments with attachments we make from multi-dim
# measurements.
attachment_names = list(itertools.chain.from_iterable(
phase.attachments.keys() for phase in all_p... | [
"def",
"convert_multidim_measurements",
"(",
"all_phases",
")",
":",
"# Combine actual attachments with attachments we make from multi-dim",
"# measurements.",
"attachment_names",
"=",
"list",
"(",
"itertools",
".",
"chain",
".",
"from_iterable",
"(",
"phase",
".",
"attachmen... | Converts each multidim measurements into attachments for all phases.. | [
"Converts",
"each",
"multidim",
"measurements",
"into",
"attachments",
"for",
"all",
"phases",
".."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L303-L324 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | attachment_to_multidim_measurement | def attachment_to_multidim_measurement(attachment, name=None):
"""Convert an OpenHTF test record attachment to a multi-dim measurement.
This is a best effort attempt to reverse, as some data is lost in converting
from a multidim to an attachment.
Args:
attachment: an `openhtf.test_record.Attachment` from ... | python | def attachment_to_multidim_measurement(attachment, name=None):
"""Convert an OpenHTF test record attachment to a multi-dim measurement.
This is a best effort attempt to reverse, as some data is lost in converting
from a multidim to an attachment.
Args:
attachment: an `openhtf.test_record.Attachment` from ... | [
"def",
"attachment_to_multidim_measurement",
"(",
"attachment",
",",
"name",
"=",
"None",
")",
":",
"data",
"=",
"json",
".",
"loads",
"(",
"attachment",
".",
"data",
")",
"name",
"=",
"name",
"or",
"data",
".",
"get",
"(",
"'name'",
")",
"# attachment_dim... | Convert an OpenHTF test record attachment to a multi-dim measurement.
This is a best effort attempt to reverse, as some data is lost in converting
from a multidim to an attachment.
Args:
attachment: an `openhtf.test_record.Attachment` from a multi-dim.
name: an optional name for the measurement. If not... | [
"Convert",
"an",
"OpenHTF",
"test",
"record",
"attachment",
"to",
"a",
"multi",
"-",
"dim",
"measurement",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L427-L497 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | PhaseCopier._copy_unidimensional_measurement | def _copy_unidimensional_measurement(
self, phase, name, measurement, mfg_event):
"""Copy uni-dimensional measurements to the MfgEvent."""
mfg_measurement = mfg_event.measurement.add()
# Copy basic measurement fields.
mfg_measurement.name = name
if measurement.docstring:
mfg_measurement... | python | def _copy_unidimensional_measurement(
self, phase, name, measurement, mfg_event):
"""Copy uni-dimensional measurements to the MfgEvent."""
mfg_measurement = mfg_event.measurement.add()
# Copy basic measurement fields.
mfg_measurement.name = name
if measurement.docstring:
mfg_measurement... | [
"def",
"_copy_unidimensional_measurement",
"(",
"self",
",",
"phase",
",",
"name",
",",
"measurement",
",",
"mfg_event",
")",
":",
"mfg_measurement",
"=",
"mfg_event",
".",
"measurement",
".",
"add",
"(",
")",
"# Copy basic measurement fields.",
"mfg_measurement",
"... | Copy uni-dimensional measurements to the MfgEvent. | [
"Copy",
"uni",
"-",
"dimensional",
"measurements",
"to",
"the",
"MfgEvent",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L341-L396 | train |
google/openhtf | openhtf/output/proto/mfg_event_converter.py | PhaseCopier._copy_attachment | def _copy_attachment(self, name, data, mimetype, mfg_event):
"""Copies an attachment to mfg_event."""
attachment = mfg_event.attachment.add()
attachment.name = name
if isinstance(data, unicode):
data = data.encode('utf8')
attachment.value_binary = data
if mimetype in test_runs_converter.MI... | python | def _copy_attachment(self, name, data, mimetype, mfg_event):
"""Copies an attachment to mfg_event."""
attachment = mfg_event.attachment.add()
attachment.name = name
if isinstance(data, unicode):
data = data.encode('utf8')
attachment.value_binary = data
if mimetype in test_runs_converter.MI... | [
"def",
"_copy_attachment",
"(",
"self",
",",
"name",
",",
"data",
",",
"mimetype",
",",
"mfg_event",
")",
":",
"attachment",
"=",
"mfg_event",
".",
"attachment",
".",
"add",
"(",
")",
"attachment",
".",
"name",
"=",
"name",
"if",
"isinstance",
"(",
"data... | Copies an attachment to mfg_event. | [
"Copies",
"an",
"attachment",
"to",
"mfg_event",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/output/proto/mfg_event_converter.py#L403-L415 | train |
google/openhtf | openhtf/plugs/usb/adb_protocol.py | AdbStream.write | def write(self, data, timeout_ms=None):
"""Write data to this stream.
Args:
data: Data to write.
timeout_ms: Timeout to use for the write/Ack transaction, in
milliseconds (or as a PolledTimeout object).
Raises:
AdbProtocolError: If an ACK is not received.
AdbStreamClosedErr... | python | def write(self, data, timeout_ms=None):
"""Write data to this stream.
Args:
data: Data to write.
timeout_ms: Timeout to use for the write/Ack transaction, in
milliseconds (or as a PolledTimeout object).
Raises:
AdbProtocolError: If an ACK is not received.
AdbStreamClosedErr... | [
"def",
"write",
"(",
"self",
",",
"data",
",",
"timeout_ms",
"=",
"None",
")",
":",
"timeout",
"=",
"timeouts",
".",
"PolledTimeout",
".",
"from_millis",
"(",
"timeout_ms",
")",
"# Break the data up into our transport's maxdata sized WRTE messages.",
"while",
"data",
... | Write data to this stream.
Args:
data: Data to write.
timeout_ms: Timeout to use for the write/Ack transaction, in
milliseconds (or as a PolledTimeout object).
Raises:
AdbProtocolError: If an ACK is not received.
AdbStreamClosedError: If the stream is already closed, or gets cl... | [
"Write",
"data",
"to",
"this",
"stream",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_protocol.py#L167-L185 | train |
google/openhtf | openhtf/plugs/usb/adb_protocol.py | AdbStream.read | def read(self, length=0, timeout_ms=None):
"""Reads data from the remote end of this stream.
Internally, this data will have been contained in AdbMessages, but
users of streams shouldn't need to care about the transport mechanism.
Args:
length: If provided, the number of bytes to read, otherwise... | python | def read(self, length=0, timeout_ms=None):
"""Reads data from the remote end of this stream.
Internally, this data will have been contained in AdbMessages, but
users of streams shouldn't need to care about the transport mechanism.
Args:
length: If provided, the number of bytes to read, otherwise... | [
"def",
"read",
"(",
"self",
",",
"length",
"=",
"0",
",",
"timeout_ms",
"=",
"None",
")",
":",
"return",
"self",
".",
"_transport",
".",
"read",
"(",
"length",
",",
"timeouts",
".",
"PolledTimeout",
".",
"from_millis",
"(",
"timeout_ms",
")",
")"
] | Reads data from the remote end of this stream.
Internally, this data will have been contained in AdbMessages, but
users of streams shouldn't need to care about the transport mechanism.
Args:
length: If provided, the number of bytes to read, otherwise all available
data will be returned (at l... | [
"Reads",
"data",
"from",
"the",
"remote",
"end",
"of",
"this",
"stream",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_protocol.py#L187-L209 | train |
google/openhtf | openhtf/plugs/usb/adb_protocol.py | AdbStream.read_until_close | def read_until_close(self, timeout_ms=None):
"""Yield data until this stream is closed.
Args:
timeout_ms: Timeout in milliseconds to keep reading (or a PolledTimeout
object).
Yields:
Data read from a single call to self.read(), until the stream is closed
or timeout is reached.
... | python | def read_until_close(self, timeout_ms=None):
"""Yield data until this stream is closed.
Args:
timeout_ms: Timeout in milliseconds to keep reading (or a PolledTimeout
object).
Yields:
Data read from a single call to self.read(), until the stream is closed
or timeout is reached.
... | [
"def",
"read_until_close",
"(",
"self",
",",
"timeout_ms",
"=",
"None",
")",
":",
"while",
"True",
":",
"try",
":",
"yield",
"self",
".",
"read",
"(",
"timeout_ms",
"=",
"timeout_ms",
")",
"except",
"usb_exceptions",
".",
"AdbStreamClosedError",
":",
"break"... | Yield data until this stream is closed.
Args:
timeout_ms: Timeout in milliseconds to keep reading (or a PolledTimeout
object).
Yields:
Data read from a single call to self.read(), until the stream is closed
or timeout is reached.
Raises:
AdbTimeoutError: On timeout. | [
"Yield",
"data",
"until",
"this",
"stream",
"is",
"closed",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_protocol.py#L211-L229 | train |
google/openhtf | openhtf/plugs/usb/adb_protocol.py | AdbStreamTransport._set_or_check_remote_id | def _set_or_check_remote_id(self, remote_id):
"""Set or check the remote id."""
if not self.remote_id:
assert self.closed_state == self.ClosedState.PENDING, 'Bad ClosedState!'
self.remote_id = remote_id
self.closed_state = self.ClosedState.OPEN
elif self.remote_id != remote_id:
raise... | python | def _set_or_check_remote_id(self, remote_id):
"""Set or check the remote id."""
if not self.remote_id:
assert self.closed_state == self.ClosedState.PENDING, 'Bad ClosedState!'
self.remote_id = remote_id
self.closed_state = self.ClosedState.OPEN
elif self.remote_id != remote_id:
raise... | [
"def",
"_set_or_check_remote_id",
"(",
"self",
",",
"remote_id",
")",
":",
"if",
"not",
"self",
".",
"remote_id",
":",
"assert",
"self",
".",
"closed_state",
"==",
"self",
".",
"ClosedState",
".",
"PENDING",
",",
"'Bad ClosedState!'",
"self",
".",
"remote_id",... | Set or check the remote id. | [
"Set",
"or",
"check",
"the",
"remote",
"id",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_protocol.py#L277-L285 | train |
google/openhtf | openhtf/plugs/usb/adb_protocol.py | AdbStreamTransport._handle_message | def _handle_message(self, message, handle_wrte=True):
"""Handle a message that was read for this stream.
For each message type, this means:
OKAY: Check id's and make sure we are expecting an OKAY. Clear the
self._expecting_okay flag so any pending write()'s know.
CLSE: Set our internal sta... | python | def _handle_message(self, message, handle_wrte=True):
"""Handle a message that was read for this stream.
For each message type, this means:
OKAY: Check id's and make sure we are expecting an OKAY. Clear the
self._expecting_okay flag so any pending write()'s know.
CLSE: Set our internal sta... | [
"def",
"_handle_message",
"(",
"self",
",",
"message",
",",
"handle_wrte",
"=",
"True",
")",
":",
"if",
"message",
".",
"command",
"==",
"'OKAY'",
":",
"self",
".",
"_set_or_check_remote_id",
"(",
"message",
".",
"arg0",
")",
"if",
"not",
"self",
".",
"_... | Handle a message that was read for this stream.
For each message type, this means:
OKAY: Check id's and make sure we are expecting an OKAY. Clear the
self._expecting_okay flag so any pending write()'s know.
CLSE: Set our internal state to closed.
WRTE: Add the data read to our internal r... | [
"Handle",
"a",
"message",
"that",
"was",
"read",
"for",
"this",
"stream",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_protocol.py#L314-L345 | train |
google/openhtf | openhtf/plugs/usb/adb_protocol.py | AdbStreamTransport._read_messages_until_true | def _read_messages_until_true(self, predicate, timeout):
"""Read a message from this stream and handle it.
This method tries to read a message from this stream, blocking until a
message is read. Once read, it will handle it accordingly by calling
self._handle_message().
This is repeated as long a... | python | def _read_messages_until_true(self, predicate, timeout):
"""Read a message from this stream and handle it.
This method tries to read a message from this stream, blocking until a
message is read. Once read, it will handle it accordingly by calling
self._handle_message().
This is repeated as long a... | [
"def",
"_read_messages_until_true",
"(",
"self",
",",
"predicate",
",",
"timeout",
")",
":",
"while",
"not",
"predicate",
"(",
")",
":",
"# Hold the message_received Lock while we try to acquire the reader_lock",
"# and waiting on the message_received condition, to prevent another ... | Read a message from this stream and handle it.
This method tries to read a message from this stream, blocking until a
message is read. Once read, it will handle it accordingly by calling
self._handle_message().
This is repeated as long as predicate() returns False. There is some
locking used int... | [
"Read",
"a",
"message",
"from",
"this",
"stream",
"and",
"handle",
"it",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_protocol.py#L347-L408 | train |
google/openhtf | openhtf/plugs/usb/adb_protocol.py | AdbStreamTransport.ensure_opened | def ensure_opened(self, timeout):
"""Ensure this stream transport was successfully opened.
Checks to make sure we receive our initial OKAY message. This must be
called after creating this AdbStreamTransport and before calling read() or
write().
Args:
timeout: timeouts.PolledTimeout to use f... | python | def ensure_opened(self, timeout):
"""Ensure this stream transport was successfully opened.
Checks to make sure we receive our initial OKAY message. This must be
called after creating this AdbStreamTransport and before calling read() or
write().
Args:
timeout: timeouts.PolledTimeout to use f... | [
"def",
"ensure_opened",
"(",
"self",
",",
"timeout",
")",
":",
"self",
".",
"_handle_message",
"(",
"self",
".",
"adb_connection",
".",
"read_for_stream",
"(",
"self",
",",
"timeout",
")",
",",
"handle_wrte",
"=",
"False",
")",
"return",
"self",
".",
"is_o... | Ensure this stream transport was successfully opened.
Checks to make sure we receive our initial OKAY message. This must be
called after creating this AdbStreamTransport and before calling read() or
write().
Args:
timeout: timeouts.PolledTimeout to use for this operation.
Returns:
Tr... | [
"Ensure",
"this",
"stream",
"transport",
"was",
"successfully",
"opened",
"."
] | 655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09 | https://github.com/google/openhtf/blob/655e85df7134db7bdf8f8fdd6ff9a6bf932e7b09/openhtf/plugs/usb/adb_protocol.py#L410-L430 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.