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 |
---|---|---|---|---|---|---|---|---|---|---|---|
iotile/coretools
|
transport_plugins/jlink/iotile_transport_jlink/jlink.py
|
JLinkAdapter.probe_async
|
def probe_async(self, callback):
"""Send advertisements for all connected devices.
Args:
callback (callable): A callback for when the probe operation has completed.
callback should have signature callback(adapter_id, success, failure_reason) where:
success: bool
failure_reason: None if success is True, otherwise a reason for why we could not probe
"""
def _on_finished(_name, control_info, exception):
if exception is not None:
callback(self.id, False, str(exception))
return
self._control_info = control_info
try:
info = {
'connection_string': "direct",
'uuid': control_info.uuid,
'signal_strength': 100
}
self._trigger_callback('on_scan', self.id, info, self.ExpirationTime)
finally:
callback(self.id, True, None)
self._control_thread.command(JLinkControlThread.FIND_CONTROL, _on_finished, self._device_info.ram_start, self._device_info.ram_size)
|
python
|
def probe_async(self, callback):
"""Send advertisements for all connected devices.
Args:
callback (callable): A callback for when the probe operation has completed.
callback should have signature callback(adapter_id, success, failure_reason) where:
success: bool
failure_reason: None if success is True, otherwise a reason for why we could not probe
"""
def _on_finished(_name, control_info, exception):
if exception is not None:
callback(self.id, False, str(exception))
return
self._control_info = control_info
try:
info = {
'connection_string': "direct",
'uuid': control_info.uuid,
'signal_strength': 100
}
self._trigger_callback('on_scan', self.id, info, self.ExpirationTime)
finally:
callback(self.id, True, None)
self._control_thread.command(JLinkControlThread.FIND_CONTROL, _on_finished, self._device_info.ram_start, self._device_info.ram_size)
|
[
"def",
"probe_async",
"(",
"self",
",",
"callback",
")",
":",
"def",
"_on_finished",
"(",
"_name",
",",
"control_info",
",",
"exception",
")",
":",
"if",
"exception",
"is",
"not",
"None",
":",
"callback",
"(",
"self",
".",
"id",
",",
"False",
",",
"str",
"(",
"exception",
")",
")",
"return",
"self",
".",
"_control_info",
"=",
"control_info",
"try",
":",
"info",
"=",
"{",
"'connection_string'",
":",
"\"direct\"",
",",
"'uuid'",
":",
"control_info",
".",
"uuid",
",",
"'signal_strength'",
":",
"100",
"}",
"self",
".",
"_trigger_callback",
"(",
"'on_scan'",
",",
"self",
".",
"id",
",",
"info",
",",
"self",
".",
"ExpirationTime",
")",
"finally",
":",
"callback",
"(",
"self",
".",
"id",
",",
"True",
",",
"None",
")",
"self",
".",
"_control_thread",
".",
"command",
"(",
"JLinkControlThread",
".",
"FIND_CONTROL",
",",
"_on_finished",
",",
"self",
".",
"_device_info",
".",
"ram_start",
",",
"self",
".",
"_device_info",
".",
"ram_size",
")"
] |
Send advertisements for all connected devices.
Args:
callback (callable): A callback for when the probe operation has completed.
callback should have signature callback(adapter_id, success, failure_reason) where:
success: bool
failure_reason: None if success is True, otherwise a reason for why we could not probe
|
[
"Send",
"advertisements",
"for",
"all",
"connected",
"devices",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/jlink/iotile_transport_jlink/jlink.py#L179-L207
|
train
|
iotile/coretools
|
transport_plugins/jlink/iotile_transport_jlink/jlink.py
|
JLinkAdapter._open_debug_interface
|
def _open_debug_interface(self, conn_id, callback, connection_string=None):
"""Enable debug interface for this IOTile device
Args:
conn_id (int): the unique identifier for the connection
callback (callback): Callback to be called when this command finishes
callback(conn_id, adapter_id, success, failure_reason)
"""
self._try_connect(connection_string)
callback(conn_id, self.id, True, None)
|
python
|
def _open_debug_interface(self, conn_id, callback, connection_string=None):
"""Enable debug interface for this IOTile device
Args:
conn_id (int): the unique identifier for the connection
callback (callback): Callback to be called when this command finishes
callback(conn_id, adapter_id, success, failure_reason)
"""
self._try_connect(connection_string)
callback(conn_id, self.id, True, None)
|
[
"def",
"_open_debug_interface",
"(",
"self",
",",
"conn_id",
",",
"callback",
",",
"connection_string",
"=",
"None",
")",
":",
"self",
".",
"_try_connect",
"(",
"connection_string",
")",
"callback",
"(",
"conn_id",
",",
"self",
".",
"id",
",",
"True",
",",
"None",
")"
] |
Enable debug interface for this IOTile device
Args:
conn_id (int): the unique identifier for the connection
callback (callback): Callback to be called when this command finishes
callback(conn_id, adapter_id, success, failure_reason)
|
[
"Enable",
"debug",
"interface",
"for",
"this",
"IOTile",
"device"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/jlink/iotile_transport_jlink/jlink.py#L305-L314
|
train
|
iotile/coretools
|
iotileemulate/iotile/emulate/virtual/peripheral_tile.py
|
EmulatedPeripheralTile._reset_vector
|
async def _reset_vector(self):
"""Main background task for the tile executive.
The tile executive is in charge registering the tile with the
controller and then handing control over to the tile's application
firmware after proper configuration values have been received.
"""
self._logger.info("Tile %s at address %d is starting from reset", self.name, self.address)
try:
address, run_level, debug = await self._device.emulator.await_rpc(8, rpcs.REGISTER_TILE, *self._registration_tuple())
except:
self._logger.exception("Error registering tile: address=%d, name=%s", self.address, self.name)
raise
self.debug_mode = bool(debug)
self.run_level = run_level
self._logger.info("Tile at address %d registered itself, received address=%d, runlevel=%d and debug=%d", self.address, address, run_level, debug)
self._registered.set()
# If we are in safe mode we do not run the main application
# loop.
if run_level == RunLevel.SAFE_MODE:
self.initialized.set()
return
if run_level == RunLevel.START_ON_COMMAND:
await self._start_received.wait()
self._hosted_app_running.set()
await self._application_main()
|
python
|
async def _reset_vector(self):
"""Main background task for the tile executive.
The tile executive is in charge registering the tile with the
controller and then handing control over to the tile's application
firmware after proper configuration values have been received.
"""
self._logger.info("Tile %s at address %d is starting from reset", self.name, self.address)
try:
address, run_level, debug = await self._device.emulator.await_rpc(8, rpcs.REGISTER_TILE, *self._registration_tuple())
except:
self._logger.exception("Error registering tile: address=%d, name=%s", self.address, self.name)
raise
self.debug_mode = bool(debug)
self.run_level = run_level
self._logger.info("Tile at address %d registered itself, received address=%d, runlevel=%d and debug=%d", self.address, address, run_level, debug)
self._registered.set()
# If we are in safe mode we do not run the main application
# loop.
if run_level == RunLevel.SAFE_MODE:
self.initialized.set()
return
if run_level == RunLevel.START_ON_COMMAND:
await self._start_received.wait()
self._hosted_app_running.set()
await self._application_main()
|
[
"async",
"def",
"_reset_vector",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Tile %s at address %d is starting from reset\"",
",",
"self",
".",
"name",
",",
"self",
".",
"address",
")",
"try",
":",
"address",
",",
"run_level",
",",
"debug",
"=",
"await",
"self",
".",
"_device",
".",
"emulator",
".",
"await_rpc",
"(",
"8",
",",
"rpcs",
".",
"REGISTER_TILE",
",",
"*",
"self",
".",
"_registration_tuple",
"(",
")",
")",
"except",
":",
"self",
".",
"_logger",
".",
"exception",
"(",
"\"Error registering tile: address=%d, name=%s\"",
",",
"self",
".",
"address",
",",
"self",
".",
"name",
")",
"raise",
"self",
".",
"debug_mode",
"=",
"bool",
"(",
"debug",
")",
"self",
".",
"run_level",
"=",
"run_level",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Tile at address %d registered itself, received address=%d, runlevel=%d and debug=%d\"",
",",
"self",
".",
"address",
",",
"address",
",",
"run_level",
",",
"debug",
")",
"self",
".",
"_registered",
".",
"set",
"(",
")",
"# If we are in safe mode we do not run the main application",
"# loop.",
"if",
"run_level",
"==",
"RunLevel",
".",
"SAFE_MODE",
":",
"self",
".",
"initialized",
".",
"set",
"(",
")",
"return",
"if",
"run_level",
"==",
"RunLevel",
".",
"START_ON_COMMAND",
":",
"await",
"self",
".",
"_start_received",
".",
"wait",
"(",
")",
"self",
".",
"_hosted_app_running",
".",
"set",
"(",
")",
"await",
"self",
".",
"_application_main",
"(",
")"
] |
Main background task for the tile executive.
The tile executive is in charge registering the tile with the
controller and then handing control over to the tile's application
firmware after proper configuration values have been received.
|
[
"Main",
"background",
"task",
"for",
"the",
"tile",
"executive",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotileemulate/iotile/emulate/virtual/peripheral_tile.py#L55-L87
|
train
|
iotile/coretools
|
iotileemulate/iotile/emulate/virtual/peripheral_tile.py
|
EmulatedPeripheralTile._handle_reset
|
def _handle_reset(self):
"""Reset this tile.
This process needs to trigger the peripheral tile to reregister itself
with the controller and get new configuration variables. It also
needs to clear app_running.
"""
self._registered.clear()
self._start_received.clear()
self._hosted_app_running.clear()
super(EmulatedPeripheralTile, self)._handle_reset()
|
python
|
def _handle_reset(self):
"""Reset this tile.
This process needs to trigger the peripheral tile to reregister itself
with the controller and get new configuration variables. It also
needs to clear app_running.
"""
self._registered.clear()
self._start_received.clear()
self._hosted_app_running.clear()
super(EmulatedPeripheralTile, self)._handle_reset()
|
[
"def",
"_handle_reset",
"(",
"self",
")",
":",
"self",
".",
"_registered",
".",
"clear",
"(",
")",
"self",
".",
"_start_received",
".",
"clear",
"(",
")",
"self",
".",
"_hosted_app_running",
".",
"clear",
"(",
")",
"super",
"(",
"EmulatedPeripheralTile",
",",
"self",
")",
".",
"_handle_reset",
"(",
")"
] |
Reset this tile.
This process needs to trigger the peripheral tile to reregister itself
with the controller and get new configuration variables. It also
needs to clear app_running.
|
[
"Reset",
"this",
"tile",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotileemulate/iotile/emulate/virtual/peripheral_tile.py#L95-L107
|
train
|
iotile/coretools
|
iotilegateway/iotilegateway/gateway.py
|
IOTileGateway.start
|
async def start(self):
"""Start the gateway."""
self._logger.info("Starting all device adapters")
await self.device_manager.start()
self._logger.info("Starting all servers")
for server in self.servers:
await server.start()
|
python
|
async def start(self):
"""Start the gateway."""
self._logger.info("Starting all device adapters")
await self.device_manager.start()
self._logger.info("Starting all servers")
for server in self.servers:
await server.start()
|
[
"async",
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Starting all device adapters\"",
")",
"await",
"self",
".",
"device_manager",
".",
"start",
"(",
")",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Starting all servers\"",
")",
"for",
"server",
"in",
"self",
".",
"servers",
":",
"await",
"server",
".",
"start",
"(",
")"
] |
Start the gateway.
|
[
"Start",
"the",
"gateway",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilegateway/iotilegateway/gateway.py#L49-L57
|
train
|
iotile/coretools
|
iotilegateway/iotilegateway/gateway.py
|
IOTileGateway.stop
|
async def stop(self):
"""Stop the gateway manager and synchronously wait for it to stop."""
self._logger.info("Stopping all servers")
for server in self.servers:
await server.stop()
self._logger.info("Stopping all device adapters")
await self.device_manager.stop()
|
python
|
async def stop(self):
"""Stop the gateway manager and synchronously wait for it to stop."""
self._logger.info("Stopping all servers")
for server in self.servers:
await server.stop()
self._logger.info("Stopping all device adapters")
await self.device_manager.stop()
|
[
"async",
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Stopping all servers\"",
")",
"for",
"server",
"in",
"self",
".",
"servers",
":",
"await",
"server",
".",
"stop",
"(",
")",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Stopping all device adapters\"",
")",
"await",
"self",
".",
"device_manager",
".",
"stop",
"(",
")"
] |
Stop the gateway manager and synchronously wait for it to stop.
|
[
"Stop",
"the",
"gateway",
"manager",
"and",
"synchronously",
"wait",
"for",
"it",
"to",
"stop",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilegateway/iotilegateway/gateway.py#L59-L67
|
train
|
iotile/coretools
|
iotileship/iotile/ship/scripts/iotile_ship.py
|
main
|
def main(argv=None):
"""Main entry point for iotile-ship recipe runner.
This is the iotile-ship command line program.
Args:
argv (list of str): An optional set of command line
parameters. If not passed, these are taken from
sys.argv.
"""
if argv is None:
argv = sys.argv[1:]
parser = build_args()
args = parser.parse_args(args=argv)
recipe_name, _ext = os.path.splitext(os.path.basename(args.recipe))
rm = RecipeManager()
rm.add_recipe_folder(os.path.dirname(args.recipe), whitelist=[os.path.basename(args.recipe)])
recipe = rm.get_recipe(recipe_name)
if args.archive is not None:
print("Archiving recipe into %s" % args.archive)
recipe.archive(args.archive)
return 0
if args.info:
print(recipe)
return 0
variables = load_variables(args.define, args.config)
success = 0
start_time = time.time()
if args.loop is None:
try:
recipe.run(variables)
success += 1
except IOTileException as exc:
print("Error running recipe: %s" % str(exc))
return 1
else:
while True:
value = input("Enter value for loop variable %s (return to stop): " % args.loop)
if value == '':
break
local_vars = dict(**variables)
local_vars[args.loop] = value
try:
recipe.run(local_vars)
success += 1
except IOTileException as exc:
print("--> ERROR processing loop variable %s: %s" % (value, str(exc)))
end_time = time.time()
total_time = end_time - start_time
if success == 0:
per_time = 0.0
else:
per_time = total_time / success
print("Performed %d runs in %.1f seconds (%.1f seconds / run)" % (success, total_time, per_time))
return 0
|
python
|
def main(argv=None):
"""Main entry point for iotile-ship recipe runner.
This is the iotile-ship command line program.
Args:
argv (list of str): An optional set of command line
parameters. If not passed, these are taken from
sys.argv.
"""
if argv is None:
argv = sys.argv[1:]
parser = build_args()
args = parser.parse_args(args=argv)
recipe_name, _ext = os.path.splitext(os.path.basename(args.recipe))
rm = RecipeManager()
rm.add_recipe_folder(os.path.dirname(args.recipe), whitelist=[os.path.basename(args.recipe)])
recipe = rm.get_recipe(recipe_name)
if args.archive is not None:
print("Archiving recipe into %s" % args.archive)
recipe.archive(args.archive)
return 0
if args.info:
print(recipe)
return 0
variables = load_variables(args.define, args.config)
success = 0
start_time = time.time()
if args.loop is None:
try:
recipe.run(variables)
success += 1
except IOTileException as exc:
print("Error running recipe: %s" % str(exc))
return 1
else:
while True:
value = input("Enter value for loop variable %s (return to stop): " % args.loop)
if value == '':
break
local_vars = dict(**variables)
local_vars[args.loop] = value
try:
recipe.run(local_vars)
success += 1
except IOTileException as exc:
print("--> ERROR processing loop variable %s: %s" % (value, str(exc)))
end_time = time.time()
total_time = end_time - start_time
if success == 0:
per_time = 0.0
else:
per_time = total_time / success
print("Performed %d runs in %.1f seconds (%.1f seconds / run)" % (success, total_time, per_time))
return 0
|
[
"def",
"main",
"(",
"argv",
"=",
"None",
")",
":",
"if",
"argv",
"is",
"None",
":",
"argv",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
"parser",
"=",
"build_args",
"(",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
"args",
"=",
"argv",
")",
"recipe_name",
",",
"_ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"os",
".",
"path",
".",
"basename",
"(",
"args",
".",
"recipe",
")",
")",
"rm",
"=",
"RecipeManager",
"(",
")",
"rm",
".",
"add_recipe_folder",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"args",
".",
"recipe",
")",
",",
"whitelist",
"=",
"[",
"os",
".",
"path",
".",
"basename",
"(",
"args",
".",
"recipe",
")",
"]",
")",
"recipe",
"=",
"rm",
".",
"get_recipe",
"(",
"recipe_name",
")",
"if",
"args",
".",
"archive",
"is",
"not",
"None",
":",
"print",
"(",
"\"Archiving recipe into %s\"",
"%",
"args",
".",
"archive",
")",
"recipe",
".",
"archive",
"(",
"args",
".",
"archive",
")",
"return",
"0",
"if",
"args",
".",
"info",
":",
"print",
"(",
"recipe",
")",
"return",
"0",
"variables",
"=",
"load_variables",
"(",
"args",
".",
"define",
",",
"args",
".",
"config",
")",
"success",
"=",
"0",
"start_time",
"=",
"time",
".",
"time",
"(",
")",
"if",
"args",
".",
"loop",
"is",
"None",
":",
"try",
":",
"recipe",
".",
"run",
"(",
"variables",
")",
"success",
"+=",
"1",
"except",
"IOTileException",
"as",
"exc",
":",
"print",
"(",
"\"Error running recipe: %s\"",
"%",
"str",
"(",
"exc",
")",
")",
"return",
"1",
"else",
":",
"while",
"True",
":",
"value",
"=",
"input",
"(",
"\"Enter value for loop variable %s (return to stop): \"",
"%",
"args",
".",
"loop",
")",
"if",
"value",
"==",
"''",
":",
"break",
"local_vars",
"=",
"dict",
"(",
"*",
"*",
"variables",
")",
"local_vars",
"[",
"args",
".",
"loop",
"]",
"=",
"value",
"try",
":",
"recipe",
".",
"run",
"(",
"local_vars",
")",
"success",
"+=",
"1",
"except",
"IOTileException",
"as",
"exc",
":",
"print",
"(",
"\"--> ERROR processing loop variable %s: %s\"",
"%",
"(",
"value",
",",
"str",
"(",
"exc",
")",
")",
")",
"end_time",
"=",
"time",
".",
"time",
"(",
")",
"total_time",
"=",
"end_time",
"-",
"start_time",
"if",
"success",
"==",
"0",
":",
"per_time",
"=",
"0.0",
"else",
":",
"per_time",
"=",
"total_time",
"/",
"success",
"print",
"(",
"\"Performed %d runs in %.1f seconds (%.1f seconds / run)\"",
"%",
"(",
"success",
",",
"total_time",
",",
"per_time",
")",
")",
"return",
"0"
] |
Main entry point for iotile-ship recipe runner.
This is the iotile-ship command line program.
Args:
argv (list of str): An optional set of command line
parameters. If not passed, these are taken from
sys.argv.
|
[
"Main",
"entry",
"point",
"for",
"iotile",
"-",
"ship",
"recipe",
"runner",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotileship/iotile/ship/scripts/iotile_ship.py#L59-L129
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Subst.py
|
subst_dict
|
def subst_dict(target, source):
"""Create a dictionary for substitution of special
construction variables.
This translates the following special arguments:
target - the target (object or array of objects),
used to generate the TARGET and TARGETS
construction variables
source - the source (object or array of objects),
used to generate the SOURCES and SOURCE
construction variables
"""
dict = {}
if target:
def get_tgt_subst_proxy(thing):
try:
subst_proxy = thing.get_subst_proxy()
except AttributeError:
subst_proxy = thing # probably a string, just return it
return subst_proxy
tnl = NLWrapper(target, get_tgt_subst_proxy)
dict['TARGETS'] = Targets_or_Sources(tnl)
dict['TARGET'] = Target_or_Source(tnl)
# This is a total cheat, but hopefully this dictionary goes
# away soon anyway. We just let these expand to $TARGETS
# because that's "good enough" for the use of ToolSurrogates
# (see test/ToolSurrogate.py) to generate documentation.
dict['CHANGED_TARGETS'] = '$TARGETS'
dict['UNCHANGED_TARGETS'] = '$TARGETS'
else:
dict['TARGETS'] = NullNodesList
dict['TARGET'] = NullNodesList
if source:
def get_src_subst_proxy(node):
try:
rfile = node.rfile
except AttributeError:
pass
else:
node = rfile()
try:
return node.get_subst_proxy()
except AttributeError:
return node # probably a String, just return it
snl = NLWrapper(source, get_src_subst_proxy)
dict['SOURCES'] = Targets_or_Sources(snl)
dict['SOURCE'] = Target_or_Source(snl)
# This is a total cheat, but hopefully this dictionary goes
# away soon anyway. We just let these expand to $TARGETS
# because that's "good enough" for the use of ToolSurrogates
# (see test/ToolSurrogate.py) to generate documentation.
dict['CHANGED_SOURCES'] = '$SOURCES'
dict['UNCHANGED_SOURCES'] = '$SOURCES'
else:
dict['SOURCES'] = NullNodesList
dict['SOURCE'] = NullNodesList
return dict
|
python
|
def subst_dict(target, source):
"""Create a dictionary for substitution of special
construction variables.
This translates the following special arguments:
target - the target (object or array of objects),
used to generate the TARGET and TARGETS
construction variables
source - the source (object or array of objects),
used to generate the SOURCES and SOURCE
construction variables
"""
dict = {}
if target:
def get_tgt_subst_proxy(thing):
try:
subst_proxy = thing.get_subst_proxy()
except AttributeError:
subst_proxy = thing # probably a string, just return it
return subst_proxy
tnl = NLWrapper(target, get_tgt_subst_proxy)
dict['TARGETS'] = Targets_or_Sources(tnl)
dict['TARGET'] = Target_or_Source(tnl)
# This is a total cheat, but hopefully this dictionary goes
# away soon anyway. We just let these expand to $TARGETS
# because that's "good enough" for the use of ToolSurrogates
# (see test/ToolSurrogate.py) to generate documentation.
dict['CHANGED_TARGETS'] = '$TARGETS'
dict['UNCHANGED_TARGETS'] = '$TARGETS'
else:
dict['TARGETS'] = NullNodesList
dict['TARGET'] = NullNodesList
if source:
def get_src_subst_proxy(node):
try:
rfile = node.rfile
except AttributeError:
pass
else:
node = rfile()
try:
return node.get_subst_proxy()
except AttributeError:
return node # probably a String, just return it
snl = NLWrapper(source, get_src_subst_proxy)
dict['SOURCES'] = Targets_or_Sources(snl)
dict['SOURCE'] = Target_or_Source(snl)
# This is a total cheat, but hopefully this dictionary goes
# away soon anyway. We just let these expand to $TARGETS
# because that's "good enough" for the use of ToolSurrogates
# (see test/ToolSurrogate.py) to generate documentation.
dict['CHANGED_SOURCES'] = '$SOURCES'
dict['UNCHANGED_SOURCES'] = '$SOURCES'
else:
dict['SOURCES'] = NullNodesList
dict['SOURCE'] = NullNodesList
return dict
|
[
"def",
"subst_dict",
"(",
"target",
",",
"source",
")",
":",
"dict",
"=",
"{",
"}",
"if",
"target",
":",
"def",
"get_tgt_subst_proxy",
"(",
"thing",
")",
":",
"try",
":",
"subst_proxy",
"=",
"thing",
".",
"get_subst_proxy",
"(",
")",
"except",
"AttributeError",
":",
"subst_proxy",
"=",
"thing",
"# probably a string, just return it",
"return",
"subst_proxy",
"tnl",
"=",
"NLWrapper",
"(",
"target",
",",
"get_tgt_subst_proxy",
")",
"dict",
"[",
"'TARGETS'",
"]",
"=",
"Targets_or_Sources",
"(",
"tnl",
")",
"dict",
"[",
"'TARGET'",
"]",
"=",
"Target_or_Source",
"(",
"tnl",
")",
"# This is a total cheat, but hopefully this dictionary goes",
"# away soon anyway. We just let these expand to $TARGETS",
"# because that's \"good enough\" for the use of ToolSurrogates",
"# (see test/ToolSurrogate.py) to generate documentation.",
"dict",
"[",
"'CHANGED_TARGETS'",
"]",
"=",
"'$TARGETS'",
"dict",
"[",
"'UNCHANGED_TARGETS'",
"]",
"=",
"'$TARGETS'",
"else",
":",
"dict",
"[",
"'TARGETS'",
"]",
"=",
"NullNodesList",
"dict",
"[",
"'TARGET'",
"]",
"=",
"NullNodesList",
"if",
"source",
":",
"def",
"get_src_subst_proxy",
"(",
"node",
")",
":",
"try",
":",
"rfile",
"=",
"node",
".",
"rfile",
"except",
"AttributeError",
":",
"pass",
"else",
":",
"node",
"=",
"rfile",
"(",
")",
"try",
":",
"return",
"node",
".",
"get_subst_proxy",
"(",
")",
"except",
"AttributeError",
":",
"return",
"node",
"# probably a String, just return it",
"snl",
"=",
"NLWrapper",
"(",
"source",
",",
"get_src_subst_proxy",
")",
"dict",
"[",
"'SOURCES'",
"]",
"=",
"Targets_or_Sources",
"(",
"snl",
")",
"dict",
"[",
"'SOURCE'",
"]",
"=",
"Target_or_Source",
"(",
"snl",
")",
"# This is a total cheat, but hopefully this dictionary goes",
"# away soon anyway. We just let these expand to $TARGETS",
"# because that's \"good enough\" for the use of ToolSurrogates",
"# (see test/ToolSurrogate.py) to generate documentation.",
"dict",
"[",
"'CHANGED_SOURCES'",
"]",
"=",
"'$SOURCES'",
"dict",
"[",
"'UNCHANGED_SOURCES'",
"]",
"=",
"'$SOURCES'",
"else",
":",
"dict",
"[",
"'SOURCES'",
"]",
"=",
"NullNodesList",
"dict",
"[",
"'SOURCE'",
"]",
"=",
"NullNodesList",
"return",
"dict"
] |
Create a dictionary for substitution of special
construction variables.
This translates the following special arguments:
target - the target (object or array of objects),
used to generate the TARGET and TARGETS
construction variables
source - the source (object or array of objects),
used to generate the SOURCES and SOURCE
construction variables
|
[
"Create",
"a",
"dictionary",
"for",
"substitution",
"of",
"special",
"construction",
"variables",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Subst.py#L266-L329
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Subst.py
|
CmdStringHolder.escape
|
def escape(self, escape_func, quote_func=quote_spaces):
"""Escape the string with the supplied function. The
function is expected to take an arbitrary string, then
return it with all special characters escaped and ready
for passing to the command interpreter.
After calling this function, the next call to str() will
return the escaped string.
"""
if self.is_literal():
return escape_func(self.data)
elif ' ' in self.data or '\t' in self.data:
return quote_func(self.data)
else:
return self.data
|
python
|
def escape(self, escape_func, quote_func=quote_spaces):
"""Escape the string with the supplied function. The
function is expected to take an arbitrary string, then
return it with all special characters escaped and ready
for passing to the command interpreter.
After calling this function, the next call to str() will
return the escaped string.
"""
if self.is_literal():
return escape_func(self.data)
elif ' ' in self.data or '\t' in self.data:
return quote_func(self.data)
else:
return self.data
|
[
"def",
"escape",
"(",
"self",
",",
"escape_func",
",",
"quote_func",
"=",
"quote_spaces",
")",
":",
"if",
"self",
".",
"is_literal",
"(",
")",
":",
"return",
"escape_func",
"(",
"self",
".",
"data",
")",
"elif",
"' '",
"in",
"self",
".",
"data",
"or",
"'\\t'",
"in",
"self",
".",
"data",
":",
"return",
"quote_func",
"(",
"self",
".",
"data",
")",
"else",
":",
"return",
"self",
".",
"data"
] |
Escape the string with the supplied function. The
function is expected to take an arbitrary string, then
return it with all special characters escaped and ready
for passing to the command interpreter.
After calling this function, the next call to str() will
return the escaped string.
|
[
"Escape",
"the",
"string",
"with",
"the",
"supplied",
"function",
".",
"The",
"function",
"is",
"expected",
"to",
"take",
"an",
"arbitrary",
"string",
"then",
"return",
"it",
"with",
"all",
"special",
"characters",
"escaped",
"and",
"ready",
"for",
"passing",
"to",
"the",
"command",
"interpreter",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Subst.py#L142-L157
|
train
|
iotile/coretools
|
iotilecore/iotile/core/utilities/formatting.py
|
indent_list
|
def indent_list(inlist, level):
"""Join a list of strings, one per line with 'level' spaces before each one"""
indent = ' '*level
joinstr = '\n' + indent
retval = joinstr.join(inlist)
return indent + retval
|
python
|
def indent_list(inlist, level):
"""Join a list of strings, one per line with 'level' spaces before each one"""
indent = ' '*level
joinstr = '\n' + indent
retval = joinstr.join(inlist)
return indent + retval
|
[
"def",
"indent_list",
"(",
"inlist",
",",
"level",
")",
":",
"indent",
"=",
"' '",
"*",
"level",
"joinstr",
"=",
"'\\n'",
"+",
"indent",
"retval",
"=",
"joinstr",
".",
"join",
"(",
"inlist",
")",
"return",
"indent",
"+",
"retval"
] |
Join a list of strings, one per line with 'level' spaces before each one
|
[
"Join",
"a",
"list",
"of",
"strings",
"one",
"per",
"line",
"with",
"level",
"spaces",
"before",
"each",
"one"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/utilities/formatting.py#L20-L27
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/gfortran.py
|
generate
|
def generate(env):
"""Add Builders and construction variables for gfortran to an
Environment."""
fortran.generate(env)
for dialect in ['F77', 'F90', 'FORTRAN', 'F95', 'F03', 'F08']:
env['%s' % dialect] = 'gfortran'
env['SH%s' % dialect] = '$%s' % dialect
if env['PLATFORM'] in ['cygwin', 'win32']:
env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS' % dialect)
else:
env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS -fPIC' % dialect)
env['INC%sPREFIX' % dialect] = "-I"
env['INC%sSUFFIX' % dialect] = ""
|
python
|
def generate(env):
"""Add Builders and construction variables for gfortran to an
Environment."""
fortran.generate(env)
for dialect in ['F77', 'F90', 'FORTRAN', 'F95', 'F03', 'F08']:
env['%s' % dialect] = 'gfortran'
env['SH%s' % dialect] = '$%s' % dialect
if env['PLATFORM'] in ['cygwin', 'win32']:
env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS' % dialect)
else:
env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS -fPIC' % dialect)
env['INC%sPREFIX' % dialect] = "-I"
env['INC%sSUFFIX' % dialect] = ""
|
[
"def",
"generate",
"(",
"env",
")",
":",
"fortran",
".",
"generate",
"(",
"env",
")",
"for",
"dialect",
"in",
"[",
"'F77'",
",",
"'F90'",
",",
"'FORTRAN'",
",",
"'F95'",
",",
"'F03'",
",",
"'F08'",
"]",
":",
"env",
"[",
"'%s'",
"%",
"dialect",
"]",
"=",
"'gfortran'",
"env",
"[",
"'SH%s'",
"%",
"dialect",
"]",
"=",
"'$%s'",
"%",
"dialect",
"if",
"env",
"[",
"'PLATFORM'",
"]",
"in",
"[",
"'cygwin'",
",",
"'win32'",
"]",
":",
"env",
"[",
"'SH%sFLAGS'",
"%",
"dialect",
"]",
"=",
"SCons",
".",
"Util",
".",
"CLVar",
"(",
"'$%sFLAGS'",
"%",
"dialect",
")",
"else",
":",
"env",
"[",
"'SH%sFLAGS'",
"%",
"dialect",
"]",
"=",
"SCons",
".",
"Util",
".",
"CLVar",
"(",
"'$%sFLAGS -fPIC'",
"%",
"dialect",
")",
"env",
"[",
"'INC%sPREFIX'",
"%",
"dialect",
"]",
"=",
"\"-I\"",
"env",
"[",
"'INC%sSUFFIX'",
"%",
"dialect",
"]",
"=",
"\"\""
] |
Add Builders and construction variables for gfortran to an
Environment.
|
[
"Add",
"Builders",
"and",
"construction",
"variables",
"for",
"gfortran",
"to",
"an",
"Environment",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/gfortran.py#L41-L55
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._extract_device_uuid
|
def _extract_device_uuid(cls, slug):
"""Turn a string slug into a UUID
"""
if len(slug) != 22:
raise ArgumentError("Invalid device slug", slug=slug)
hexdigits = slug[3:]
hexdigits = hexdigits.replace('-', '')
try:
rawbytes = binascii.unhexlify(hexdigits)
words = struct.unpack(">LL", rawbytes)
return (words[0] << 32) | (words[1])
except ValueError as exc:
raise ArgumentError("Could not convert device slug to hex integer", slug=slug, error=str(exc))
|
python
|
def _extract_device_uuid(cls, slug):
"""Turn a string slug into a UUID
"""
if len(slug) != 22:
raise ArgumentError("Invalid device slug", slug=slug)
hexdigits = slug[3:]
hexdigits = hexdigits.replace('-', '')
try:
rawbytes = binascii.unhexlify(hexdigits)
words = struct.unpack(">LL", rawbytes)
return (words[0] << 32) | (words[1])
except ValueError as exc:
raise ArgumentError("Could not convert device slug to hex integer", slug=slug, error=str(exc))
|
[
"def",
"_extract_device_uuid",
"(",
"cls",
",",
"slug",
")",
":",
"if",
"len",
"(",
"slug",
")",
"!=",
"22",
":",
"raise",
"ArgumentError",
"(",
"\"Invalid device slug\"",
",",
"slug",
"=",
"slug",
")",
"hexdigits",
"=",
"slug",
"[",
"3",
":",
"]",
"hexdigits",
"=",
"hexdigits",
".",
"replace",
"(",
"'-'",
",",
"''",
")",
"try",
":",
"rawbytes",
"=",
"binascii",
".",
"unhexlify",
"(",
"hexdigits",
")",
"words",
"=",
"struct",
".",
"unpack",
"(",
"\">LL\"",
",",
"rawbytes",
")",
"return",
"(",
"words",
"[",
"0",
"]",
"<<",
"32",
")",
"|",
"(",
"words",
"[",
"1",
"]",
")",
"except",
"ValueError",
"as",
"exc",
":",
"raise",
"ArgumentError",
"(",
"\"Could not convert device slug to hex integer\"",
",",
"slug",
"=",
"slug",
",",
"error",
"=",
"str",
"(",
"exc",
")",
")"
] |
Turn a string slug into a UUID
|
[
"Turn",
"a",
"string",
"slug",
"into",
"a",
"UUID"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L69-L84
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent.start
|
def start(self):
"""Start this gateway agent."""
self._prepare()
self._disconnector = tornado.ioloop.PeriodicCallback(self._disconnect_hanging_devices, 1000, self._loop)
self._disconnector.start()
|
python
|
def start(self):
"""Start this gateway agent."""
self._prepare()
self._disconnector = tornado.ioloop.PeriodicCallback(self._disconnect_hanging_devices, 1000, self._loop)
self._disconnector.start()
|
[
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"_prepare",
"(",
")",
"self",
".",
"_disconnector",
"=",
"tornado",
".",
"ioloop",
".",
"PeriodicCallback",
"(",
"self",
".",
"_disconnect_hanging_devices",
",",
"1000",
",",
"self",
".",
"_loop",
")",
"self",
".",
"_disconnector",
".",
"start",
"(",
")"
] |
Start this gateway agent.
|
[
"Start",
"this",
"gateway",
"agent",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L86-L92
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent.stop
|
def stop(self):
"""Stop this gateway agent."""
if self._disconnector:
self._disconnector.stop()
self.client.disconnect()
|
python
|
def stop(self):
"""Stop this gateway agent."""
if self._disconnector:
self._disconnector.stop()
self.client.disconnect()
|
[
"def",
"stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"_disconnector",
":",
"self",
".",
"_disconnector",
".",
"stop",
"(",
")",
"self",
".",
"client",
".",
"disconnect",
"(",
")"
] |
Stop this gateway agent.
|
[
"Stop",
"this",
"gateway",
"agent",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L94-L100
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._validate_connection
|
def _validate_connection(self, action, uuid, key):
"""Validate that a message received for a device has the right key
If this action is valid the corresponding internal connection id to
be used with the DeviceManager is returned, otherwise None is returned
and an invalid message status is published.
Args:
slug (string): The slug for the device we're trying to connect to
uuid (int): The uuid corresponding to the slug
key (string): The key passed in when this device was first connected
to
Returns:
int: if the action is allowed, otherwise None
"""
if uuid not in self._connections:
self._logger.warn("Received message for device with no connection 0x%X", uuid)
return None
data = self._connections[uuid]
if key != data['key']:
self._logger.warn("Received message for device with incorrect key, uuid=0x%X", uuid)
return None
return data['connection_id']
|
python
|
def _validate_connection(self, action, uuid, key):
"""Validate that a message received for a device has the right key
If this action is valid the corresponding internal connection id to
be used with the DeviceManager is returned, otherwise None is returned
and an invalid message status is published.
Args:
slug (string): The slug for the device we're trying to connect to
uuid (int): The uuid corresponding to the slug
key (string): The key passed in when this device was first connected
to
Returns:
int: if the action is allowed, otherwise None
"""
if uuid not in self._connections:
self._logger.warn("Received message for device with no connection 0x%X", uuid)
return None
data = self._connections[uuid]
if key != data['key']:
self._logger.warn("Received message for device with incorrect key, uuid=0x%X", uuid)
return None
return data['connection_id']
|
[
"def",
"_validate_connection",
"(",
"self",
",",
"action",
",",
"uuid",
",",
"key",
")",
":",
"if",
"uuid",
"not",
"in",
"self",
".",
"_connections",
":",
"self",
".",
"_logger",
".",
"warn",
"(",
"\"Received message for device with no connection 0x%X\"",
",",
"uuid",
")",
"return",
"None",
"data",
"=",
"self",
".",
"_connections",
"[",
"uuid",
"]",
"if",
"key",
"!=",
"data",
"[",
"'key'",
"]",
":",
"self",
".",
"_logger",
".",
"warn",
"(",
"\"Received message for device with incorrect key, uuid=0x%X\"",
",",
"uuid",
")",
"return",
"None",
"return",
"data",
"[",
"'connection_id'",
"]"
] |
Validate that a message received for a device has the right key
If this action is valid the corresponding internal connection id to
be used with the DeviceManager is returned, otherwise None is returned
and an invalid message status is published.
Args:
slug (string): The slug for the device we're trying to connect to
uuid (int): The uuid corresponding to the slug
key (string): The key passed in when this device was first connected
to
Returns:
int: if the action is allowed, otherwise None
|
[
"Validate",
"that",
"a",
"message",
"received",
"for",
"a",
"device",
"has",
"the",
"right",
"key"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L118-L144
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._publish_status
|
def _publish_status(self, slug, data):
"""Publish a status message for a device
Args:
slug (string): The device slug that we are publishing on behalf of
data (dict): The status message data to be sent back to the caller
"""
status_topic = self.topics.prefix + 'devices/{}/data/status'.format(slug)
self._logger.debug("Publishing status message: (topic=%s) (message=%s)", status_topic, str(data))
self.client.publish(status_topic, data)
|
python
|
def _publish_status(self, slug, data):
"""Publish a status message for a device
Args:
slug (string): The device slug that we are publishing on behalf of
data (dict): The status message data to be sent back to the caller
"""
status_topic = self.topics.prefix + 'devices/{}/data/status'.format(slug)
self._logger.debug("Publishing status message: (topic=%s) (message=%s)", status_topic, str(data))
self.client.publish(status_topic, data)
|
[
"def",
"_publish_status",
"(",
"self",
",",
"slug",
",",
"data",
")",
":",
"status_topic",
"=",
"self",
".",
"topics",
".",
"prefix",
"+",
"'devices/{}/data/status'",
".",
"format",
"(",
"slug",
")",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Publishing status message: (topic=%s) (message=%s)\"",
",",
"status_topic",
",",
"str",
"(",
"data",
")",
")",
"self",
".",
"client",
".",
"publish",
"(",
"status_topic",
",",
"data",
")"
] |
Publish a status message for a device
Args:
slug (string): The device slug that we are publishing on behalf of
data (dict): The status message data to be sent back to the caller
|
[
"Publish",
"a",
"status",
"message",
"for",
"a",
"device"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L146-L157
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._publish_response
|
def _publish_response(self, slug, message):
"""Publish a response message for a device
Args:
slug (string): The device slug that we are publishing on behalf of
message (dict): A set of key value pairs that are used to create the message
that is sent.
"""
resp_topic = self.topics.gateway_topic(slug, 'data/response')
self._logger.debug("Publishing response message: (topic=%s) (message=%s)", resp_topic, message)
self.client.publish(resp_topic, message)
|
python
|
def _publish_response(self, slug, message):
"""Publish a response message for a device
Args:
slug (string): The device slug that we are publishing on behalf of
message (dict): A set of key value pairs that are used to create the message
that is sent.
"""
resp_topic = self.topics.gateway_topic(slug, 'data/response')
self._logger.debug("Publishing response message: (topic=%s) (message=%s)", resp_topic, message)
self.client.publish(resp_topic, message)
|
[
"def",
"_publish_response",
"(",
"self",
",",
"slug",
",",
"message",
")",
":",
"resp_topic",
"=",
"self",
".",
"topics",
".",
"gateway_topic",
"(",
"slug",
",",
"'data/response'",
")",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Publishing response message: (topic=%s) (message=%s)\"",
",",
"resp_topic",
",",
"message",
")",
"self",
".",
"client",
".",
"publish",
"(",
"resp_topic",
",",
"message",
")"
] |
Publish a response message for a device
Args:
slug (string): The device slug that we are publishing on behalf of
message (dict): A set of key value pairs that are used to create the message
that is sent.
|
[
"Publish",
"a",
"response",
"message",
"for",
"a",
"device"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L159-L170
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._on_action
|
def _on_action(self, sequence, topic, message):
"""Process a command action that we received on behalf of a device.
Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message (dict): The message itself
"""
try:
slug = None
parts = topic.split('/')
slug = parts[-3]
uuid = self._extract_device_uuid(slug)
except Exception as exc:
self._logger.warn("Error parsing slug in action handler (slug=%s, topic=%s)", slug, topic)
return
if messages.DisconnectCommand.matches(message):
self._logger.debug("Received disconnect command for device 0x%X", uuid)
key = message['key']
client = message['client']
self._loop.add_callback(self._disconnect_from_device, uuid, key, client)
elif messages.OpenInterfaceCommand.matches(message) or messages.CloseInterfaceCommand.matches(message):
self._logger.debug("Received %s command for device 0x%X", message['operation'], uuid)
key = message['key']
client = message['client']
oper = message['operation']
if oper == 'open_interface':
self._loop.add_callback(self._open_interface, client, uuid, message['interface'], key)
else:
self._loop.add_callback(self._close_interface, client, uuid, message['interface'], key)
elif messages.RPCCommand.matches(message):
rpc_msg = messages.RPCCommand.verify(message)
client = rpc_msg['client']
address = rpc_msg['address']
rpc = rpc_msg['rpc_id']
payload = rpc_msg['payload']
key = rpc_msg['key']
timeout = rpc_msg['timeout']
self._loop.add_callback(self._send_rpc, client, uuid, address, rpc, payload, timeout, key)
elif messages.ScriptCommand.matches(message):
script_msg = messages.ScriptCommand.verify(message)
key = script_msg['key']
client = script_msg['client']
script = script_msg['script']
self._loop.add_callback(self._send_script, client, uuid, script, key, (script_msg['fragment_index'], script_msg['fragment_count']))
else:
self._logger.error("Unsupported message received (topic=%s) (message=%s)", topic, str(message))
|
python
|
def _on_action(self, sequence, topic, message):
"""Process a command action that we received on behalf of a device.
Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message (dict): The message itself
"""
try:
slug = None
parts = topic.split('/')
slug = parts[-3]
uuid = self._extract_device_uuid(slug)
except Exception as exc:
self._logger.warn("Error parsing slug in action handler (slug=%s, topic=%s)", slug, topic)
return
if messages.DisconnectCommand.matches(message):
self._logger.debug("Received disconnect command for device 0x%X", uuid)
key = message['key']
client = message['client']
self._loop.add_callback(self._disconnect_from_device, uuid, key, client)
elif messages.OpenInterfaceCommand.matches(message) or messages.CloseInterfaceCommand.matches(message):
self._logger.debug("Received %s command for device 0x%X", message['operation'], uuid)
key = message['key']
client = message['client']
oper = message['operation']
if oper == 'open_interface':
self._loop.add_callback(self._open_interface, client, uuid, message['interface'], key)
else:
self._loop.add_callback(self._close_interface, client, uuid, message['interface'], key)
elif messages.RPCCommand.matches(message):
rpc_msg = messages.RPCCommand.verify(message)
client = rpc_msg['client']
address = rpc_msg['address']
rpc = rpc_msg['rpc_id']
payload = rpc_msg['payload']
key = rpc_msg['key']
timeout = rpc_msg['timeout']
self._loop.add_callback(self._send_rpc, client, uuid, address, rpc, payload, timeout, key)
elif messages.ScriptCommand.matches(message):
script_msg = messages.ScriptCommand.verify(message)
key = script_msg['key']
client = script_msg['client']
script = script_msg['script']
self._loop.add_callback(self._send_script, client, uuid, script, key, (script_msg['fragment_index'], script_msg['fragment_count']))
else:
self._logger.error("Unsupported message received (topic=%s) (message=%s)", topic, str(message))
|
[
"def",
"_on_action",
"(",
"self",
",",
"sequence",
",",
"topic",
",",
"message",
")",
":",
"try",
":",
"slug",
"=",
"None",
"parts",
"=",
"topic",
".",
"split",
"(",
"'/'",
")",
"slug",
"=",
"parts",
"[",
"-",
"3",
"]",
"uuid",
"=",
"self",
".",
"_extract_device_uuid",
"(",
"slug",
")",
"except",
"Exception",
"as",
"exc",
":",
"self",
".",
"_logger",
".",
"warn",
"(",
"\"Error parsing slug in action handler (slug=%s, topic=%s)\"",
",",
"slug",
",",
"topic",
")",
"return",
"if",
"messages",
".",
"DisconnectCommand",
".",
"matches",
"(",
"message",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Received disconnect command for device 0x%X\"",
",",
"uuid",
")",
"key",
"=",
"message",
"[",
"'key'",
"]",
"client",
"=",
"message",
"[",
"'client'",
"]",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_disconnect_from_device",
",",
"uuid",
",",
"key",
",",
"client",
")",
"elif",
"messages",
".",
"OpenInterfaceCommand",
".",
"matches",
"(",
"message",
")",
"or",
"messages",
".",
"CloseInterfaceCommand",
".",
"matches",
"(",
"message",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Received %s command for device 0x%X\"",
",",
"message",
"[",
"'operation'",
"]",
",",
"uuid",
")",
"key",
"=",
"message",
"[",
"'key'",
"]",
"client",
"=",
"message",
"[",
"'client'",
"]",
"oper",
"=",
"message",
"[",
"'operation'",
"]",
"if",
"oper",
"==",
"'open_interface'",
":",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_open_interface",
",",
"client",
",",
"uuid",
",",
"message",
"[",
"'interface'",
"]",
",",
"key",
")",
"else",
":",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_close_interface",
",",
"client",
",",
"uuid",
",",
"message",
"[",
"'interface'",
"]",
",",
"key",
")",
"elif",
"messages",
".",
"RPCCommand",
".",
"matches",
"(",
"message",
")",
":",
"rpc_msg",
"=",
"messages",
".",
"RPCCommand",
".",
"verify",
"(",
"message",
")",
"client",
"=",
"rpc_msg",
"[",
"'client'",
"]",
"address",
"=",
"rpc_msg",
"[",
"'address'",
"]",
"rpc",
"=",
"rpc_msg",
"[",
"'rpc_id'",
"]",
"payload",
"=",
"rpc_msg",
"[",
"'payload'",
"]",
"key",
"=",
"rpc_msg",
"[",
"'key'",
"]",
"timeout",
"=",
"rpc_msg",
"[",
"'timeout'",
"]",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_send_rpc",
",",
"client",
",",
"uuid",
",",
"address",
",",
"rpc",
",",
"payload",
",",
"timeout",
",",
"key",
")",
"elif",
"messages",
".",
"ScriptCommand",
".",
"matches",
"(",
"message",
")",
":",
"script_msg",
"=",
"messages",
".",
"ScriptCommand",
".",
"verify",
"(",
"message",
")",
"key",
"=",
"script_msg",
"[",
"'key'",
"]",
"client",
"=",
"script_msg",
"[",
"'client'",
"]",
"script",
"=",
"script_msg",
"[",
"'script'",
"]",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_send_script",
",",
"client",
",",
"uuid",
",",
"script",
",",
"key",
",",
"(",
"script_msg",
"[",
"'fragment_index'",
"]",
",",
"script_msg",
"[",
"'fragment_count'",
"]",
")",
")",
"else",
":",
"self",
".",
"_logger",
".",
"error",
"(",
"\"Unsupported message received (topic=%s) (message=%s)\"",
",",
"topic",
",",
"str",
"(",
"message",
")",
")"
] |
Process a command action that we received on behalf of a device.
Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message (dict): The message itself
|
[
"Process",
"a",
"command",
"action",
"that",
"we",
"received",
"on",
"behalf",
"of",
"a",
"device",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L172-L225
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._on_connect
|
def _on_connect(self, sequence, topic, message):
"""Process a request to connect to an IOTile device
A connection message triggers an attempt to connect to a device,
any error checking is done by the DeviceManager that is actually
managing the devices.
A disconnection message is checked to make sure its key matches
what we except for this device and is either discarded or
forwarded on to the DeviceManager.
Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself
"""
try:
slug = None
parts = topic.split('/')
slug = parts[-3]
uuid = self._extract_device_uuid(slug)
except Exception:
self._logger.exception("Error parsing slug from connection request (slug=%s, topic=%s)", slug, topic)
return
if messages.ConnectCommand.matches(message):
key = message['key']
client = message['client']
self._loop.add_callback(self._connect_to_device, uuid, key, client)
else:
self._logger.warn("Unknown message received on connect topic=%s, message=%s", topic, message)
|
python
|
def _on_connect(self, sequence, topic, message):
"""Process a request to connect to an IOTile device
A connection message triggers an attempt to connect to a device,
any error checking is done by the DeviceManager that is actually
managing the devices.
A disconnection message is checked to make sure its key matches
what we except for this device and is either discarded or
forwarded on to the DeviceManager.
Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself
"""
try:
slug = None
parts = topic.split('/')
slug = parts[-3]
uuid = self._extract_device_uuid(slug)
except Exception:
self._logger.exception("Error parsing slug from connection request (slug=%s, topic=%s)", slug, topic)
return
if messages.ConnectCommand.matches(message):
key = message['key']
client = message['client']
self._loop.add_callback(self._connect_to_device, uuid, key, client)
else:
self._logger.warn("Unknown message received on connect topic=%s, message=%s", topic, message)
|
[
"def",
"_on_connect",
"(",
"self",
",",
"sequence",
",",
"topic",
",",
"message",
")",
":",
"try",
":",
"slug",
"=",
"None",
"parts",
"=",
"topic",
".",
"split",
"(",
"'/'",
")",
"slug",
"=",
"parts",
"[",
"-",
"3",
"]",
"uuid",
"=",
"self",
".",
"_extract_device_uuid",
"(",
"slug",
")",
"except",
"Exception",
":",
"self",
".",
"_logger",
".",
"exception",
"(",
"\"Error parsing slug from connection request (slug=%s, topic=%s)\"",
",",
"slug",
",",
"topic",
")",
"return",
"if",
"messages",
".",
"ConnectCommand",
".",
"matches",
"(",
"message",
")",
":",
"key",
"=",
"message",
"[",
"'key'",
"]",
"client",
"=",
"message",
"[",
"'client'",
"]",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_connect_to_device",
",",
"uuid",
",",
"key",
",",
"client",
")",
"else",
":",
"self",
".",
"_logger",
".",
"warn",
"(",
"\"Unknown message received on connect topic=%s, message=%s\"",
",",
"topic",
",",
"message",
")"
] |
Process a request to connect to an IOTile device
A connection message triggers an attempt to connect to a device,
any error checking is done by the DeviceManager that is actually
managing the devices.
A disconnection message is checked to make sure its key matches
what we except for this device and is either discarded or
forwarded on to the DeviceManager.
Args:
sequence (int): The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself
|
[
"Process",
"a",
"request",
"to",
"connect",
"to",
"an",
"IOTile",
"device"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L227-L259
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._send_rpc
|
def _send_rpc(self, client, uuid, address, rpc, payload, timeout, key):
"""Send an RPC to a connected device
Args:
client (string): The client that sent the rpc request
uuid (int): The id of the device we're opening the interface on
address (int): The address of the tile that we want to send the RPC to
rpc (int): The id of the rpc that we want to send.
payload (bytearray): The payload of arguments that we want to send
timeout (float): The number of seconds to wait for the response
key (string): The key to authenticate the caller
"""
conn_id = self._validate_connection('send_rpc', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
conn_data['last_touch'] = monotonic()
slug = self._build_device_slug(uuid)
try:
resp = yield self._manager.send_rpc(conn_id, address, rpc >> 8, rpc & 0xFF, bytes(payload), timeout)
except Exception as exc:
self._logger.error("Error in manager send rpc: %s" % str(exc))
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
payload = {'client': client, 'type': 'response', 'operation': 'rpc'}
payload['success'] = resp['success']
if resp['success'] is False:
payload['failure_reason'] = resp['reason']
else:
payload['status'] = resp['status']
payload['payload'] = binascii.hexlify(resp['payload'])
self._publish_response(slug, payload)
|
python
|
def _send_rpc(self, client, uuid, address, rpc, payload, timeout, key):
"""Send an RPC to a connected device
Args:
client (string): The client that sent the rpc request
uuid (int): The id of the device we're opening the interface on
address (int): The address of the tile that we want to send the RPC to
rpc (int): The id of the rpc that we want to send.
payload (bytearray): The payload of arguments that we want to send
timeout (float): The number of seconds to wait for the response
key (string): The key to authenticate the caller
"""
conn_id = self._validate_connection('send_rpc', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
conn_data['last_touch'] = monotonic()
slug = self._build_device_slug(uuid)
try:
resp = yield self._manager.send_rpc(conn_id, address, rpc >> 8, rpc & 0xFF, bytes(payload), timeout)
except Exception as exc:
self._logger.error("Error in manager send rpc: %s" % str(exc))
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
payload = {'client': client, 'type': 'response', 'operation': 'rpc'}
payload['success'] = resp['success']
if resp['success'] is False:
payload['failure_reason'] = resp['reason']
else:
payload['status'] = resp['status']
payload['payload'] = binascii.hexlify(resp['payload'])
self._publish_response(slug, payload)
|
[
"def",
"_send_rpc",
"(",
"self",
",",
"client",
",",
"uuid",
",",
"address",
",",
"rpc",
",",
"payload",
",",
"timeout",
",",
"key",
")",
":",
"conn_id",
"=",
"self",
".",
"_validate_connection",
"(",
"'send_rpc'",
",",
"uuid",
",",
"key",
")",
"if",
"conn_id",
"is",
"None",
":",
"return",
"conn_data",
"=",
"self",
".",
"_connections",
"[",
"uuid",
"]",
"conn_data",
"[",
"'last_touch'",
"]",
"=",
"monotonic",
"(",
")",
"slug",
"=",
"self",
".",
"_build_device_slug",
"(",
"uuid",
")",
"try",
":",
"resp",
"=",
"yield",
"self",
".",
"_manager",
".",
"send_rpc",
"(",
"conn_id",
",",
"address",
",",
"rpc",
">>",
"8",
",",
"rpc",
"&",
"0xFF",
",",
"bytes",
"(",
"payload",
")",
",",
"timeout",
")",
"except",
"Exception",
"as",
"exc",
":",
"self",
".",
"_logger",
".",
"error",
"(",
"\"Error in manager send rpc: %s\"",
"%",
"str",
"(",
"exc",
")",
")",
"resp",
"=",
"{",
"'success'",
":",
"False",
",",
"'reason'",
":",
"\"Internal error: %s\"",
"%",
"str",
"(",
"exc",
")",
"}",
"payload",
"=",
"{",
"'client'",
":",
"client",
",",
"'type'",
":",
"'response'",
",",
"'operation'",
":",
"'rpc'",
"}",
"payload",
"[",
"'success'",
"]",
"=",
"resp",
"[",
"'success'",
"]",
"if",
"resp",
"[",
"'success'",
"]",
"is",
"False",
":",
"payload",
"[",
"'failure_reason'",
"]",
"=",
"resp",
"[",
"'reason'",
"]",
"else",
":",
"payload",
"[",
"'status'",
"]",
"=",
"resp",
"[",
"'status'",
"]",
"payload",
"[",
"'payload'",
"]",
"=",
"binascii",
".",
"hexlify",
"(",
"resp",
"[",
"'payload'",
"]",
")",
"self",
".",
"_publish_response",
"(",
"slug",
",",
"payload",
")"
] |
Send an RPC to a connected device
Args:
client (string): The client that sent the rpc request
uuid (int): The id of the device we're opening the interface on
address (int): The address of the tile that we want to send the RPC to
rpc (int): The id of the rpc that we want to send.
payload (bytearray): The payload of arguments that we want to send
timeout (float): The number of seconds to wait for the response
key (string): The key to authenticate the caller
|
[
"Send",
"an",
"RPC",
"to",
"a",
"connected",
"device"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L262-L299
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._send_script
|
def _send_script(self, client, uuid, chunk, key, chunk_status):
"""Send a script to the connected device.
Args:
client (string): The client that sent the rpc request
uuid (int): The id of the device we're opening the interface on
chunk (bytes): The binary script to send to the device
key (string): The key to authenticate the caller
last_chunk (tuple): the chunk index and count of chunks of this script
so that we know to either accumulate it or send it on to the device
immediately.
"""
conn_id = self._validate_connection('send_script', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
conn_data['last_touch'] = monotonic()
slug = self._build_device_slug(uuid)
# Check and see if we have the entire script or if we need to accumulate it
index, count = chunk_status
if index == 0:
conn_data['script'] = bytes()
conn_data['script'] += chunk
# If there is more than one chunk and we aren't on the last one, wait until we receive them
# all before sending them on to the device as a unit
if index != count - 1:
return
# Initialize our progress throttling system in case we need to throttle progress reports
conn_data['last_progress'] = None
try:
resp = yield self._manager.send_script(conn_id, conn_data['script'], lambda x, y: self._notify_progress_async(uuid, client, x, y))
yield None # Make sure we give time for any progress notifications that may have been queued to flush out
conn_data['script'] = bytes()
except Exception as exc:
self._logger.exception("Error in manager send_script")
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
payload = {'client': client, 'type': 'response', 'operation': 'send_script', 'success': resp['success']}
if resp['success'] is False:
payload['failure_reason'] = resp['reason']
self._publish_response(slug, payload)
|
python
|
def _send_script(self, client, uuid, chunk, key, chunk_status):
"""Send a script to the connected device.
Args:
client (string): The client that sent the rpc request
uuid (int): The id of the device we're opening the interface on
chunk (bytes): The binary script to send to the device
key (string): The key to authenticate the caller
last_chunk (tuple): the chunk index and count of chunks of this script
so that we know to either accumulate it or send it on to the device
immediately.
"""
conn_id = self._validate_connection('send_script', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
conn_data['last_touch'] = monotonic()
slug = self._build_device_slug(uuid)
# Check and see if we have the entire script or if we need to accumulate it
index, count = chunk_status
if index == 0:
conn_data['script'] = bytes()
conn_data['script'] += chunk
# If there is more than one chunk and we aren't on the last one, wait until we receive them
# all before sending them on to the device as a unit
if index != count - 1:
return
# Initialize our progress throttling system in case we need to throttle progress reports
conn_data['last_progress'] = None
try:
resp = yield self._manager.send_script(conn_id, conn_data['script'], lambda x, y: self._notify_progress_async(uuid, client, x, y))
yield None # Make sure we give time for any progress notifications that may have been queued to flush out
conn_data['script'] = bytes()
except Exception as exc:
self._logger.exception("Error in manager send_script")
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
payload = {'client': client, 'type': 'response', 'operation': 'send_script', 'success': resp['success']}
if resp['success'] is False:
payload['failure_reason'] = resp['reason']
self._publish_response(slug, payload)
|
[
"def",
"_send_script",
"(",
"self",
",",
"client",
",",
"uuid",
",",
"chunk",
",",
"key",
",",
"chunk_status",
")",
":",
"conn_id",
"=",
"self",
".",
"_validate_connection",
"(",
"'send_script'",
",",
"uuid",
",",
"key",
")",
"if",
"conn_id",
"is",
"None",
":",
"return",
"conn_data",
"=",
"self",
".",
"_connections",
"[",
"uuid",
"]",
"conn_data",
"[",
"'last_touch'",
"]",
"=",
"monotonic",
"(",
")",
"slug",
"=",
"self",
".",
"_build_device_slug",
"(",
"uuid",
")",
"# Check and see if we have the entire script or if we need to accumulate it",
"index",
",",
"count",
"=",
"chunk_status",
"if",
"index",
"==",
"0",
":",
"conn_data",
"[",
"'script'",
"]",
"=",
"bytes",
"(",
")",
"conn_data",
"[",
"'script'",
"]",
"+=",
"chunk",
"# If there is more than one chunk and we aren't on the last one, wait until we receive them",
"# all before sending them on to the device as a unit",
"if",
"index",
"!=",
"count",
"-",
"1",
":",
"return",
"# Initialize our progress throttling system in case we need to throttle progress reports",
"conn_data",
"[",
"'last_progress'",
"]",
"=",
"None",
"try",
":",
"resp",
"=",
"yield",
"self",
".",
"_manager",
".",
"send_script",
"(",
"conn_id",
",",
"conn_data",
"[",
"'script'",
"]",
",",
"lambda",
"x",
",",
"y",
":",
"self",
".",
"_notify_progress_async",
"(",
"uuid",
",",
"client",
",",
"x",
",",
"y",
")",
")",
"yield",
"None",
"# Make sure we give time for any progress notifications that may have been queued to flush out",
"conn_data",
"[",
"'script'",
"]",
"=",
"bytes",
"(",
")",
"except",
"Exception",
"as",
"exc",
":",
"self",
".",
"_logger",
".",
"exception",
"(",
"\"Error in manager send_script\"",
")",
"resp",
"=",
"{",
"'success'",
":",
"False",
",",
"'reason'",
":",
"\"Internal error: %s\"",
"%",
"str",
"(",
"exc",
")",
"}",
"payload",
"=",
"{",
"'client'",
":",
"client",
",",
"'type'",
":",
"'response'",
",",
"'operation'",
":",
"'send_script'",
",",
"'success'",
":",
"resp",
"[",
"'success'",
"]",
"}",
"if",
"resp",
"[",
"'success'",
"]",
"is",
"False",
":",
"payload",
"[",
"'failure_reason'",
"]",
"=",
"resp",
"[",
"'reason'",
"]",
"self",
".",
"_publish_response",
"(",
"slug",
",",
"payload",
")"
] |
Send a script to the connected device.
Args:
client (string): The client that sent the rpc request
uuid (int): The id of the device we're opening the interface on
chunk (bytes): The binary script to send to the device
key (string): The key to authenticate the caller
last_chunk (tuple): the chunk index and count of chunks of this script
so that we know to either accumulate it or send it on to the device
immediately.
|
[
"Send",
"a",
"script",
"to",
"the",
"connected",
"device",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L302-L351
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._open_interface
|
def _open_interface(self, client, uuid, iface, key):
"""Open an interface on a connected device.
Args:
client (string): The client id who is requesting this operation
uuid (int): The id of the device we're opening the interface on
iface (string): The name of the interface that we're opening
key (string): The key to authenticate the caller
"""
conn_id = self._validate_connection('open_interface', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
conn_data['last_touch'] = monotonic()
slug = self._build_device_slug(uuid)
try:
resp = yield self._manager.open_interface(conn_id, iface)
except Exception as exc:
self._logger.exception("Error in manager open interface")
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
message = {'type': 'response', 'operation': 'open_interface', 'client': client}
message['success'] = resp['success']
if not message['success']:
message['failure_reason'] = resp['reason']
self._publish_response(slug, message)
|
python
|
def _open_interface(self, client, uuid, iface, key):
"""Open an interface on a connected device.
Args:
client (string): The client id who is requesting this operation
uuid (int): The id of the device we're opening the interface on
iface (string): The name of the interface that we're opening
key (string): The key to authenticate the caller
"""
conn_id = self._validate_connection('open_interface', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
conn_data['last_touch'] = monotonic()
slug = self._build_device_slug(uuid)
try:
resp = yield self._manager.open_interface(conn_id, iface)
except Exception as exc:
self._logger.exception("Error in manager open interface")
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
message = {'type': 'response', 'operation': 'open_interface', 'client': client}
message['success'] = resp['success']
if not message['success']:
message['failure_reason'] = resp['reason']
self._publish_response(slug, message)
|
[
"def",
"_open_interface",
"(",
"self",
",",
"client",
",",
"uuid",
",",
"iface",
",",
"key",
")",
":",
"conn_id",
"=",
"self",
".",
"_validate_connection",
"(",
"'open_interface'",
",",
"uuid",
",",
"key",
")",
"if",
"conn_id",
"is",
"None",
":",
"return",
"conn_data",
"=",
"self",
".",
"_connections",
"[",
"uuid",
"]",
"conn_data",
"[",
"'last_touch'",
"]",
"=",
"monotonic",
"(",
")",
"slug",
"=",
"self",
".",
"_build_device_slug",
"(",
"uuid",
")",
"try",
":",
"resp",
"=",
"yield",
"self",
".",
"_manager",
".",
"open_interface",
"(",
"conn_id",
",",
"iface",
")",
"except",
"Exception",
"as",
"exc",
":",
"self",
".",
"_logger",
".",
"exception",
"(",
"\"Error in manager open interface\"",
")",
"resp",
"=",
"{",
"'success'",
":",
"False",
",",
"'reason'",
":",
"\"Internal error: %s\"",
"%",
"str",
"(",
"exc",
")",
"}",
"message",
"=",
"{",
"'type'",
":",
"'response'",
",",
"'operation'",
":",
"'open_interface'",
",",
"'client'",
":",
"client",
"}",
"message",
"[",
"'success'",
"]",
"=",
"resp",
"[",
"'success'",
"]",
"if",
"not",
"message",
"[",
"'success'",
"]",
":",
"message",
"[",
"'failure_reason'",
"]",
"=",
"resp",
"[",
"'reason'",
"]",
"self",
".",
"_publish_response",
"(",
"slug",
",",
"message",
")"
] |
Open an interface on a connected device.
Args:
client (string): The client id who is requesting this operation
uuid (int): The id of the device we're opening the interface on
iface (string): The name of the interface that we're opening
key (string): The key to authenticate the caller
|
[
"Open",
"an",
"interface",
"on",
"a",
"connected",
"device",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L409-L440
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._disconnect_hanging_devices
|
def _disconnect_hanging_devices(self):
"""Periodic callback that checks for devices that haven't been used and disconnects them."""
now = monotonic()
for uuid, data in self._connections.items():
if (now - data['last_touch']) > self.client_timeout:
self._logger.info("Disconnect inactive client %s from device 0x%X", data['client'], uuid)
self._loop.add_callback(self._disconnect_from_device, uuid, data['key'], data['client'], unsolicited=True)
|
python
|
def _disconnect_hanging_devices(self):
"""Periodic callback that checks for devices that haven't been used and disconnects them."""
now = monotonic()
for uuid, data in self._connections.items():
if (now - data['last_touch']) > self.client_timeout:
self._logger.info("Disconnect inactive client %s from device 0x%X", data['client'], uuid)
self._loop.add_callback(self._disconnect_from_device, uuid, data['key'], data['client'], unsolicited=True)
|
[
"def",
"_disconnect_hanging_devices",
"(",
"self",
")",
":",
"now",
"=",
"monotonic",
"(",
")",
"for",
"uuid",
",",
"data",
"in",
"self",
".",
"_connections",
".",
"items",
"(",
")",
":",
"if",
"(",
"now",
"-",
"data",
"[",
"'last_touch'",
"]",
")",
">",
"self",
".",
"client_timeout",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Disconnect inactive client %s from device 0x%X\"",
",",
"data",
"[",
"'client'",
"]",
",",
"uuid",
")",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_disconnect_from_device",
",",
"uuid",
",",
"data",
"[",
"'key'",
"]",
",",
"data",
"[",
"'client'",
"]",
",",
"unsolicited",
"=",
"True",
")"
] |
Periodic callback that checks for devices that haven't been used and disconnects them.
|
[
"Periodic",
"callback",
"that",
"checks",
"for",
"devices",
"that",
"haven",
"t",
"been",
"used",
"and",
"disconnects",
"them",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L476-L483
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._disconnect_from_device
|
def _disconnect_from_device(self, uuid, key, client, unsolicited=False):
"""Disconnect from a device that we have previously connected to.
Args:
uuid (int): The unique id of the device
key (string): A 64 byte string used to secure this connection
client (string): The client id for who is trying to connect
to the device.
unsolicited (bool): Whether the client asked us to disconnect or we
are forcibly doing it. Forcible disconnections are sent as notifications
instead of responses.
"""
conn_id = self._validate_connection('disconnect', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
slug = self._build_device_slug(uuid)
message = {'client': client, 'type': 'response', 'operation': 'disconnect'}
self.client.reset_sequence(self.topics.gateway_topic(slug, 'control/connect'))
self.client.reset_sequence(self.topics.gateway_topic(slug, 'control/action'))
try:
resp = yield self._manager.disconnect(conn_id)
except Exception as exc:
self._logger.exception("Error in manager disconnect")
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
# Remove any monitors that we registered for this device
self._manager.remove_monitor(conn_data['report_monitor'])
self._manager.remove_monitor(conn_data['trace_monitor'])
if resp['success']:
del self._connections[uuid]
message['success'] = True
else:
message['success'] = False
message['failure_reason'] = resp['reason']
self._logger.info("Client %s disconnected from device 0x%X", client, uuid)
# Send a response for all requested disconnects and if we tried to disconnect the client
# on our own and succeeded, send an unsolicited notification to that effect
if unsolicited and resp['success']:
self._publish_response(slug, {'client': client, 'type': 'notification', 'operation': 'disconnect'})
elif not unsolicited:
self._publish_response(slug, message)
|
python
|
def _disconnect_from_device(self, uuid, key, client, unsolicited=False):
"""Disconnect from a device that we have previously connected to.
Args:
uuid (int): The unique id of the device
key (string): A 64 byte string used to secure this connection
client (string): The client id for who is trying to connect
to the device.
unsolicited (bool): Whether the client asked us to disconnect or we
are forcibly doing it. Forcible disconnections are sent as notifications
instead of responses.
"""
conn_id = self._validate_connection('disconnect', uuid, key)
if conn_id is None:
return
conn_data = self._connections[uuid]
slug = self._build_device_slug(uuid)
message = {'client': client, 'type': 'response', 'operation': 'disconnect'}
self.client.reset_sequence(self.topics.gateway_topic(slug, 'control/connect'))
self.client.reset_sequence(self.topics.gateway_topic(slug, 'control/action'))
try:
resp = yield self._manager.disconnect(conn_id)
except Exception as exc:
self._logger.exception("Error in manager disconnect")
resp = {'success': False, 'reason': "Internal error: %s" % str(exc)}
# Remove any monitors that we registered for this device
self._manager.remove_monitor(conn_data['report_monitor'])
self._manager.remove_monitor(conn_data['trace_monitor'])
if resp['success']:
del self._connections[uuid]
message['success'] = True
else:
message['success'] = False
message['failure_reason'] = resp['reason']
self._logger.info("Client %s disconnected from device 0x%X", client, uuid)
# Send a response for all requested disconnects and if we tried to disconnect the client
# on our own and succeeded, send an unsolicited notification to that effect
if unsolicited and resp['success']:
self._publish_response(slug, {'client': client, 'type': 'notification', 'operation': 'disconnect'})
elif not unsolicited:
self._publish_response(slug, message)
|
[
"def",
"_disconnect_from_device",
"(",
"self",
",",
"uuid",
",",
"key",
",",
"client",
",",
"unsolicited",
"=",
"False",
")",
":",
"conn_id",
"=",
"self",
".",
"_validate_connection",
"(",
"'disconnect'",
",",
"uuid",
",",
"key",
")",
"if",
"conn_id",
"is",
"None",
":",
"return",
"conn_data",
"=",
"self",
".",
"_connections",
"[",
"uuid",
"]",
"slug",
"=",
"self",
".",
"_build_device_slug",
"(",
"uuid",
")",
"message",
"=",
"{",
"'client'",
":",
"client",
",",
"'type'",
":",
"'response'",
",",
"'operation'",
":",
"'disconnect'",
"}",
"self",
".",
"client",
".",
"reset_sequence",
"(",
"self",
".",
"topics",
".",
"gateway_topic",
"(",
"slug",
",",
"'control/connect'",
")",
")",
"self",
".",
"client",
".",
"reset_sequence",
"(",
"self",
".",
"topics",
".",
"gateway_topic",
"(",
"slug",
",",
"'control/action'",
")",
")",
"try",
":",
"resp",
"=",
"yield",
"self",
".",
"_manager",
".",
"disconnect",
"(",
"conn_id",
")",
"except",
"Exception",
"as",
"exc",
":",
"self",
".",
"_logger",
".",
"exception",
"(",
"\"Error in manager disconnect\"",
")",
"resp",
"=",
"{",
"'success'",
":",
"False",
",",
"'reason'",
":",
"\"Internal error: %s\"",
"%",
"str",
"(",
"exc",
")",
"}",
"# Remove any monitors that we registered for this device",
"self",
".",
"_manager",
".",
"remove_monitor",
"(",
"conn_data",
"[",
"'report_monitor'",
"]",
")",
"self",
".",
"_manager",
".",
"remove_monitor",
"(",
"conn_data",
"[",
"'trace_monitor'",
"]",
")",
"if",
"resp",
"[",
"'success'",
"]",
":",
"del",
"self",
".",
"_connections",
"[",
"uuid",
"]",
"message",
"[",
"'success'",
"]",
"=",
"True",
"else",
":",
"message",
"[",
"'success'",
"]",
"=",
"False",
"message",
"[",
"'failure_reason'",
"]",
"=",
"resp",
"[",
"'reason'",
"]",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Client %s disconnected from device 0x%X\"",
",",
"client",
",",
"uuid",
")",
"# Send a response for all requested disconnects and if we tried to disconnect the client",
"# on our own and succeeded, send an unsolicited notification to that effect",
"if",
"unsolicited",
"and",
"resp",
"[",
"'success'",
"]",
":",
"self",
".",
"_publish_response",
"(",
"slug",
",",
"{",
"'client'",
":",
"client",
",",
"'type'",
":",
"'notification'",
",",
"'operation'",
":",
"'disconnect'",
"}",
")",
"elif",
"not",
"unsolicited",
":",
"self",
".",
"_publish_response",
"(",
"slug",
",",
"message",
")"
] |
Disconnect from a device that we have previously connected to.
Args:
uuid (int): The unique id of the device
key (string): A 64 byte string used to secure this connection
client (string): The client id for who is trying to connect
to the device.
unsolicited (bool): Whether the client asked us to disconnect or we
are forcibly doing it. Forcible disconnections are sent as notifications
instead of responses.
|
[
"Disconnect",
"from",
"a",
"device",
"that",
"we",
"have",
"previously",
"connected",
"to",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L486-L536
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._notify_report
|
def _notify_report(self, device_uuid, event_name, report):
"""Notify that a report has been received from a device.
This routine is called synchronously in the event loop by the DeviceManager
"""
if device_uuid not in self._connections:
self._logger.debug("Dropping report for device without an active connection, uuid=0x%X", device_uuid)
return
slug = self._build_device_slug(device_uuid)
streaming_topic = self.topics.prefix + 'devices/{}/data/streaming'.format(slug)
data = {'type': 'notification', 'operation': 'report'}
ser = report.serialize()
data['received_time'] = ser['received_time'].strftime("%Y%m%dT%H:%M:%S.%fZ").encode()
data['report_origin'] = ser['origin']
data['report_format'] = ser['report_format']
data['report'] = binascii.hexlify(ser['encoded_report'])
data['fragment_count'] = 1
data['fragment_index'] = 0
self._logger.debug("Publishing report: (topic=%s)", streaming_topic)
self.client.publish(streaming_topic, data)
|
python
|
def _notify_report(self, device_uuid, event_name, report):
"""Notify that a report has been received from a device.
This routine is called synchronously in the event loop by the DeviceManager
"""
if device_uuid not in self._connections:
self._logger.debug("Dropping report for device without an active connection, uuid=0x%X", device_uuid)
return
slug = self._build_device_slug(device_uuid)
streaming_topic = self.topics.prefix + 'devices/{}/data/streaming'.format(slug)
data = {'type': 'notification', 'operation': 'report'}
ser = report.serialize()
data['received_time'] = ser['received_time'].strftime("%Y%m%dT%H:%M:%S.%fZ").encode()
data['report_origin'] = ser['origin']
data['report_format'] = ser['report_format']
data['report'] = binascii.hexlify(ser['encoded_report'])
data['fragment_count'] = 1
data['fragment_index'] = 0
self._logger.debug("Publishing report: (topic=%s)", streaming_topic)
self.client.publish(streaming_topic, data)
|
[
"def",
"_notify_report",
"(",
"self",
",",
"device_uuid",
",",
"event_name",
",",
"report",
")",
":",
"if",
"device_uuid",
"not",
"in",
"self",
".",
"_connections",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Dropping report for device without an active connection, uuid=0x%X\"",
",",
"device_uuid",
")",
"return",
"slug",
"=",
"self",
".",
"_build_device_slug",
"(",
"device_uuid",
")",
"streaming_topic",
"=",
"self",
".",
"topics",
".",
"prefix",
"+",
"'devices/{}/data/streaming'",
".",
"format",
"(",
"slug",
")",
"data",
"=",
"{",
"'type'",
":",
"'notification'",
",",
"'operation'",
":",
"'report'",
"}",
"ser",
"=",
"report",
".",
"serialize",
"(",
")",
"data",
"[",
"'received_time'",
"]",
"=",
"ser",
"[",
"'received_time'",
"]",
".",
"strftime",
"(",
"\"%Y%m%dT%H:%M:%S.%fZ\"",
")",
".",
"encode",
"(",
")",
"data",
"[",
"'report_origin'",
"]",
"=",
"ser",
"[",
"'origin'",
"]",
"data",
"[",
"'report_format'",
"]",
"=",
"ser",
"[",
"'report_format'",
"]",
"data",
"[",
"'report'",
"]",
"=",
"binascii",
".",
"hexlify",
"(",
"ser",
"[",
"'encoded_report'",
"]",
")",
"data",
"[",
"'fragment_count'",
"]",
"=",
"1",
"data",
"[",
"'fragment_index'",
"]",
"=",
"0",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Publishing report: (topic=%s)\"",
",",
"streaming_topic",
")",
"self",
".",
"client",
".",
"publish",
"(",
"streaming_topic",
",",
"data",
")"
] |
Notify that a report has been received from a device.
This routine is called synchronously in the event loop by the DeviceManager
|
[
"Notify",
"that",
"a",
"report",
"has",
"been",
"received",
"from",
"a",
"device",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L580-L603
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._notify_trace
|
def _notify_trace(self, device_uuid, event_name, trace):
"""Notify that we have received tracing data from a device.
This routine is called synchronously in the event loop by the DeviceManager
"""
if device_uuid not in self._connections:
self._logger.debug("Dropping trace data for device without an active connection, uuid=0x%X", device_uuid)
return
conn_data = self._connections[device_uuid]
last_trace = conn_data['last_trace']
now = monotonic()
conn_data['trace_accum'] += bytes(trace)
# If we're throttling tracing data, we need to see if we should accumulate this trace or
# send it now. We acculumate if we've last sent tracing data less than self.throttle_trace seconds ago
if last_trace is not None and (now - last_trace) < self.throttle_trace:
if not conn_data['trace_scheduled']:
self._loop.call_later(self.throttle_trace - (now - last_trace), self._send_accum_trace, device_uuid)
conn_data['trace_scheduled'] = True
self._logger.debug("Deferring trace data due to throttling uuid=0x%X", device_uuid)
else:
self._send_accum_trace(device_uuid)
|
python
|
def _notify_trace(self, device_uuid, event_name, trace):
"""Notify that we have received tracing data from a device.
This routine is called synchronously in the event loop by the DeviceManager
"""
if device_uuid not in self._connections:
self._logger.debug("Dropping trace data for device without an active connection, uuid=0x%X", device_uuid)
return
conn_data = self._connections[device_uuid]
last_trace = conn_data['last_trace']
now = monotonic()
conn_data['trace_accum'] += bytes(trace)
# If we're throttling tracing data, we need to see if we should accumulate this trace or
# send it now. We acculumate if we've last sent tracing data less than self.throttle_trace seconds ago
if last_trace is not None and (now - last_trace) < self.throttle_trace:
if not conn_data['trace_scheduled']:
self._loop.call_later(self.throttle_trace - (now - last_trace), self._send_accum_trace, device_uuid)
conn_data['trace_scheduled'] = True
self._logger.debug("Deferring trace data due to throttling uuid=0x%X", device_uuid)
else:
self._send_accum_trace(device_uuid)
|
[
"def",
"_notify_trace",
"(",
"self",
",",
"device_uuid",
",",
"event_name",
",",
"trace",
")",
":",
"if",
"device_uuid",
"not",
"in",
"self",
".",
"_connections",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Dropping trace data for device without an active connection, uuid=0x%X\"",
",",
"device_uuid",
")",
"return",
"conn_data",
"=",
"self",
".",
"_connections",
"[",
"device_uuid",
"]",
"last_trace",
"=",
"conn_data",
"[",
"'last_trace'",
"]",
"now",
"=",
"monotonic",
"(",
")",
"conn_data",
"[",
"'trace_accum'",
"]",
"+=",
"bytes",
"(",
"trace",
")",
"# If we're throttling tracing data, we need to see if we should accumulate this trace or",
"# send it now. We acculumate if we've last sent tracing data less than self.throttle_trace seconds ago",
"if",
"last_trace",
"is",
"not",
"None",
"and",
"(",
"now",
"-",
"last_trace",
")",
"<",
"self",
".",
"throttle_trace",
":",
"if",
"not",
"conn_data",
"[",
"'trace_scheduled'",
"]",
":",
"self",
".",
"_loop",
".",
"call_later",
"(",
"self",
".",
"throttle_trace",
"-",
"(",
"now",
"-",
"last_trace",
")",
",",
"self",
".",
"_send_accum_trace",
",",
"device_uuid",
")",
"conn_data",
"[",
"'trace_scheduled'",
"]",
"=",
"True",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Deferring trace data due to throttling uuid=0x%X\"",
",",
"device_uuid",
")",
"else",
":",
"self",
".",
"_send_accum_trace",
"(",
"device_uuid",
")"
] |
Notify that we have received tracing data from a device.
This routine is called synchronously in the event loop by the DeviceManager
|
[
"Notify",
"that",
"we",
"have",
"received",
"tracing",
"data",
"from",
"a",
"device",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L605-L629
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._send_accum_trace
|
def _send_accum_trace(self, device_uuid):
"""Send whatever accumulated tracing data we have for the device."""
if device_uuid not in self._connections:
self._logger.debug("Dropping trace data for device without an active connection, uuid=0x%X", device_uuid)
return
conn_data = self._connections[device_uuid]
trace = conn_data['trace_accum']
if len(trace) > 0:
slug = self._build_device_slug(device_uuid)
tracing_topic = self.topics.prefix + 'devices/{}/data/tracing'.format(slug)
data = {'type': 'notification', 'operation': 'trace'}
data['trace'] = binascii.hexlify(trace)
data['trace_origin'] = device_uuid
self._logger.debug('Publishing trace: (topic=%s)', tracing_topic)
self.client.publish(tracing_topic, data)
conn_data['trace_scheduled'] = False
conn_data['last_trace'] = monotonic()
conn_data['trace_accum'] = bytes()
|
python
|
def _send_accum_trace(self, device_uuid):
"""Send whatever accumulated tracing data we have for the device."""
if device_uuid not in self._connections:
self._logger.debug("Dropping trace data for device without an active connection, uuid=0x%X", device_uuid)
return
conn_data = self._connections[device_uuid]
trace = conn_data['trace_accum']
if len(trace) > 0:
slug = self._build_device_slug(device_uuid)
tracing_topic = self.topics.prefix + 'devices/{}/data/tracing'.format(slug)
data = {'type': 'notification', 'operation': 'trace'}
data['trace'] = binascii.hexlify(trace)
data['trace_origin'] = device_uuid
self._logger.debug('Publishing trace: (topic=%s)', tracing_topic)
self.client.publish(tracing_topic, data)
conn_data['trace_scheduled'] = False
conn_data['last_trace'] = monotonic()
conn_data['trace_accum'] = bytes()
|
[
"def",
"_send_accum_trace",
"(",
"self",
",",
"device_uuid",
")",
":",
"if",
"device_uuid",
"not",
"in",
"self",
".",
"_connections",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Dropping trace data for device without an active connection, uuid=0x%X\"",
",",
"device_uuid",
")",
"return",
"conn_data",
"=",
"self",
".",
"_connections",
"[",
"device_uuid",
"]",
"trace",
"=",
"conn_data",
"[",
"'trace_accum'",
"]",
"if",
"len",
"(",
"trace",
")",
">",
"0",
":",
"slug",
"=",
"self",
".",
"_build_device_slug",
"(",
"device_uuid",
")",
"tracing_topic",
"=",
"self",
".",
"topics",
".",
"prefix",
"+",
"'devices/{}/data/tracing'",
".",
"format",
"(",
"slug",
")",
"data",
"=",
"{",
"'type'",
":",
"'notification'",
",",
"'operation'",
":",
"'trace'",
"}",
"data",
"[",
"'trace'",
"]",
"=",
"binascii",
".",
"hexlify",
"(",
"trace",
")",
"data",
"[",
"'trace_origin'",
"]",
"=",
"device_uuid",
"self",
".",
"_logger",
".",
"debug",
"(",
"'Publishing trace: (topic=%s)'",
",",
"tracing_topic",
")",
"self",
".",
"client",
".",
"publish",
"(",
"tracing_topic",
",",
"data",
")",
"conn_data",
"[",
"'trace_scheduled'",
"]",
"=",
"False",
"conn_data",
"[",
"'last_trace'",
"]",
"=",
"monotonic",
"(",
")",
"conn_data",
"[",
"'trace_accum'",
"]",
"=",
"bytes",
"(",
")"
] |
Send whatever accumulated tracing data we have for the device.
|
[
"Send",
"whatever",
"accumulated",
"tracing",
"data",
"we",
"have",
"for",
"the",
"device",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L631-L655
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._on_scan_request
|
def _on_scan_request(self, sequence, topic, message):
"""Process a request for scanning information
Args:
sequence (int:) The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself
"""
if messages.ProbeCommand.matches(message):
self._logger.debug("Received probe message on topic %s, message=%s", topic, message)
self._loop.add_callback(self._publish_scan_response, message['client'])
else:
self._logger.warn("Invalid message received on topic %s, message=%s", topic, message)
|
python
|
def _on_scan_request(self, sequence, topic, message):
"""Process a request for scanning information
Args:
sequence (int:) The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself
"""
if messages.ProbeCommand.matches(message):
self._logger.debug("Received probe message on topic %s, message=%s", topic, message)
self._loop.add_callback(self._publish_scan_response, message['client'])
else:
self._logger.warn("Invalid message received on topic %s, message=%s", topic, message)
|
[
"def",
"_on_scan_request",
"(",
"self",
",",
"sequence",
",",
"topic",
",",
"message",
")",
":",
"if",
"messages",
".",
"ProbeCommand",
".",
"matches",
"(",
"message",
")",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Received probe message on topic %s, message=%s\"",
",",
"topic",
",",
"message",
")",
"self",
".",
"_loop",
".",
"add_callback",
"(",
"self",
".",
"_publish_scan_response",
",",
"message",
"[",
"'client'",
"]",
")",
"else",
":",
"self",
".",
"_logger",
".",
"warn",
"(",
"\"Invalid message received on topic %s, message=%s\"",
",",
"topic",
",",
"message",
")"
] |
Process a request for scanning information
Args:
sequence (int:) The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself
|
[
"Process",
"a",
"request",
"for",
"scanning",
"information"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L657-L671
|
train
|
iotile/coretools
|
transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py
|
AWSIOTGatewayAgent._publish_scan_response
|
def _publish_scan_response(self, client):
"""Publish a scan response message
The message contains all of the devices that are currently known
to this agent. Connection strings for direct connections are
translated to what is appropriate for this agent.
Args:
client (string): A unique id for the client that made this request
"""
devices = self._manager.scanned_devices
converted_devs = []
for uuid, info in devices.items():
slug = self._build_device_slug(uuid)
message = {}
message['uuid'] = uuid
if uuid in self._connections:
message['user_connected'] = True
elif 'user_connected' in info:
message['user_connected'] = info['user_connected']
else:
message['user_connected'] = False
message['connection_string'] = slug
message['signal_strength'] = info['signal_strength']
converted_devs.append({x: y for x, y in message.items()})
message['type'] = 'notification'
message['operation'] = 'advertisement'
self.client.publish(self.topics.gateway_topic(slug, 'data/advertisement'), message)
probe_message = {}
probe_message['type'] = 'response'
probe_message['client'] = client
probe_message['success'] = True
probe_message['devices'] = converted_devs
self.client.publish(self.topics.status, probe_message)
|
python
|
def _publish_scan_response(self, client):
"""Publish a scan response message
The message contains all of the devices that are currently known
to this agent. Connection strings for direct connections are
translated to what is appropriate for this agent.
Args:
client (string): A unique id for the client that made this request
"""
devices = self._manager.scanned_devices
converted_devs = []
for uuid, info in devices.items():
slug = self._build_device_slug(uuid)
message = {}
message['uuid'] = uuid
if uuid in self._connections:
message['user_connected'] = True
elif 'user_connected' in info:
message['user_connected'] = info['user_connected']
else:
message['user_connected'] = False
message['connection_string'] = slug
message['signal_strength'] = info['signal_strength']
converted_devs.append({x: y for x, y in message.items()})
message['type'] = 'notification'
message['operation'] = 'advertisement'
self.client.publish(self.topics.gateway_topic(slug, 'data/advertisement'), message)
probe_message = {}
probe_message['type'] = 'response'
probe_message['client'] = client
probe_message['success'] = True
probe_message['devices'] = converted_devs
self.client.publish(self.topics.status, probe_message)
|
[
"def",
"_publish_scan_response",
"(",
"self",
",",
"client",
")",
":",
"devices",
"=",
"self",
".",
"_manager",
".",
"scanned_devices",
"converted_devs",
"=",
"[",
"]",
"for",
"uuid",
",",
"info",
"in",
"devices",
".",
"items",
"(",
")",
":",
"slug",
"=",
"self",
".",
"_build_device_slug",
"(",
"uuid",
")",
"message",
"=",
"{",
"}",
"message",
"[",
"'uuid'",
"]",
"=",
"uuid",
"if",
"uuid",
"in",
"self",
".",
"_connections",
":",
"message",
"[",
"'user_connected'",
"]",
"=",
"True",
"elif",
"'user_connected'",
"in",
"info",
":",
"message",
"[",
"'user_connected'",
"]",
"=",
"info",
"[",
"'user_connected'",
"]",
"else",
":",
"message",
"[",
"'user_connected'",
"]",
"=",
"False",
"message",
"[",
"'connection_string'",
"]",
"=",
"slug",
"message",
"[",
"'signal_strength'",
"]",
"=",
"info",
"[",
"'signal_strength'",
"]",
"converted_devs",
".",
"append",
"(",
"{",
"x",
":",
"y",
"for",
"x",
",",
"y",
"in",
"message",
".",
"items",
"(",
")",
"}",
")",
"message",
"[",
"'type'",
"]",
"=",
"'notification'",
"message",
"[",
"'operation'",
"]",
"=",
"'advertisement'",
"self",
".",
"client",
".",
"publish",
"(",
"self",
".",
"topics",
".",
"gateway_topic",
"(",
"slug",
",",
"'data/advertisement'",
")",
",",
"message",
")",
"probe_message",
"=",
"{",
"}",
"probe_message",
"[",
"'type'",
"]",
"=",
"'response'",
"probe_message",
"[",
"'client'",
"]",
"=",
"client",
"probe_message",
"[",
"'success'",
"]",
"=",
"True",
"probe_message",
"[",
"'devices'",
"]",
"=",
"converted_devs",
"self",
".",
"client",
".",
"publish",
"(",
"self",
".",
"topics",
".",
"status",
",",
"probe_message",
")"
] |
Publish a scan response message
The message contains all of the devices that are currently known
to this agent. Connection strings for direct connections are
translated to what is appropriate for this agent.
Args:
client (string): A unique id for the client that made this request
|
[
"Publish",
"a",
"scan",
"response",
"message"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/awsiot/iotile_transport_awsiot/gateway_agent.py#L673-L714
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/link.py
|
_versioned_lib_suffix
|
def _versioned_lib_suffix(env, suffix, version):
"""For suffix='.so' and version='0.1.2' it returns '.so.0.1.2'"""
Verbose = False
if Verbose:
print("_versioned_lib_suffix: suffix={:r}".format(suffix))
print("_versioned_lib_suffix: version={:r}".format(version))
if not suffix.endswith(version):
suffix = suffix + '.' + version
if Verbose:
print("_versioned_lib_suffix: return suffix={:r}".format(suffix))
return suffix
|
python
|
def _versioned_lib_suffix(env, suffix, version):
"""For suffix='.so' and version='0.1.2' it returns '.so.0.1.2'"""
Verbose = False
if Verbose:
print("_versioned_lib_suffix: suffix={:r}".format(suffix))
print("_versioned_lib_suffix: version={:r}".format(version))
if not suffix.endswith(version):
suffix = suffix + '.' + version
if Verbose:
print("_versioned_lib_suffix: return suffix={:r}".format(suffix))
return suffix
|
[
"def",
"_versioned_lib_suffix",
"(",
"env",
",",
"suffix",
",",
"version",
")",
":",
"Verbose",
"=",
"False",
"if",
"Verbose",
":",
"print",
"(",
"\"_versioned_lib_suffix: suffix={:r}\"",
".",
"format",
"(",
"suffix",
")",
")",
"print",
"(",
"\"_versioned_lib_suffix: version={:r}\"",
".",
"format",
"(",
"version",
")",
")",
"if",
"not",
"suffix",
".",
"endswith",
"(",
"version",
")",
":",
"suffix",
"=",
"suffix",
"+",
"'.'",
"+",
"version",
"if",
"Verbose",
":",
"print",
"(",
"\"_versioned_lib_suffix: return suffix={:r}\"",
".",
"format",
"(",
"suffix",
")",
")",
"return",
"suffix"
] |
For suffix='.so' and version='0.1.2' it returns '.so.0.1.2
|
[
"For",
"suffix",
"=",
".",
"so",
"and",
"version",
"=",
"0",
".",
"1",
".",
"2",
"it",
"returns",
".",
"so",
".",
"0",
".",
"1",
".",
"2"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/link.py#L148-L158
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/link.py
|
_setup_versioned_lib_variables
|
def _setup_versioned_lib_variables(env, **kw):
"""
Setup all variables required by the versioning machinery
"""
tool = None
try: tool = kw['tool']
except KeyError: pass
use_soname = False
try: use_soname = kw['use_soname']
except KeyError: pass
# The $_SHLIBVERSIONFLAGS define extra commandline flags used when
# building VERSIONED shared libraries. It's always set, but used only
# when VERSIONED library is built (see __SHLIBVERSIONFLAGS in SCons/Defaults.py).
if use_soname:
# If the linker uses SONAME, then we need this little automata
if tool == 'sunlink':
env['_SHLIBVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS -h $_SHLIBSONAME'
env['_LDMODULEVERSIONFLAGS'] = '$LDMODULEVERSIONFLAGS -h $_LDMODULESONAME'
else:
env['_SHLIBVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS -Wl,-soname=$_SHLIBSONAME'
env['_LDMODULEVERSIONFLAGS'] = '$LDMODULEVERSIONFLAGS -Wl,-soname=$_LDMODULESONAME'
env['_SHLIBSONAME'] = '${ShLibSonameGenerator(__env__,TARGET)}'
env['_LDMODULESONAME'] = '${LdModSonameGenerator(__env__,TARGET)}'
env['ShLibSonameGenerator'] = SCons.Tool.ShLibSonameGenerator
env['LdModSonameGenerator'] = SCons.Tool.LdModSonameGenerator
else:
env['_SHLIBVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS'
env['_LDMODULEVERSIONFLAGS'] = '$LDMODULEVERSIONFLAGS'
# LDOMDULVERSIONFLAGS should always default to $SHLIBVERSIONFLAGS
env['LDMODULEVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS'
|
python
|
def _setup_versioned_lib_variables(env, **kw):
"""
Setup all variables required by the versioning machinery
"""
tool = None
try: tool = kw['tool']
except KeyError: pass
use_soname = False
try: use_soname = kw['use_soname']
except KeyError: pass
# The $_SHLIBVERSIONFLAGS define extra commandline flags used when
# building VERSIONED shared libraries. It's always set, but used only
# when VERSIONED library is built (see __SHLIBVERSIONFLAGS in SCons/Defaults.py).
if use_soname:
# If the linker uses SONAME, then we need this little automata
if tool == 'sunlink':
env['_SHLIBVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS -h $_SHLIBSONAME'
env['_LDMODULEVERSIONFLAGS'] = '$LDMODULEVERSIONFLAGS -h $_LDMODULESONAME'
else:
env['_SHLIBVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS -Wl,-soname=$_SHLIBSONAME'
env['_LDMODULEVERSIONFLAGS'] = '$LDMODULEVERSIONFLAGS -Wl,-soname=$_LDMODULESONAME'
env['_SHLIBSONAME'] = '${ShLibSonameGenerator(__env__,TARGET)}'
env['_LDMODULESONAME'] = '${LdModSonameGenerator(__env__,TARGET)}'
env['ShLibSonameGenerator'] = SCons.Tool.ShLibSonameGenerator
env['LdModSonameGenerator'] = SCons.Tool.LdModSonameGenerator
else:
env['_SHLIBVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS'
env['_LDMODULEVERSIONFLAGS'] = '$LDMODULEVERSIONFLAGS'
# LDOMDULVERSIONFLAGS should always default to $SHLIBVERSIONFLAGS
env['LDMODULEVERSIONFLAGS'] = '$SHLIBVERSIONFLAGS'
|
[
"def",
"_setup_versioned_lib_variables",
"(",
"env",
",",
"*",
"*",
"kw",
")",
":",
"tool",
"=",
"None",
"try",
":",
"tool",
"=",
"kw",
"[",
"'tool'",
"]",
"except",
"KeyError",
":",
"pass",
"use_soname",
"=",
"False",
"try",
":",
"use_soname",
"=",
"kw",
"[",
"'use_soname'",
"]",
"except",
"KeyError",
":",
"pass",
"# The $_SHLIBVERSIONFLAGS define extra commandline flags used when",
"# building VERSIONED shared libraries. It's always set, but used only",
"# when VERSIONED library is built (see __SHLIBVERSIONFLAGS in SCons/Defaults.py).",
"if",
"use_soname",
":",
"# If the linker uses SONAME, then we need this little automata",
"if",
"tool",
"==",
"'sunlink'",
":",
"env",
"[",
"'_SHLIBVERSIONFLAGS'",
"]",
"=",
"'$SHLIBVERSIONFLAGS -h $_SHLIBSONAME'",
"env",
"[",
"'_LDMODULEVERSIONFLAGS'",
"]",
"=",
"'$LDMODULEVERSIONFLAGS -h $_LDMODULESONAME'",
"else",
":",
"env",
"[",
"'_SHLIBVERSIONFLAGS'",
"]",
"=",
"'$SHLIBVERSIONFLAGS -Wl,-soname=$_SHLIBSONAME'",
"env",
"[",
"'_LDMODULEVERSIONFLAGS'",
"]",
"=",
"'$LDMODULEVERSIONFLAGS -Wl,-soname=$_LDMODULESONAME'",
"env",
"[",
"'_SHLIBSONAME'",
"]",
"=",
"'${ShLibSonameGenerator(__env__,TARGET)}'",
"env",
"[",
"'_LDMODULESONAME'",
"]",
"=",
"'${LdModSonameGenerator(__env__,TARGET)}'",
"env",
"[",
"'ShLibSonameGenerator'",
"]",
"=",
"SCons",
".",
"Tool",
".",
"ShLibSonameGenerator",
"env",
"[",
"'LdModSonameGenerator'",
"]",
"=",
"SCons",
".",
"Tool",
".",
"LdModSonameGenerator",
"else",
":",
"env",
"[",
"'_SHLIBVERSIONFLAGS'",
"]",
"=",
"'$SHLIBVERSIONFLAGS'",
"env",
"[",
"'_LDMODULEVERSIONFLAGS'",
"]",
"=",
"'$LDMODULEVERSIONFLAGS'",
"# LDOMDULVERSIONFLAGS should always default to $SHLIBVERSIONFLAGS",
"env",
"[",
"'LDMODULEVERSIONFLAGS'",
"]",
"=",
"'$SHLIBVERSIONFLAGS'"
] |
Setup all variables required by the versioning machinery
|
[
"Setup",
"all",
"variables",
"required",
"by",
"the",
"versioning",
"machinery"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Tool/link.py#L245-L278
|
train
|
iotile/coretools
|
iotilegateway/iotilegateway/main.py
|
main
|
def main(argv=None, loop=SharedLoop, max_time=None):
"""Main entry point for iotile-gateway."""
should_raise = argv is not None
if argv is None:
argv = sys.argv[1:]
parser = build_parser()
cmd_args = parser.parse_args(argv)
configure_logging(cmd_args.verbose)
logger = logging.getLogger(__name__)
try:
args = {}
if cmd_args.config is not None:
try:
with open(cmd_args.config, "r") as conf:
args = json.load(conf)
except IOError as exc:
raise ScriptError("Could not open config file %s due to %s"
% (cmd_args.config, str(exc)), 2)
except ValueError as exc:
raise ScriptError("Could not parse JSON from config file %s due to %s"
% (cmd_args.config, str(exc)), 3)
except TypeError as exc:
raise ScriptError("You must pass the path to a json config file", 4)
logger.critical("Starting gateway")
gateway = IOTileGateway(args, loop=loop)
loop.run_coroutine(gateway.start())
logger.critical("Gateway running")
# Run forever until we receive a ctrl-c
# (allow quitting early after max_time seconds for testing)
loop.wait_for_interrupt(max_time=max_time)
loop.run_coroutine(gateway.stop())
except ScriptError as exc:
if should_raise:
raise exc
logger.fatal("Quitting due to error: %s", exc.msg)
return exc.code
except Exception as exc: # pylint: disable=W0703
if should_raise:
raise exc
logger.exception("Fatal error running gateway")
return 1
return 0
|
python
|
def main(argv=None, loop=SharedLoop, max_time=None):
"""Main entry point for iotile-gateway."""
should_raise = argv is not None
if argv is None:
argv = sys.argv[1:]
parser = build_parser()
cmd_args = parser.parse_args(argv)
configure_logging(cmd_args.verbose)
logger = logging.getLogger(__name__)
try:
args = {}
if cmd_args.config is not None:
try:
with open(cmd_args.config, "r") as conf:
args = json.load(conf)
except IOError as exc:
raise ScriptError("Could not open config file %s due to %s"
% (cmd_args.config, str(exc)), 2)
except ValueError as exc:
raise ScriptError("Could not parse JSON from config file %s due to %s"
% (cmd_args.config, str(exc)), 3)
except TypeError as exc:
raise ScriptError("You must pass the path to a json config file", 4)
logger.critical("Starting gateway")
gateway = IOTileGateway(args, loop=loop)
loop.run_coroutine(gateway.start())
logger.critical("Gateway running")
# Run forever until we receive a ctrl-c
# (allow quitting early after max_time seconds for testing)
loop.wait_for_interrupt(max_time=max_time)
loop.run_coroutine(gateway.stop())
except ScriptError as exc:
if should_raise:
raise exc
logger.fatal("Quitting due to error: %s", exc.msg)
return exc.code
except Exception as exc: # pylint: disable=W0703
if should_raise:
raise exc
logger.exception("Fatal error running gateway")
return 1
return 0
|
[
"def",
"main",
"(",
"argv",
"=",
"None",
",",
"loop",
"=",
"SharedLoop",
",",
"max_time",
"=",
"None",
")",
":",
"should_raise",
"=",
"argv",
"is",
"not",
"None",
"if",
"argv",
"is",
"None",
":",
"argv",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
"parser",
"=",
"build_parser",
"(",
")",
"cmd_args",
"=",
"parser",
".",
"parse_args",
"(",
"argv",
")",
"configure_logging",
"(",
"cmd_args",
".",
"verbose",
")",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"__name__",
")",
"try",
":",
"args",
"=",
"{",
"}",
"if",
"cmd_args",
".",
"config",
"is",
"not",
"None",
":",
"try",
":",
"with",
"open",
"(",
"cmd_args",
".",
"config",
",",
"\"r\"",
")",
"as",
"conf",
":",
"args",
"=",
"json",
".",
"load",
"(",
"conf",
")",
"except",
"IOError",
"as",
"exc",
":",
"raise",
"ScriptError",
"(",
"\"Could not open config file %s due to %s\"",
"%",
"(",
"cmd_args",
".",
"config",
",",
"str",
"(",
"exc",
")",
")",
",",
"2",
")",
"except",
"ValueError",
"as",
"exc",
":",
"raise",
"ScriptError",
"(",
"\"Could not parse JSON from config file %s due to %s\"",
"%",
"(",
"cmd_args",
".",
"config",
",",
"str",
"(",
"exc",
")",
")",
",",
"3",
")",
"except",
"TypeError",
"as",
"exc",
":",
"raise",
"ScriptError",
"(",
"\"You must pass the path to a json config file\"",
",",
"4",
")",
"logger",
".",
"critical",
"(",
"\"Starting gateway\"",
")",
"gateway",
"=",
"IOTileGateway",
"(",
"args",
",",
"loop",
"=",
"loop",
")",
"loop",
".",
"run_coroutine",
"(",
"gateway",
".",
"start",
"(",
")",
")",
"logger",
".",
"critical",
"(",
"\"Gateway running\"",
")",
"# Run forever until we receive a ctrl-c",
"# (allow quitting early after max_time seconds for testing)",
"loop",
".",
"wait_for_interrupt",
"(",
"max_time",
"=",
"max_time",
")",
"loop",
".",
"run_coroutine",
"(",
"gateway",
".",
"stop",
"(",
")",
")",
"except",
"ScriptError",
"as",
"exc",
":",
"if",
"should_raise",
":",
"raise",
"exc",
"logger",
".",
"fatal",
"(",
"\"Quitting due to error: %s\"",
",",
"exc",
".",
"msg",
")",
"return",
"exc",
".",
"code",
"except",
"Exception",
"as",
"exc",
":",
"# pylint: disable=W0703",
"if",
"should_raise",
":",
"raise",
"exc",
"logger",
".",
"exception",
"(",
"\"Fatal error running gateway\"",
")",
"return",
"1",
"return",
"0"
] |
Main entry point for iotile-gateway.
|
[
"Main",
"entry",
"point",
"for",
"iotile",
"-",
"gateway",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilegateway/iotilegateway/main.py#L54-L107
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
_TimeAnchor.copy
|
def copy(self):
"""Return a copy of this _TimeAnchor."""
return _TimeAnchor(self.reading_id, self.uptime, self.utc, self.is_break, self.exact)
|
python
|
def copy(self):
"""Return a copy of this _TimeAnchor."""
return _TimeAnchor(self.reading_id, self.uptime, self.utc, self.is_break, self.exact)
|
[
"def",
"copy",
"(",
"self",
")",
":",
"return",
"_TimeAnchor",
"(",
"self",
".",
"reading_id",
",",
"self",
".",
"uptime",
",",
"self",
".",
"utc",
",",
"self",
".",
"is_break",
",",
"self",
".",
"exact",
")"
] |
Return a copy of this _TimeAnchor.
|
[
"Return",
"a",
"copy",
"of",
"this",
"_TimeAnchor",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L43-L45
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.anchor_stream
|
def anchor_stream(self, stream_id, converter="rtc"):
"""Mark a stream as containing anchor points."""
if isinstance(converter, str):
converter = self._known_converters.get(converter)
if converter is None:
raise ArgumentError("Unknown anchor converter string: %s" % converter,
known_converters=list(self._known_converters))
self._anchor_streams[stream_id] = converter
|
python
|
def anchor_stream(self, stream_id, converter="rtc"):
"""Mark a stream as containing anchor points."""
if isinstance(converter, str):
converter = self._known_converters.get(converter)
if converter is None:
raise ArgumentError("Unknown anchor converter string: %s" % converter,
known_converters=list(self._known_converters))
self._anchor_streams[stream_id] = converter
|
[
"def",
"anchor_stream",
"(",
"self",
",",
"stream_id",
",",
"converter",
"=",
"\"rtc\"",
")",
":",
"if",
"isinstance",
"(",
"converter",
",",
"str",
")",
":",
"converter",
"=",
"self",
".",
"_known_converters",
".",
"get",
"(",
"converter",
")",
"if",
"converter",
"is",
"None",
":",
"raise",
"ArgumentError",
"(",
"\"Unknown anchor converter string: %s\"",
"%",
"converter",
",",
"known_converters",
"=",
"list",
"(",
"self",
".",
"_known_converters",
")",
")",
"self",
".",
"_anchor_streams",
"[",
"stream_id",
"]",
"=",
"converter"
] |
Mark a stream as containing anchor points.
|
[
"Mark",
"a",
"stream",
"as",
"containing",
"anchor",
"points",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L125-L135
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.id_range
|
def id_range(self):
"""Get the range of archor reading_ids.
Returns:
(int, int): The lowest and highest reading ids.
If no reading ids have been loaded, (0, 0) is returned.
"""
if len(self._anchor_points) == 0:
return (0, 0)
return (self._anchor_points[0].reading_id, self._anchor_points[-1].reading_id)
|
python
|
def id_range(self):
"""Get the range of archor reading_ids.
Returns:
(int, int): The lowest and highest reading ids.
If no reading ids have been loaded, (0, 0) is returned.
"""
if len(self._anchor_points) == 0:
return (0, 0)
return (self._anchor_points[0].reading_id, self._anchor_points[-1].reading_id)
|
[
"def",
"id_range",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"_anchor_points",
")",
"==",
"0",
":",
"return",
"(",
"0",
",",
"0",
")",
"return",
"(",
"self",
".",
"_anchor_points",
"[",
"0",
"]",
".",
"reading_id",
",",
"self",
".",
"_anchor_points",
"[",
"-",
"1",
"]",
".",
"reading_id",
")"
] |
Get the range of archor reading_ids.
Returns:
(int, int): The lowest and highest reading ids.
If no reading ids have been loaded, (0, 0) is returned.
|
[
"Get",
"the",
"range",
"of",
"archor",
"reading_ids",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L137-L149
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner._convert_epoch_anchor
|
def _convert_epoch_anchor(cls, reading):
"""Convert a reading containing an epoch timestamp to datetime."""
delta = datetime.timedelta(seconds=reading.value)
return cls._EpochReference + delta
|
python
|
def _convert_epoch_anchor(cls, reading):
"""Convert a reading containing an epoch timestamp to datetime."""
delta = datetime.timedelta(seconds=reading.value)
return cls._EpochReference + delta
|
[
"def",
"_convert_epoch_anchor",
"(",
"cls",
",",
"reading",
")",
":",
"delta",
"=",
"datetime",
".",
"timedelta",
"(",
"seconds",
"=",
"reading",
".",
"value",
")",
"return",
"cls",
".",
"_EpochReference",
"+",
"delta"
] |
Convert a reading containing an epoch timestamp to datetime.
|
[
"Convert",
"a",
"reading",
"containing",
"an",
"epoch",
"timestamp",
"to",
"datetime",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L168-L172
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.add_point
|
def add_point(self, reading_id, uptime=None, utc=None, is_break=False):
"""Add a time point that could be used as a UTC reference."""
if reading_id == 0:
return
if uptime is None and utc is None:
return
if uptime is not None and uptime & (1 << 31):
if utc is not None:
return
uptime &= ~(1 << 31)
utc = self.convert_rtc(uptime)
uptime = None
anchor = _TimeAnchor(reading_id, uptime, utc, is_break, exact=utc is not None)
if anchor in self._anchor_points:
return
self._anchor_points.add(anchor)
self._prepared = False
|
python
|
def add_point(self, reading_id, uptime=None, utc=None, is_break=False):
"""Add a time point that could be used as a UTC reference."""
if reading_id == 0:
return
if uptime is None and utc is None:
return
if uptime is not None and uptime & (1 << 31):
if utc is not None:
return
uptime &= ~(1 << 31)
utc = self.convert_rtc(uptime)
uptime = None
anchor = _TimeAnchor(reading_id, uptime, utc, is_break, exact=utc is not None)
if anchor in self._anchor_points:
return
self._anchor_points.add(anchor)
self._prepared = False
|
[
"def",
"add_point",
"(",
"self",
",",
"reading_id",
",",
"uptime",
"=",
"None",
",",
"utc",
"=",
"None",
",",
"is_break",
"=",
"False",
")",
":",
"if",
"reading_id",
"==",
"0",
":",
"return",
"if",
"uptime",
"is",
"None",
"and",
"utc",
"is",
"None",
":",
"return",
"if",
"uptime",
"is",
"not",
"None",
"and",
"uptime",
"&",
"(",
"1",
"<<",
"31",
")",
":",
"if",
"utc",
"is",
"not",
"None",
":",
"return",
"uptime",
"&=",
"~",
"(",
"1",
"<<",
"31",
")",
"utc",
"=",
"self",
".",
"convert_rtc",
"(",
"uptime",
")",
"uptime",
"=",
"None",
"anchor",
"=",
"_TimeAnchor",
"(",
"reading_id",
",",
"uptime",
",",
"utc",
",",
"is_break",
",",
"exact",
"=",
"utc",
"is",
"not",
"None",
")",
"if",
"anchor",
"in",
"self",
".",
"_anchor_points",
":",
"return",
"self",
".",
"_anchor_points",
".",
"add",
"(",
"anchor",
")",
"self",
".",
"_prepared",
"=",
"False"
] |
Add a time point that could be used as a UTC reference.
|
[
"Add",
"a",
"time",
"point",
"that",
"could",
"be",
"used",
"as",
"a",
"UTC",
"reference",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L174-L198
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.add_reading
|
def add_reading(self, reading):
"""Add an IOTileReading."""
is_break = False
utc = None
if reading.stream in self._break_streams:
is_break = True
if reading.stream in self._anchor_streams:
utc = self._anchor_streams[reading.stream](reading)
self.add_point(reading.reading_id, reading.raw_time, utc, is_break=is_break)
|
python
|
def add_reading(self, reading):
"""Add an IOTileReading."""
is_break = False
utc = None
if reading.stream in self._break_streams:
is_break = True
if reading.stream in self._anchor_streams:
utc = self._anchor_streams[reading.stream](reading)
self.add_point(reading.reading_id, reading.raw_time, utc, is_break=is_break)
|
[
"def",
"add_reading",
"(",
"self",
",",
"reading",
")",
":",
"is_break",
"=",
"False",
"utc",
"=",
"None",
"if",
"reading",
".",
"stream",
"in",
"self",
".",
"_break_streams",
":",
"is_break",
"=",
"True",
"if",
"reading",
".",
"stream",
"in",
"self",
".",
"_anchor_streams",
":",
"utc",
"=",
"self",
".",
"_anchor_streams",
"[",
"reading",
".",
"stream",
"]",
"(",
"reading",
")",
"self",
".",
"add_point",
"(",
"reading",
".",
"reading_id",
",",
"reading",
".",
"raw_time",
",",
"utc",
",",
"is_break",
"=",
"is_break",
")"
] |
Add an IOTileReading.
|
[
"Add",
"an",
"IOTileReading",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L200-L212
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.add_report
|
def add_report(self, report, ignore_errors=False):
"""Add all anchors from a report."""
if not isinstance(report, SignedListReport):
if ignore_errors:
return
raise ArgumentError("You can only add SignedListReports to a UTCAssigner", report=report)
for reading in report.visible_readings:
self.add_reading(reading)
self.add_point(report.report_id, report.sent_timestamp, report.received_time)
|
python
|
def add_report(self, report, ignore_errors=False):
"""Add all anchors from a report."""
if not isinstance(report, SignedListReport):
if ignore_errors:
return
raise ArgumentError("You can only add SignedListReports to a UTCAssigner", report=report)
for reading in report.visible_readings:
self.add_reading(reading)
self.add_point(report.report_id, report.sent_timestamp, report.received_time)
|
[
"def",
"add_report",
"(",
"self",
",",
"report",
",",
"ignore_errors",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"report",
",",
"SignedListReport",
")",
":",
"if",
"ignore_errors",
":",
"return",
"raise",
"ArgumentError",
"(",
"\"You can only add SignedListReports to a UTCAssigner\"",
",",
"report",
"=",
"report",
")",
"for",
"reading",
"in",
"report",
".",
"visible_readings",
":",
"self",
".",
"add_reading",
"(",
"reading",
")",
"self",
".",
"add_point",
"(",
"report",
".",
"report_id",
",",
"report",
".",
"sent_timestamp",
",",
"report",
".",
"received_time",
")"
] |
Add all anchors from a report.
|
[
"Add",
"all",
"anchors",
"from",
"a",
"report",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L214-L226
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.assign_utc
|
def assign_utc(self, reading_id, uptime=None, prefer="before"):
"""Assign a utc datetime to a reading id.
This method will return an object with assignment information or None
if a utc value cannot be assigned. The assignment object returned
contains a utc property that has the asssigned UTC as well as other
properties describing how reliable the assignment is.
Args:
reading_id (int): The monotonic reading id that we wish to assign
a utc timestamp to.
uptime (int): Optional uptime that should be associated with the
reading id. If this is not specified and the reading_id is
found in the anchor points passed to this class then the
uptime from the corresponding anchor point will be used.
prefer (str): There are two possible directions that can be used
to assign a UTC timestamp (the nearest anchor before or after the
reading). If both directions are of similar quality, the choice
is arbitrary. Passing prefer="before" will use the anchor point
before the reading. Passing prefer="after" will use the anchor
point after the reading. Default: before.
Returns:
UTCAssignment: The assigned UTC time or None if assignment is impossible.
"""
if prefer not in ("before", "after"):
raise ArgumentError("Invalid prefer parameter: {}, must be 'before' or 'after'".format(prefer))
if len(self._anchor_points) == 0:
return None
if reading_id > self._anchor_points[-1].reading_id:
return None
i = self._anchor_points.bisect_key_left(reading_id)
found_id = False
crossed_break = False
exact = True
last = self._anchor_points[i].copy()
if uptime is not None:
last.uptime = uptime
if last.reading_id == reading_id:
found_id = True
if last.utc is not None:
return UTCAssignment(reading_id, last.utc, found_id, exact, crossed_break)
left_assign = self._fix_left(reading_id, last, i, found_id)
if left_assign is not None and left_assign.exact:
return left_assign
right_assign = self._fix_right(reading_id, last, i, found_id)
if right_assign is not None and right_assign.exact:
return right_assign
return self._pick_best_fix(left_assign, right_assign, prefer)
|
python
|
def assign_utc(self, reading_id, uptime=None, prefer="before"):
"""Assign a utc datetime to a reading id.
This method will return an object with assignment information or None
if a utc value cannot be assigned. The assignment object returned
contains a utc property that has the asssigned UTC as well as other
properties describing how reliable the assignment is.
Args:
reading_id (int): The monotonic reading id that we wish to assign
a utc timestamp to.
uptime (int): Optional uptime that should be associated with the
reading id. If this is not specified and the reading_id is
found in the anchor points passed to this class then the
uptime from the corresponding anchor point will be used.
prefer (str): There are two possible directions that can be used
to assign a UTC timestamp (the nearest anchor before or after the
reading). If both directions are of similar quality, the choice
is arbitrary. Passing prefer="before" will use the anchor point
before the reading. Passing prefer="after" will use the anchor
point after the reading. Default: before.
Returns:
UTCAssignment: The assigned UTC time or None if assignment is impossible.
"""
if prefer not in ("before", "after"):
raise ArgumentError("Invalid prefer parameter: {}, must be 'before' or 'after'".format(prefer))
if len(self._anchor_points) == 0:
return None
if reading_id > self._anchor_points[-1].reading_id:
return None
i = self._anchor_points.bisect_key_left(reading_id)
found_id = False
crossed_break = False
exact = True
last = self._anchor_points[i].copy()
if uptime is not None:
last.uptime = uptime
if last.reading_id == reading_id:
found_id = True
if last.utc is not None:
return UTCAssignment(reading_id, last.utc, found_id, exact, crossed_break)
left_assign = self._fix_left(reading_id, last, i, found_id)
if left_assign is not None and left_assign.exact:
return left_assign
right_assign = self._fix_right(reading_id, last, i, found_id)
if right_assign is not None and right_assign.exact:
return right_assign
return self._pick_best_fix(left_assign, right_assign, prefer)
|
[
"def",
"assign_utc",
"(",
"self",
",",
"reading_id",
",",
"uptime",
"=",
"None",
",",
"prefer",
"=",
"\"before\"",
")",
":",
"if",
"prefer",
"not",
"in",
"(",
"\"before\"",
",",
"\"after\"",
")",
":",
"raise",
"ArgumentError",
"(",
"\"Invalid prefer parameter: {}, must be 'before' or 'after'\"",
".",
"format",
"(",
"prefer",
")",
")",
"if",
"len",
"(",
"self",
".",
"_anchor_points",
")",
"==",
"0",
":",
"return",
"None",
"if",
"reading_id",
">",
"self",
".",
"_anchor_points",
"[",
"-",
"1",
"]",
".",
"reading_id",
":",
"return",
"None",
"i",
"=",
"self",
".",
"_anchor_points",
".",
"bisect_key_left",
"(",
"reading_id",
")",
"found_id",
"=",
"False",
"crossed_break",
"=",
"False",
"exact",
"=",
"True",
"last",
"=",
"self",
".",
"_anchor_points",
"[",
"i",
"]",
".",
"copy",
"(",
")",
"if",
"uptime",
"is",
"not",
"None",
":",
"last",
".",
"uptime",
"=",
"uptime",
"if",
"last",
".",
"reading_id",
"==",
"reading_id",
":",
"found_id",
"=",
"True",
"if",
"last",
".",
"utc",
"is",
"not",
"None",
":",
"return",
"UTCAssignment",
"(",
"reading_id",
",",
"last",
".",
"utc",
",",
"found_id",
",",
"exact",
",",
"crossed_break",
")",
"left_assign",
"=",
"self",
".",
"_fix_left",
"(",
"reading_id",
",",
"last",
",",
"i",
",",
"found_id",
")",
"if",
"left_assign",
"is",
"not",
"None",
"and",
"left_assign",
".",
"exact",
":",
"return",
"left_assign",
"right_assign",
"=",
"self",
".",
"_fix_right",
"(",
"reading_id",
",",
"last",
",",
"i",
",",
"found_id",
")",
"if",
"right_assign",
"is",
"not",
"None",
"and",
"right_assign",
".",
"exact",
":",
"return",
"right_assign",
"return",
"self",
".",
"_pick_best_fix",
"(",
"left_assign",
",",
"right_assign",
",",
"prefer",
")"
] |
Assign a utc datetime to a reading id.
This method will return an object with assignment information or None
if a utc value cannot be assigned. The assignment object returned
contains a utc property that has the asssigned UTC as well as other
properties describing how reliable the assignment is.
Args:
reading_id (int): The monotonic reading id that we wish to assign
a utc timestamp to.
uptime (int): Optional uptime that should be associated with the
reading id. If this is not specified and the reading_id is
found in the anchor points passed to this class then the
uptime from the corresponding anchor point will be used.
prefer (str): There are two possible directions that can be used
to assign a UTC timestamp (the nearest anchor before or after the
reading). If both directions are of similar quality, the choice
is arbitrary. Passing prefer="before" will use the anchor point
before the reading. Passing prefer="after" will use the anchor
point after the reading. Default: before.
Returns:
UTCAssignment: The assigned UTC time or None if assignment is impossible.
|
[
"Assign",
"a",
"utc",
"datetime",
"to",
"a",
"reading",
"id",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L228-L286
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.ensure_prepared
|
def ensure_prepared(self):
"""Calculate and cache UTC values for all exactly known anchor points."""
if self._prepared:
return
exact_count = 0
fixed_count = 0
inexact_count = 0
self._logger.debug("Preparing UTCAssigner (%d total anchors)", len(self._anchor_points))
for curr in self._anchor_points:
if not curr.exact:
assignment = self.assign_utc(curr.reading_id, curr.uptime)
if assignment is not None and assignment.exact:
curr.utc = assignment.utc
curr.exact = True
fixed_count += 1
else:
inexact_count += 1
else:
exact_count += 1
self._logger.debug("Prepared UTCAssigner with %d reference points, "
"%d exact anchors and %d inexact anchors",
exact_count, fixed_count, inexact_count)
self._prepared = True
|
python
|
def ensure_prepared(self):
"""Calculate and cache UTC values for all exactly known anchor points."""
if self._prepared:
return
exact_count = 0
fixed_count = 0
inexact_count = 0
self._logger.debug("Preparing UTCAssigner (%d total anchors)", len(self._anchor_points))
for curr in self._anchor_points:
if not curr.exact:
assignment = self.assign_utc(curr.reading_id, curr.uptime)
if assignment is not None and assignment.exact:
curr.utc = assignment.utc
curr.exact = True
fixed_count += 1
else:
inexact_count += 1
else:
exact_count += 1
self._logger.debug("Prepared UTCAssigner with %d reference points, "
"%d exact anchors and %d inexact anchors",
exact_count, fixed_count, inexact_count)
self._prepared = True
|
[
"def",
"ensure_prepared",
"(",
"self",
")",
":",
"if",
"self",
".",
"_prepared",
":",
"return",
"exact_count",
"=",
"0",
"fixed_count",
"=",
"0",
"inexact_count",
"=",
"0",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Preparing UTCAssigner (%d total anchors)\"",
",",
"len",
"(",
"self",
".",
"_anchor_points",
")",
")",
"for",
"curr",
"in",
"self",
".",
"_anchor_points",
":",
"if",
"not",
"curr",
".",
"exact",
":",
"assignment",
"=",
"self",
".",
"assign_utc",
"(",
"curr",
".",
"reading_id",
",",
"curr",
".",
"uptime",
")",
"if",
"assignment",
"is",
"not",
"None",
"and",
"assignment",
".",
"exact",
":",
"curr",
".",
"utc",
"=",
"assignment",
".",
"utc",
"curr",
".",
"exact",
"=",
"True",
"fixed_count",
"+=",
"1",
"else",
":",
"inexact_count",
"+=",
"1",
"else",
":",
"exact_count",
"+=",
"1",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"Prepared UTCAssigner with %d reference points, \"",
"\"%d exact anchors and %d inexact anchors\"",
",",
"exact_count",
",",
"fixed_count",
",",
"inexact_count",
")",
"self",
".",
"_prepared",
"=",
"True"
] |
Calculate and cache UTC values for all exactly known anchor points.
|
[
"Calculate",
"and",
"cache",
"UTC",
"values",
"for",
"all",
"exactly",
"known",
"anchor",
"points",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L288-L316
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner.fix_report
|
def fix_report(self, report, errors="drop", prefer="before"):
"""Perform utc assignment on all readings in a report.
The returned report will have all reading timestamps in UTC. This only
works on SignedListReport objects. Note that the report should
typically have previously been added to the UTC assigner using
add_report or no reference points from the report will be used.
Args:
report (SignedListReport): The report that we should fix.
errors (str): The behavior that we should have when we can't
fix a given reading. The only currently support behavior is
drop, which means that the reading will be dropped and not
included in the new report.
prefer (str): Whether to prefer fixing readings by looking for
reference points after the reading or before, all other things
being equal. See the description of ``assign_utc``.
Returns:
SignedListReport: The report with UTC timestamps.
"""
if not isinstance(report, SignedListReport):
raise ArgumentError("Report must be a SignedListReport", report=report)
if errors not in ('drop',):
raise ArgumentError("Unknown errors handler: {}, supported=['drop']".format(errors))
self.ensure_prepared()
fixed_readings = []
dropped_readings = 0
for reading in report.visible_readings:
assignment = self.assign_utc(reading.reading_id, reading.raw_time, prefer=prefer)
if assignment is None:
dropped_readings += 1
continue
fixed_reading = IOTileReading(assignment.rtc_value, reading.stream, reading.value,
reading_time=assignment.utc, reading_id=reading.reading_id)
fixed_readings.append(fixed_reading)
fixed_report = SignedListReport.FromReadings(report.origin, fixed_readings, report_id=report.report_id,
selector=report.streamer_selector, streamer=report.origin_streamer,
sent_timestamp=report.sent_timestamp)
fixed_report.received_time = report.received_time
if dropped_readings > 0:
self._logger.warning("Dropped %d readings of %d when fixing UTC timestamps in report 0x%08X for device 0x%08X",
dropped_readings, len(report.visible_readings), report.report_id, report.origin)
return fixed_report
|
python
|
def fix_report(self, report, errors="drop", prefer="before"):
"""Perform utc assignment on all readings in a report.
The returned report will have all reading timestamps in UTC. This only
works on SignedListReport objects. Note that the report should
typically have previously been added to the UTC assigner using
add_report or no reference points from the report will be used.
Args:
report (SignedListReport): The report that we should fix.
errors (str): The behavior that we should have when we can't
fix a given reading. The only currently support behavior is
drop, which means that the reading will be dropped and not
included in the new report.
prefer (str): Whether to prefer fixing readings by looking for
reference points after the reading or before, all other things
being equal. See the description of ``assign_utc``.
Returns:
SignedListReport: The report with UTC timestamps.
"""
if not isinstance(report, SignedListReport):
raise ArgumentError("Report must be a SignedListReport", report=report)
if errors not in ('drop',):
raise ArgumentError("Unknown errors handler: {}, supported=['drop']".format(errors))
self.ensure_prepared()
fixed_readings = []
dropped_readings = 0
for reading in report.visible_readings:
assignment = self.assign_utc(reading.reading_id, reading.raw_time, prefer=prefer)
if assignment is None:
dropped_readings += 1
continue
fixed_reading = IOTileReading(assignment.rtc_value, reading.stream, reading.value,
reading_time=assignment.utc, reading_id=reading.reading_id)
fixed_readings.append(fixed_reading)
fixed_report = SignedListReport.FromReadings(report.origin, fixed_readings, report_id=report.report_id,
selector=report.streamer_selector, streamer=report.origin_streamer,
sent_timestamp=report.sent_timestamp)
fixed_report.received_time = report.received_time
if dropped_readings > 0:
self._logger.warning("Dropped %d readings of %d when fixing UTC timestamps in report 0x%08X for device 0x%08X",
dropped_readings, len(report.visible_readings), report.report_id, report.origin)
return fixed_report
|
[
"def",
"fix_report",
"(",
"self",
",",
"report",
",",
"errors",
"=",
"\"drop\"",
",",
"prefer",
"=",
"\"before\"",
")",
":",
"if",
"not",
"isinstance",
"(",
"report",
",",
"SignedListReport",
")",
":",
"raise",
"ArgumentError",
"(",
"\"Report must be a SignedListReport\"",
",",
"report",
"=",
"report",
")",
"if",
"errors",
"not",
"in",
"(",
"'drop'",
",",
")",
":",
"raise",
"ArgumentError",
"(",
"\"Unknown errors handler: {}, supported=['drop']\"",
".",
"format",
"(",
"errors",
")",
")",
"self",
".",
"ensure_prepared",
"(",
")",
"fixed_readings",
"=",
"[",
"]",
"dropped_readings",
"=",
"0",
"for",
"reading",
"in",
"report",
".",
"visible_readings",
":",
"assignment",
"=",
"self",
".",
"assign_utc",
"(",
"reading",
".",
"reading_id",
",",
"reading",
".",
"raw_time",
",",
"prefer",
"=",
"prefer",
")",
"if",
"assignment",
"is",
"None",
":",
"dropped_readings",
"+=",
"1",
"continue",
"fixed_reading",
"=",
"IOTileReading",
"(",
"assignment",
".",
"rtc_value",
",",
"reading",
".",
"stream",
",",
"reading",
".",
"value",
",",
"reading_time",
"=",
"assignment",
".",
"utc",
",",
"reading_id",
"=",
"reading",
".",
"reading_id",
")",
"fixed_readings",
".",
"append",
"(",
"fixed_reading",
")",
"fixed_report",
"=",
"SignedListReport",
".",
"FromReadings",
"(",
"report",
".",
"origin",
",",
"fixed_readings",
",",
"report_id",
"=",
"report",
".",
"report_id",
",",
"selector",
"=",
"report",
".",
"streamer_selector",
",",
"streamer",
"=",
"report",
".",
"origin_streamer",
",",
"sent_timestamp",
"=",
"report",
".",
"sent_timestamp",
")",
"fixed_report",
".",
"received_time",
"=",
"report",
".",
"received_time",
"if",
"dropped_readings",
">",
"0",
":",
"self",
".",
"_logger",
".",
"warning",
"(",
"\"Dropped %d readings of %d when fixing UTC timestamps in report 0x%08X for device 0x%08X\"",
",",
"dropped_readings",
",",
"len",
"(",
"report",
".",
"visible_readings",
")",
",",
"report",
".",
"report_id",
",",
"report",
".",
"origin",
")",
"return",
"fixed_report"
] |
Perform utc assignment on all readings in a report.
The returned report will have all reading timestamps in UTC. This only
works on SignedListReport objects. Note that the report should
typically have previously been added to the UTC assigner using
add_report or no reference points from the report will be used.
Args:
report (SignedListReport): The report that we should fix.
errors (str): The behavior that we should have when we can't
fix a given reading. The only currently support behavior is
drop, which means that the reading will be dropped and not
included in the new report.
prefer (str): Whether to prefer fixing readings by looking for
reference points after the reading or before, all other things
being equal. See the description of ``assign_utc``.
Returns:
SignedListReport: The report with UTC timestamps.
|
[
"Perform",
"utc",
"assignment",
"on",
"all",
"readings",
"in",
"a",
"report",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L318-L371
|
train
|
iotile/coretools
|
iotilecore/iotile/core/hw/reports/utc_assigner.py
|
UTCAssigner._fix_left
|
def _fix_left(self, reading_id, last, start, found_id):
"""Fix a reading by looking for the nearest anchor point before it."""
accum_delta = 0
exact = True
crossed_break = False
if start == 0:
return None
for curr in self._anchor_points.islice(None, start - 1, reverse=True):
if curr.uptime is None or last.uptime is None:
exact = False
elif curr.is_break or last.uptime < curr.uptime:
exact = False
crossed_break = True
else:
accum_delta += last.uptime - curr.uptime
if curr.utc is not None:
time_delta = datetime.timedelta(seconds=accum_delta)
return UTCAssignment(reading_id, curr.utc + time_delta, found_id, exact, crossed_break)
last = curr
return None
|
python
|
def _fix_left(self, reading_id, last, start, found_id):
"""Fix a reading by looking for the nearest anchor point before it."""
accum_delta = 0
exact = True
crossed_break = False
if start == 0:
return None
for curr in self._anchor_points.islice(None, start - 1, reverse=True):
if curr.uptime is None or last.uptime is None:
exact = False
elif curr.is_break or last.uptime < curr.uptime:
exact = False
crossed_break = True
else:
accum_delta += last.uptime - curr.uptime
if curr.utc is not None:
time_delta = datetime.timedelta(seconds=accum_delta)
return UTCAssignment(reading_id, curr.utc + time_delta, found_id, exact, crossed_break)
last = curr
return None
|
[
"def",
"_fix_left",
"(",
"self",
",",
"reading_id",
",",
"last",
",",
"start",
",",
"found_id",
")",
":",
"accum_delta",
"=",
"0",
"exact",
"=",
"True",
"crossed_break",
"=",
"False",
"if",
"start",
"==",
"0",
":",
"return",
"None",
"for",
"curr",
"in",
"self",
".",
"_anchor_points",
".",
"islice",
"(",
"None",
",",
"start",
"-",
"1",
",",
"reverse",
"=",
"True",
")",
":",
"if",
"curr",
".",
"uptime",
"is",
"None",
"or",
"last",
".",
"uptime",
"is",
"None",
":",
"exact",
"=",
"False",
"elif",
"curr",
".",
"is_break",
"or",
"last",
".",
"uptime",
"<",
"curr",
".",
"uptime",
":",
"exact",
"=",
"False",
"crossed_break",
"=",
"True",
"else",
":",
"accum_delta",
"+=",
"last",
".",
"uptime",
"-",
"curr",
".",
"uptime",
"if",
"curr",
".",
"utc",
"is",
"not",
"None",
":",
"time_delta",
"=",
"datetime",
".",
"timedelta",
"(",
"seconds",
"=",
"accum_delta",
")",
"return",
"UTCAssignment",
"(",
"reading_id",
",",
"curr",
".",
"utc",
"+",
"time_delta",
",",
"found_id",
",",
"exact",
",",
"crossed_break",
")",
"last",
"=",
"curr",
"return",
"None"
] |
Fix a reading by looking for the nearest anchor point before it.
|
[
"Fix",
"a",
"reading",
"by",
"looking",
"for",
"the",
"nearest",
"anchor",
"point",
"before",
"it",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilecore/iotile/core/hw/reports/utc_assigner.py#L427-L452
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
sconsign_dir
|
def sconsign_dir(node):
"""Return the .sconsign file info for this directory,
creating it first if necessary."""
if not node._sconsign:
import SCons.SConsign
node._sconsign = SCons.SConsign.ForDirectory(node)
return node._sconsign
|
python
|
def sconsign_dir(node):
"""Return the .sconsign file info for this directory,
creating it first if necessary."""
if not node._sconsign:
import SCons.SConsign
node._sconsign = SCons.SConsign.ForDirectory(node)
return node._sconsign
|
[
"def",
"sconsign_dir",
"(",
"node",
")",
":",
"if",
"not",
"node",
".",
"_sconsign",
":",
"import",
"SCons",
".",
"SConsign",
"node",
".",
"_sconsign",
"=",
"SCons",
".",
"SConsign",
".",
"ForDirectory",
"(",
"node",
")",
"return",
"node",
".",
"_sconsign"
] |
Return the .sconsign file info for this directory,
creating it first if necessary.
|
[
"Return",
"the",
".",
"sconsign",
"file",
"info",
"for",
"this",
"directory",
"creating",
"it",
"first",
"if",
"necessary",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L65-L71
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
EntryProxy.__get_base_path
|
def __get_base_path(self):
"""Return the file's directory and file name, with the
suffix stripped."""
entry = self.get()
return SCons.Subst.SpecialAttrWrapper(SCons.Util.splitext(entry.get_path())[0],
entry.name + "_base")
|
python
|
def __get_base_path(self):
"""Return the file's directory and file name, with the
suffix stripped."""
entry = self.get()
return SCons.Subst.SpecialAttrWrapper(SCons.Util.splitext(entry.get_path())[0],
entry.name + "_base")
|
[
"def",
"__get_base_path",
"(",
"self",
")",
":",
"entry",
"=",
"self",
".",
"get",
"(",
")",
"return",
"SCons",
".",
"Subst",
".",
"SpecialAttrWrapper",
"(",
"SCons",
".",
"Util",
".",
"splitext",
"(",
"entry",
".",
"get_path",
"(",
")",
")",
"[",
"0",
"]",
",",
"entry",
".",
"name",
"+",
"\"_base\"",
")"
] |
Return the file's directory and file name, with the
suffix stripped.
|
[
"Return",
"the",
"file",
"s",
"directory",
"and",
"file",
"name",
"with",
"the",
"suffix",
"stripped",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L447-L452
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
EntryProxy.__get_windows_path
|
def __get_windows_path(self):
"""Return the path with \ as the path separator,
regardless of platform."""
if OS_SEP == '\\':
return self
else:
entry = self.get()
r = entry.get_path().replace(OS_SEP, '\\')
return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_windows")
|
python
|
def __get_windows_path(self):
"""Return the path with \ as the path separator,
regardless of platform."""
if OS_SEP == '\\':
return self
else:
entry = self.get()
r = entry.get_path().replace(OS_SEP, '\\')
return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_windows")
|
[
"def",
"__get_windows_path",
"(",
"self",
")",
":",
"if",
"OS_SEP",
"==",
"'\\\\'",
":",
"return",
"self",
"else",
":",
"entry",
"=",
"self",
".",
"get",
"(",
")",
"r",
"=",
"entry",
".",
"get_path",
"(",
")",
".",
"replace",
"(",
"OS_SEP",
",",
"'\\\\'",
")",
"return",
"SCons",
".",
"Subst",
".",
"SpecialAttrWrapper",
"(",
"r",
",",
"entry",
".",
"name",
"+",
"\"_windows\"",
")"
] |
Return the path with \ as the path separator,
regardless of platform.
|
[
"Return",
"the",
"path",
"with",
"\\",
"as",
"the",
"path",
"separator",
"regardless",
"of",
"platform",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L464-L472
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Base.must_be_same
|
def must_be_same(self, klass):
"""
This node, which already existed, is being looked up as the
specified klass. Raise an exception if it isn't.
"""
if isinstance(self, klass) or klass is Entry:
return
raise TypeError("Tried to lookup %s '%s' as a %s." %\
(self.__class__.__name__, self.get_internal_path(), klass.__name__))
|
python
|
def must_be_same(self, klass):
"""
This node, which already existed, is being looked up as the
specified klass. Raise an exception if it isn't.
"""
if isinstance(self, klass) or klass is Entry:
return
raise TypeError("Tried to lookup %s '%s' as a %s." %\
(self.__class__.__name__, self.get_internal_path(), klass.__name__))
|
[
"def",
"must_be_same",
"(",
"self",
",",
"klass",
")",
":",
"if",
"isinstance",
"(",
"self",
",",
"klass",
")",
"or",
"klass",
"is",
"Entry",
":",
"return",
"raise",
"TypeError",
"(",
"\"Tried to lookup %s '%s' as a %s.\"",
"%",
"(",
"self",
".",
"__class__",
".",
"__name__",
",",
"self",
".",
"get_internal_path",
"(",
")",
",",
"klass",
".",
"__name__",
")",
")"
] |
This node, which already existed, is being looked up as the
specified klass. Raise an exception if it isn't.
|
[
"This",
"node",
"which",
"already",
"existed",
"is",
"being",
"looked",
"up",
"as",
"the",
"specified",
"klass",
".",
"Raise",
"an",
"exception",
"if",
"it",
"isn",
"t",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L593-L601
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Base.srcnode
|
def srcnode(self):
"""If this node is in a build path, return the node
corresponding to its source file. Otherwise, return
ourself.
"""
srcdir_list = self.dir.srcdir_list()
if srcdir_list:
srcnode = srcdir_list[0].Entry(self.name)
srcnode.must_be_same(self.__class__)
return srcnode
return self
|
python
|
def srcnode(self):
"""If this node is in a build path, return the node
corresponding to its source file. Otherwise, return
ourself.
"""
srcdir_list = self.dir.srcdir_list()
if srcdir_list:
srcnode = srcdir_list[0].Entry(self.name)
srcnode.must_be_same(self.__class__)
return srcnode
return self
|
[
"def",
"srcnode",
"(",
"self",
")",
":",
"srcdir_list",
"=",
"self",
".",
"dir",
".",
"srcdir_list",
"(",
")",
"if",
"srcdir_list",
":",
"srcnode",
"=",
"srcdir_list",
"[",
"0",
"]",
".",
"Entry",
"(",
"self",
".",
"name",
")",
"srcnode",
".",
"must_be_same",
"(",
"self",
".",
"__class__",
")",
"return",
"srcnode",
"return",
"self"
] |
If this node is in a build path, return the node
corresponding to its source file. Otherwise, return
ourself.
|
[
"If",
"this",
"node",
"is",
"in",
"a",
"build",
"path",
"return",
"the",
"node",
"corresponding",
"to",
"its",
"source",
"file",
".",
"Otherwise",
"return",
"ourself",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L733-L743
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Base.get_path
|
def get_path(self, dir=None):
"""Return path relative to the current working directory of the
Node.FS.Base object that owns us."""
if not dir:
dir = self.fs.getcwd()
if self == dir:
return '.'
path_elems = self.get_path_elements()
pathname = ''
try: i = path_elems.index(dir)
except ValueError:
for p in path_elems[:-1]:
pathname += p.dirname
else:
for p in path_elems[i+1:-1]:
pathname += p.dirname
return pathname + path_elems[-1].name
|
python
|
def get_path(self, dir=None):
"""Return path relative to the current working directory of the
Node.FS.Base object that owns us."""
if not dir:
dir = self.fs.getcwd()
if self == dir:
return '.'
path_elems = self.get_path_elements()
pathname = ''
try: i = path_elems.index(dir)
except ValueError:
for p in path_elems[:-1]:
pathname += p.dirname
else:
for p in path_elems[i+1:-1]:
pathname += p.dirname
return pathname + path_elems[-1].name
|
[
"def",
"get_path",
"(",
"self",
",",
"dir",
"=",
"None",
")",
":",
"if",
"not",
"dir",
":",
"dir",
"=",
"self",
".",
"fs",
".",
"getcwd",
"(",
")",
"if",
"self",
"==",
"dir",
":",
"return",
"'.'",
"path_elems",
"=",
"self",
".",
"get_path_elements",
"(",
")",
"pathname",
"=",
"''",
"try",
":",
"i",
"=",
"path_elems",
".",
"index",
"(",
"dir",
")",
"except",
"ValueError",
":",
"for",
"p",
"in",
"path_elems",
"[",
":",
"-",
"1",
"]",
":",
"pathname",
"+=",
"p",
".",
"dirname",
"else",
":",
"for",
"p",
"in",
"path_elems",
"[",
"i",
"+",
"1",
":",
"-",
"1",
"]",
":",
"pathname",
"+=",
"p",
".",
"dirname",
"return",
"pathname",
"+",
"path_elems",
"[",
"-",
"1",
"]",
".",
"name"
] |
Return path relative to the current working directory of the
Node.FS.Base object that owns us.
|
[
"Return",
"path",
"relative",
"to",
"the",
"current",
"working",
"directory",
"of",
"the",
"Node",
".",
"FS",
".",
"Base",
"object",
"that",
"owns",
"us",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L745-L761
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Base.set_src_builder
|
def set_src_builder(self, builder):
"""Set the source code builder for this node."""
self.sbuilder = builder
if not self.has_builder():
self.builder_set(builder)
|
python
|
def set_src_builder(self, builder):
"""Set the source code builder for this node."""
self.sbuilder = builder
if not self.has_builder():
self.builder_set(builder)
|
[
"def",
"set_src_builder",
"(",
"self",
",",
"builder",
")",
":",
"self",
".",
"sbuilder",
"=",
"builder",
"if",
"not",
"self",
".",
"has_builder",
"(",
")",
":",
"self",
".",
"builder_set",
"(",
"builder",
")"
] |
Set the source code builder for this node.
|
[
"Set",
"the",
"source",
"code",
"builder",
"for",
"this",
"node",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L763-L767
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Base.src_builder
|
def src_builder(self):
"""Fetch the source code builder for this node.
If there isn't one, we cache the source code builder specified
for the directory (which in turn will cache the value from its
parent directory, and so on up to the file system root).
"""
try:
scb = self.sbuilder
except AttributeError:
scb = self.dir.src_builder()
self.sbuilder = scb
return scb
|
python
|
def src_builder(self):
"""Fetch the source code builder for this node.
If there isn't one, we cache the source code builder specified
for the directory (which in turn will cache the value from its
parent directory, and so on up to the file system root).
"""
try:
scb = self.sbuilder
except AttributeError:
scb = self.dir.src_builder()
self.sbuilder = scb
return scb
|
[
"def",
"src_builder",
"(",
"self",
")",
":",
"try",
":",
"scb",
"=",
"self",
".",
"sbuilder",
"except",
"AttributeError",
":",
"scb",
"=",
"self",
".",
"dir",
".",
"src_builder",
"(",
")",
"self",
".",
"sbuilder",
"=",
"scb",
"return",
"scb"
] |
Fetch the source code builder for this node.
If there isn't one, we cache the source code builder specified
for the directory (which in turn will cache the value from its
parent directory, and so on up to the file system root).
|
[
"Fetch",
"the",
"source",
"code",
"builder",
"for",
"this",
"node",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L769-L781
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Base.Rfindalldirs
|
def Rfindalldirs(self, pathlist):
"""
Return all of the directories for a given path list, including
corresponding "backing" directories in any repositories.
The Node lookups are relative to this Node (typically a
directory), so memoizing result saves cycles from looking
up the same path for each target in a given directory.
"""
try:
memo_dict = self._memo['Rfindalldirs']
except KeyError:
memo_dict = {}
self._memo['Rfindalldirs'] = memo_dict
else:
try:
return memo_dict[pathlist]
except KeyError:
pass
create_dir_relative_to_self = self.Dir
result = []
for path in pathlist:
if isinstance(path, SCons.Node.Node):
result.append(path)
else:
dir = create_dir_relative_to_self(path)
result.extend(dir.get_all_rdirs())
memo_dict[pathlist] = result
return result
|
python
|
def Rfindalldirs(self, pathlist):
"""
Return all of the directories for a given path list, including
corresponding "backing" directories in any repositories.
The Node lookups are relative to this Node (typically a
directory), so memoizing result saves cycles from looking
up the same path for each target in a given directory.
"""
try:
memo_dict = self._memo['Rfindalldirs']
except KeyError:
memo_dict = {}
self._memo['Rfindalldirs'] = memo_dict
else:
try:
return memo_dict[pathlist]
except KeyError:
pass
create_dir_relative_to_self = self.Dir
result = []
for path in pathlist:
if isinstance(path, SCons.Node.Node):
result.append(path)
else:
dir = create_dir_relative_to_self(path)
result.extend(dir.get_all_rdirs())
memo_dict[pathlist] = result
return result
|
[
"def",
"Rfindalldirs",
"(",
"self",
",",
"pathlist",
")",
":",
"try",
":",
"memo_dict",
"=",
"self",
".",
"_memo",
"[",
"'Rfindalldirs'",
"]",
"except",
"KeyError",
":",
"memo_dict",
"=",
"{",
"}",
"self",
".",
"_memo",
"[",
"'Rfindalldirs'",
"]",
"=",
"memo_dict",
"else",
":",
"try",
":",
"return",
"memo_dict",
"[",
"pathlist",
"]",
"except",
"KeyError",
":",
"pass",
"create_dir_relative_to_self",
"=",
"self",
".",
"Dir",
"result",
"=",
"[",
"]",
"for",
"path",
"in",
"pathlist",
":",
"if",
"isinstance",
"(",
"path",
",",
"SCons",
".",
"Node",
".",
"Node",
")",
":",
"result",
".",
"append",
"(",
"path",
")",
"else",
":",
"dir",
"=",
"create_dir_relative_to_self",
"(",
"path",
")",
"result",
".",
"extend",
"(",
"dir",
".",
"get_all_rdirs",
"(",
")",
")",
"memo_dict",
"[",
"pathlist",
"]",
"=",
"result",
"return",
"result"
] |
Return all of the directories for a given path list, including
corresponding "backing" directories in any repositories.
The Node lookups are relative to this Node (typically a
directory), so memoizing result saves cycles from looking
up the same path for each target in a given directory.
|
[
"Return",
"all",
"of",
"the",
"directories",
"for",
"a",
"given",
"path",
"list",
"including",
"corresponding",
"backing",
"directories",
"in",
"any",
"repositories",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L836-L867
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Base.RDirs
|
def RDirs(self, pathlist):
"""Search for a list of directories in the Repository list."""
cwd = self.cwd or self.fs._cwd
return cwd.Rfindalldirs(pathlist)
|
python
|
def RDirs(self, pathlist):
"""Search for a list of directories in the Repository list."""
cwd = self.cwd or self.fs._cwd
return cwd.Rfindalldirs(pathlist)
|
[
"def",
"RDirs",
"(",
"self",
",",
"pathlist",
")",
":",
"cwd",
"=",
"self",
".",
"cwd",
"or",
"self",
".",
"fs",
".",
"_cwd",
"return",
"cwd",
".",
"Rfindalldirs",
"(",
"pathlist",
")"
] |
Search for a list of directories in the Repository list.
|
[
"Search",
"for",
"a",
"list",
"of",
"directories",
"in",
"the",
"Repository",
"list",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L869-L872
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Entry.rfile
|
def rfile(self):
"""We're a generic Entry, but the caller is actually looking for
a File at this point, so morph into one."""
self.__class__ = File
self._morph()
self.clear()
return File.rfile(self)
|
python
|
def rfile(self):
"""We're a generic Entry, but the caller is actually looking for
a File at this point, so morph into one."""
self.__class__ = File
self._morph()
self.clear()
return File.rfile(self)
|
[
"def",
"rfile",
"(",
"self",
")",
":",
"self",
".",
"__class__",
"=",
"File",
"self",
".",
"_morph",
"(",
")",
"self",
".",
"clear",
"(",
")",
"return",
"File",
".",
"rfile",
"(",
"self",
")"
] |
We're a generic Entry, but the caller is actually looking for
a File at this point, so morph into one.
|
[
"We",
"re",
"a",
"generic",
"Entry",
"but",
"the",
"caller",
"is",
"actually",
"looking",
"for",
"a",
"File",
"at",
"this",
"point",
"so",
"morph",
"into",
"one",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L973-L979
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Entry.get_text_contents
|
def get_text_contents(self):
"""Fetch the decoded text contents of a Unicode encoded Entry.
Since this should return the text contents from the file
system, we check to see into what sort of subclass we should
morph this Entry."""
try:
self = self.disambiguate(must_exist=1)
except SCons.Errors.UserError:
# There was nothing on disk with which to disambiguate
# this entry. Leave it as an Entry, but return a null
# string so calls to get_text_contents() in emitters and
# the like (e.g. in qt.py) don't have to disambiguate by
# hand or catch the exception.
return ''
else:
return self.get_text_contents()
|
python
|
def get_text_contents(self):
"""Fetch the decoded text contents of a Unicode encoded Entry.
Since this should return the text contents from the file
system, we check to see into what sort of subclass we should
morph this Entry."""
try:
self = self.disambiguate(must_exist=1)
except SCons.Errors.UserError:
# There was nothing on disk with which to disambiguate
# this entry. Leave it as an Entry, but return a null
# string so calls to get_text_contents() in emitters and
# the like (e.g. in qt.py) don't have to disambiguate by
# hand or catch the exception.
return ''
else:
return self.get_text_contents()
|
[
"def",
"get_text_contents",
"(",
"self",
")",
":",
"try",
":",
"self",
"=",
"self",
".",
"disambiguate",
"(",
"must_exist",
"=",
"1",
")",
"except",
"SCons",
".",
"Errors",
".",
"UserError",
":",
"# There was nothing on disk with which to disambiguate",
"# this entry. Leave it as an Entry, but return a null",
"# string so calls to get_text_contents() in emitters and",
"# the like (e.g. in qt.py) don't have to disambiguate by",
"# hand or catch the exception.",
"return",
"''",
"else",
":",
"return",
"self",
".",
"get_text_contents",
"(",
")"
] |
Fetch the decoded text contents of a Unicode encoded Entry.
Since this should return the text contents from the file
system, we check to see into what sort of subclass we should
morph this Entry.
|
[
"Fetch",
"the",
"decoded",
"text",
"contents",
"of",
"a",
"Unicode",
"encoded",
"Entry",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L989-L1005
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Entry.must_be_same
|
def must_be_same(self, klass):
"""Called to make sure a Node is a Dir. Since we're an
Entry, we can morph into one."""
if self.__class__ is not klass:
self.__class__ = klass
self._morph()
self.clear()
|
python
|
def must_be_same(self, klass):
"""Called to make sure a Node is a Dir. Since we're an
Entry, we can morph into one."""
if self.__class__ is not klass:
self.__class__ = klass
self._morph()
self.clear()
|
[
"def",
"must_be_same",
"(",
"self",
",",
"klass",
")",
":",
"if",
"self",
".",
"__class__",
"is",
"not",
"klass",
":",
"self",
".",
"__class__",
"=",
"klass",
"self",
".",
"_morph",
"(",
")",
"self",
".",
"clear",
"(",
")"
] |
Called to make sure a Node is a Dir. Since we're an
Entry, we can morph into one.
|
[
"Called",
"to",
"make",
"sure",
"a",
"Node",
"is",
"a",
"Dir",
".",
"Since",
"we",
"re",
"an",
"Entry",
"we",
"can",
"morph",
"into",
"one",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1007-L1013
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FS.chdir
|
def chdir(self, dir, change_os_dir=0):
"""Change the current working directory for lookups.
If change_os_dir is true, we will also change the "real" cwd
to match.
"""
curr=self._cwd
try:
if dir is not None:
self._cwd = dir
if change_os_dir:
os.chdir(dir.get_abspath())
except OSError:
self._cwd = curr
raise
|
python
|
def chdir(self, dir, change_os_dir=0):
"""Change the current working directory for lookups.
If change_os_dir is true, we will also change the "real" cwd
to match.
"""
curr=self._cwd
try:
if dir is not None:
self._cwd = dir
if change_os_dir:
os.chdir(dir.get_abspath())
except OSError:
self._cwd = curr
raise
|
[
"def",
"chdir",
"(",
"self",
",",
"dir",
",",
"change_os_dir",
"=",
"0",
")",
":",
"curr",
"=",
"self",
".",
"_cwd",
"try",
":",
"if",
"dir",
"is",
"not",
"None",
":",
"self",
".",
"_cwd",
"=",
"dir",
"if",
"change_os_dir",
":",
"os",
".",
"chdir",
"(",
"dir",
".",
"get_abspath",
"(",
")",
")",
"except",
"OSError",
":",
"self",
".",
"_cwd",
"=",
"curr",
"raise"
] |
Change the current working directory for lookups.
If change_os_dir is true, we will also change the "real" cwd
to match.
|
[
"Change",
"the",
"current",
"working",
"directory",
"for",
"lookups",
".",
"If",
"change_os_dir",
"is",
"true",
"we",
"will",
"also",
"change",
"the",
"real",
"cwd",
"to",
"match",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1168-L1181
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FS.get_root
|
def get_root(self, drive):
"""
Returns the root directory for the specified drive, creating
it if necessary.
"""
drive = _my_normcase(drive)
try:
return self.Root[drive]
except KeyError:
root = RootDir(drive, self)
self.Root[drive] = root
if not drive:
self.Root[self.defaultDrive] = root
elif drive == self.defaultDrive:
self.Root[''] = root
return root
|
python
|
def get_root(self, drive):
"""
Returns the root directory for the specified drive, creating
it if necessary.
"""
drive = _my_normcase(drive)
try:
return self.Root[drive]
except KeyError:
root = RootDir(drive, self)
self.Root[drive] = root
if not drive:
self.Root[self.defaultDrive] = root
elif drive == self.defaultDrive:
self.Root[''] = root
return root
|
[
"def",
"get_root",
"(",
"self",
",",
"drive",
")",
":",
"drive",
"=",
"_my_normcase",
"(",
"drive",
")",
"try",
":",
"return",
"self",
".",
"Root",
"[",
"drive",
"]",
"except",
"KeyError",
":",
"root",
"=",
"RootDir",
"(",
"drive",
",",
"self",
")",
"self",
".",
"Root",
"[",
"drive",
"]",
"=",
"root",
"if",
"not",
"drive",
":",
"self",
".",
"Root",
"[",
"self",
".",
"defaultDrive",
"]",
"=",
"root",
"elif",
"drive",
"==",
"self",
".",
"defaultDrive",
":",
"self",
".",
"Root",
"[",
"''",
"]",
"=",
"root",
"return",
"root"
] |
Returns the root directory for the specified drive, creating
it if necessary.
|
[
"Returns",
"the",
"root",
"directory",
"for",
"the",
"specified",
"drive",
"creating",
"it",
"if",
"necessary",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1183-L1198
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FS._lookup
|
def _lookup(self, p, directory, fsclass, create=1):
"""
The generic entry point for Node lookup with user-supplied data.
This translates arbitrary input into a canonical Node.FS object
of the specified fsclass. The general approach for strings is
to turn it into a fully normalized absolute path and then call
the root directory's lookup_abs() method for the heavy lifting.
If the path name begins with '#', it is unconditionally
interpreted relative to the top-level directory of this FS. '#'
is treated as a synonym for the top-level SConstruct directory,
much like '~' is treated as a synonym for the user's home
directory in a UNIX shell. So both '#foo' and '#/foo' refer
to the 'foo' subdirectory underneath the top-level SConstruct
directory.
If the path name is relative, then the path is looked up relative
to the specified directory, or the current directory (self._cwd,
typically the SConscript directory) if the specified directory
is None.
"""
if isinstance(p, Base):
# It's already a Node.FS object. Make sure it's the right
# class and return.
p.must_be_same(fsclass)
return p
# str(p) in case it's something like a proxy object
p = str(p)
if not os_sep_is_slash:
p = p.replace(OS_SEP, '/')
if p[0:1] == '#':
# There was an initial '#', so we strip it and override
# whatever directory they may have specified with the
# top-level SConstruct directory.
p = p[1:]
directory = self.Top
# There might be a drive letter following the
# '#'. Although it is not described in the SCons man page,
# the regression test suite explicitly tests for that
# syntax. It seems to mean the following thing:
#
# Assuming the the SCons top dir is in C:/xxx/yyy,
# '#X:/toto' means X:/xxx/yyy/toto.
#
# i.e. it assumes that the X: drive has a directory
# structure similar to the one found on drive C:.
if do_splitdrive:
drive, p = _my_splitdrive(p)
if drive:
root = self.get_root(drive)
else:
root = directory.root
else:
root = directory.root
# We can only strip trailing after splitting the drive
# since the drive might the UNC '//' prefix.
p = p.strip('/')
needs_normpath = needs_normpath_match(p)
# The path is relative to the top-level SCons directory.
if p in ('', '.'):
p = directory.get_labspath()
else:
p = directory.get_labspath() + '/' + p
else:
if do_splitdrive:
drive, p = _my_splitdrive(p)
if drive and not p:
# This causes a naked drive letter to be treated
# as a synonym for the root directory on that
# drive.
p = '/'
else:
drive = ''
# We can only strip trailing '/' since the drive might the
# UNC '//' prefix.
if p != '/':
p = p.rstrip('/')
needs_normpath = needs_normpath_match(p)
if p[0:1] == '/':
# Absolute path
root = self.get_root(drive)
else:
# This is a relative lookup or to the current directory
# (the path name is not absolute). Add the string to the
# appropriate directory lookup path, after which the whole
# thing gets normalized.
if directory:
if not isinstance(directory, Dir):
directory = self.Dir(directory)
else:
directory = self._cwd
if p in ('', '.'):
p = directory.get_labspath()
else:
p = directory.get_labspath() + '/' + p
if drive:
root = self.get_root(drive)
else:
root = directory.root
if needs_normpath is not None:
# Normalize a pathname. Will return the same result for
# equivalent paths.
#
# We take advantage of the fact that we have an absolute
# path here for sure. In addition, we know that the
# components of lookup path are separated by slashes at
# this point. Because of this, this code is about 2X
# faster than calling os.path.normpath() followed by
# replacing os.sep with '/' again.
ins = p.split('/')[1:]
outs = []
for d in ins:
if d == '..':
try:
outs.pop()
except IndexError:
pass
elif d not in ('', '.'):
outs.append(d)
p = '/' + '/'.join(outs)
return root._lookup_abs(p, fsclass, create)
|
python
|
def _lookup(self, p, directory, fsclass, create=1):
"""
The generic entry point for Node lookup with user-supplied data.
This translates arbitrary input into a canonical Node.FS object
of the specified fsclass. The general approach for strings is
to turn it into a fully normalized absolute path and then call
the root directory's lookup_abs() method for the heavy lifting.
If the path name begins with '#', it is unconditionally
interpreted relative to the top-level directory of this FS. '#'
is treated as a synonym for the top-level SConstruct directory,
much like '~' is treated as a synonym for the user's home
directory in a UNIX shell. So both '#foo' and '#/foo' refer
to the 'foo' subdirectory underneath the top-level SConstruct
directory.
If the path name is relative, then the path is looked up relative
to the specified directory, or the current directory (self._cwd,
typically the SConscript directory) if the specified directory
is None.
"""
if isinstance(p, Base):
# It's already a Node.FS object. Make sure it's the right
# class and return.
p.must_be_same(fsclass)
return p
# str(p) in case it's something like a proxy object
p = str(p)
if not os_sep_is_slash:
p = p.replace(OS_SEP, '/')
if p[0:1] == '#':
# There was an initial '#', so we strip it and override
# whatever directory they may have specified with the
# top-level SConstruct directory.
p = p[1:]
directory = self.Top
# There might be a drive letter following the
# '#'. Although it is not described in the SCons man page,
# the regression test suite explicitly tests for that
# syntax. It seems to mean the following thing:
#
# Assuming the the SCons top dir is in C:/xxx/yyy,
# '#X:/toto' means X:/xxx/yyy/toto.
#
# i.e. it assumes that the X: drive has a directory
# structure similar to the one found on drive C:.
if do_splitdrive:
drive, p = _my_splitdrive(p)
if drive:
root = self.get_root(drive)
else:
root = directory.root
else:
root = directory.root
# We can only strip trailing after splitting the drive
# since the drive might the UNC '//' prefix.
p = p.strip('/')
needs_normpath = needs_normpath_match(p)
# The path is relative to the top-level SCons directory.
if p in ('', '.'):
p = directory.get_labspath()
else:
p = directory.get_labspath() + '/' + p
else:
if do_splitdrive:
drive, p = _my_splitdrive(p)
if drive and not p:
# This causes a naked drive letter to be treated
# as a synonym for the root directory on that
# drive.
p = '/'
else:
drive = ''
# We can only strip trailing '/' since the drive might the
# UNC '//' prefix.
if p != '/':
p = p.rstrip('/')
needs_normpath = needs_normpath_match(p)
if p[0:1] == '/':
# Absolute path
root = self.get_root(drive)
else:
# This is a relative lookup or to the current directory
# (the path name is not absolute). Add the string to the
# appropriate directory lookup path, after which the whole
# thing gets normalized.
if directory:
if not isinstance(directory, Dir):
directory = self.Dir(directory)
else:
directory = self._cwd
if p in ('', '.'):
p = directory.get_labspath()
else:
p = directory.get_labspath() + '/' + p
if drive:
root = self.get_root(drive)
else:
root = directory.root
if needs_normpath is not None:
# Normalize a pathname. Will return the same result for
# equivalent paths.
#
# We take advantage of the fact that we have an absolute
# path here for sure. In addition, we know that the
# components of lookup path are separated by slashes at
# this point. Because of this, this code is about 2X
# faster than calling os.path.normpath() followed by
# replacing os.sep with '/' again.
ins = p.split('/')[1:]
outs = []
for d in ins:
if d == '..':
try:
outs.pop()
except IndexError:
pass
elif d not in ('', '.'):
outs.append(d)
p = '/' + '/'.join(outs)
return root._lookup_abs(p, fsclass, create)
|
[
"def",
"_lookup",
"(",
"self",
",",
"p",
",",
"directory",
",",
"fsclass",
",",
"create",
"=",
"1",
")",
":",
"if",
"isinstance",
"(",
"p",
",",
"Base",
")",
":",
"# It's already a Node.FS object. Make sure it's the right",
"# class and return.",
"p",
".",
"must_be_same",
"(",
"fsclass",
")",
"return",
"p",
"# str(p) in case it's something like a proxy object",
"p",
"=",
"str",
"(",
"p",
")",
"if",
"not",
"os_sep_is_slash",
":",
"p",
"=",
"p",
".",
"replace",
"(",
"OS_SEP",
",",
"'/'",
")",
"if",
"p",
"[",
"0",
":",
"1",
"]",
"==",
"'#'",
":",
"# There was an initial '#', so we strip it and override",
"# whatever directory they may have specified with the",
"# top-level SConstruct directory.",
"p",
"=",
"p",
"[",
"1",
":",
"]",
"directory",
"=",
"self",
".",
"Top",
"# There might be a drive letter following the",
"# '#'. Although it is not described in the SCons man page,",
"# the regression test suite explicitly tests for that",
"# syntax. It seems to mean the following thing:",
"#",
"# Assuming the the SCons top dir is in C:/xxx/yyy,",
"# '#X:/toto' means X:/xxx/yyy/toto.",
"#",
"# i.e. it assumes that the X: drive has a directory",
"# structure similar to the one found on drive C:.",
"if",
"do_splitdrive",
":",
"drive",
",",
"p",
"=",
"_my_splitdrive",
"(",
"p",
")",
"if",
"drive",
":",
"root",
"=",
"self",
".",
"get_root",
"(",
"drive",
")",
"else",
":",
"root",
"=",
"directory",
".",
"root",
"else",
":",
"root",
"=",
"directory",
".",
"root",
"# We can only strip trailing after splitting the drive",
"# since the drive might the UNC '//' prefix.",
"p",
"=",
"p",
".",
"strip",
"(",
"'/'",
")",
"needs_normpath",
"=",
"needs_normpath_match",
"(",
"p",
")",
"# The path is relative to the top-level SCons directory.",
"if",
"p",
"in",
"(",
"''",
",",
"'.'",
")",
":",
"p",
"=",
"directory",
".",
"get_labspath",
"(",
")",
"else",
":",
"p",
"=",
"directory",
".",
"get_labspath",
"(",
")",
"+",
"'/'",
"+",
"p",
"else",
":",
"if",
"do_splitdrive",
":",
"drive",
",",
"p",
"=",
"_my_splitdrive",
"(",
"p",
")",
"if",
"drive",
"and",
"not",
"p",
":",
"# This causes a naked drive letter to be treated",
"# as a synonym for the root directory on that",
"# drive.",
"p",
"=",
"'/'",
"else",
":",
"drive",
"=",
"''",
"# We can only strip trailing '/' since the drive might the",
"# UNC '//' prefix.",
"if",
"p",
"!=",
"'/'",
":",
"p",
"=",
"p",
".",
"rstrip",
"(",
"'/'",
")",
"needs_normpath",
"=",
"needs_normpath_match",
"(",
"p",
")",
"if",
"p",
"[",
"0",
":",
"1",
"]",
"==",
"'/'",
":",
"# Absolute path",
"root",
"=",
"self",
".",
"get_root",
"(",
"drive",
")",
"else",
":",
"# This is a relative lookup or to the current directory",
"# (the path name is not absolute). Add the string to the",
"# appropriate directory lookup path, after which the whole",
"# thing gets normalized.",
"if",
"directory",
":",
"if",
"not",
"isinstance",
"(",
"directory",
",",
"Dir",
")",
":",
"directory",
"=",
"self",
".",
"Dir",
"(",
"directory",
")",
"else",
":",
"directory",
"=",
"self",
".",
"_cwd",
"if",
"p",
"in",
"(",
"''",
",",
"'.'",
")",
":",
"p",
"=",
"directory",
".",
"get_labspath",
"(",
")",
"else",
":",
"p",
"=",
"directory",
".",
"get_labspath",
"(",
")",
"+",
"'/'",
"+",
"p",
"if",
"drive",
":",
"root",
"=",
"self",
".",
"get_root",
"(",
"drive",
")",
"else",
":",
"root",
"=",
"directory",
".",
"root",
"if",
"needs_normpath",
"is",
"not",
"None",
":",
"# Normalize a pathname. Will return the same result for",
"# equivalent paths.",
"#",
"# We take advantage of the fact that we have an absolute",
"# path here for sure. In addition, we know that the",
"# components of lookup path are separated by slashes at",
"# this point. Because of this, this code is about 2X",
"# faster than calling os.path.normpath() followed by",
"# replacing os.sep with '/' again.",
"ins",
"=",
"p",
".",
"split",
"(",
"'/'",
")",
"[",
"1",
":",
"]",
"outs",
"=",
"[",
"]",
"for",
"d",
"in",
"ins",
":",
"if",
"d",
"==",
"'..'",
":",
"try",
":",
"outs",
".",
"pop",
"(",
")",
"except",
"IndexError",
":",
"pass",
"elif",
"d",
"not",
"in",
"(",
"''",
",",
"'.'",
")",
":",
"outs",
".",
"append",
"(",
"d",
")",
"p",
"=",
"'/'",
"+",
"'/'",
".",
"join",
"(",
"outs",
")",
"return",
"root",
".",
"_lookup_abs",
"(",
"p",
",",
"fsclass",
",",
"create",
")"
] |
The generic entry point for Node lookup with user-supplied data.
This translates arbitrary input into a canonical Node.FS object
of the specified fsclass. The general approach for strings is
to turn it into a fully normalized absolute path and then call
the root directory's lookup_abs() method for the heavy lifting.
If the path name begins with '#', it is unconditionally
interpreted relative to the top-level directory of this FS. '#'
is treated as a synonym for the top-level SConstruct directory,
much like '~' is treated as a synonym for the user's home
directory in a UNIX shell. So both '#foo' and '#/foo' refer
to the 'foo' subdirectory underneath the top-level SConstruct
directory.
If the path name is relative, then the path is looked up relative
to the specified directory, or the current directory (self._cwd,
typically the SConscript directory) if the specified directory
is None.
|
[
"The",
"generic",
"entry",
"point",
"for",
"Node",
"lookup",
"with",
"user",
"-",
"supplied",
"data",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1200-L1334
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FS.VariantDir
|
def VariantDir(self, variant_dir, src_dir, duplicate=1):
"""Link the supplied variant directory to the source directory
for purposes of building files."""
if not isinstance(src_dir, SCons.Node.Node):
src_dir = self.Dir(src_dir)
if not isinstance(variant_dir, SCons.Node.Node):
variant_dir = self.Dir(variant_dir)
if src_dir.is_under(variant_dir):
raise SCons.Errors.UserError("Source directory cannot be under variant directory.")
if variant_dir.srcdir:
if variant_dir.srcdir == src_dir:
return # We already did this.
raise SCons.Errors.UserError("'%s' already has a source directory: '%s'."%(variant_dir, variant_dir.srcdir))
variant_dir.link(src_dir, duplicate)
|
python
|
def VariantDir(self, variant_dir, src_dir, duplicate=1):
"""Link the supplied variant directory to the source directory
for purposes of building files."""
if not isinstance(src_dir, SCons.Node.Node):
src_dir = self.Dir(src_dir)
if not isinstance(variant_dir, SCons.Node.Node):
variant_dir = self.Dir(variant_dir)
if src_dir.is_under(variant_dir):
raise SCons.Errors.UserError("Source directory cannot be under variant directory.")
if variant_dir.srcdir:
if variant_dir.srcdir == src_dir:
return # We already did this.
raise SCons.Errors.UserError("'%s' already has a source directory: '%s'."%(variant_dir, variant_dir.srcdir))
variant_dir.link(src_dir, duplicate)
|
[
"def",
"VariantDir",
"(",
"self",
",",
"variant_dir",
",",
"src_dir",
",",
"duplicate",
"=",
"1",
")",
":",
"if",
"not",
"isinstance",
"(",
"src_dir",
",",
"SCons",
".",
"Node",
".",
"Node",
")",
":",
"src_dir",
"=",
"self",
".",
"Dir",
"(",
"src_dir",
")",
"if",
"not",
"isinstance",
"(",
"variant_dir",
",",
"SCons",
".",
"Node",
".",
"Node",
")",
":",
"variant_dir",
"=",
"self",
".",
"Dir",
"(",
"variant_dir",
")",
"if",
"src_dir",
".",
"is_under",
"(",
"variant_dir",
")",
":",
"raise",
"SCons",
".",
"Errors",
".",
"UserError",
"(",
"\"Source directory cannot be under variant directory.\"",
")",
"if",
"variant_dir",
".",
"srcdir",
":",
"if",
"variant_dir",
".",
"srcdir",
"==",
"src_dir",
":",
"return",
"# We already did this.",
"raise",
"SCons",
".",
"Errors",
".",
"UserError",
"(",
"\"'%s' already has a source directory: '%s'.\"",
"%",
"(",
"variant_dir",
",",
"variant_dir",
".",
"srcdir",
")",
")",
"variant_dir",
".",
"link",
"(",
"src_dir",
",",
"duplicate",
")"
] |
Link the supplied variant directory to the source directory
for purposes of building files.
|
[
"Link",
"the",
"supplied",
"variant",
"directory",
"to",
"the",
"source",
"directory",
"for",
"purposes",
"of",
"building",
"files",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1369-L1383
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FS.Repository
|
def Repository(self, *dirs):
"""Specify Repository directories to search."""
for d in dirs:
if not isinstance(d, SCons.Node.Node):
d = self.Dir(d)
self.Top.addRepository(d)
|
python
|
def Repository(self, *dirs):
"""Specify Repository directories to search."""
for d in dirs:
if not isinstance(d, SCons.Node.Node):
d = self.Dir(d)
self.Top.addRepository(d)
|
[
"def",
"Repository",
"(",
"self",
",",
"*",
"dirs",
")",
":",
"for",
"d",
"in",
"dirs",
":",
"if",
"not",
"isinstance",
"(",
"d",
",",
"SCons",
".",
"Node",
".",
"Node",
")",
":",
"d",
"=",
"self",
".",
"Dir",
"(",
"d",
")",
"self",
".",
"Top",
".",
"addRepository",
"(",
"d",
")"
] |
Specify Repository directories to search.
|
[
"Specify",
"Repository",
"directories",
"to",
"search",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1385-L1390
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FS.variant_dir_target_climb
|
def variant_dir_target_climb(self, orig, dir, tail):
"""Create targets in corresponding variant directories
Climb the directory tree, and look up path names
relative to any linked variant directories we find.
Even though this loops and walks up the tree, we don't memoize
the return value because this is really only used to process
the command-line targets.
"""
targets = []
message = None
fmt = "building associated VariantDir targets: %s"
start_dir = dir
while dir:
for bd in dir.variant_dirs:
if start_dir.is_under(bd):
# If already in the build-dir location, don't reflect
return [orig], fmt % str(orig)
p = os.path.join(bd._path, *tail)
targets.append(self.Entry(p))
tail = [dir.name] + tail
dir = dir.up()
if targets:
message = fmt % ' '.join(map(str, targets))
return targets, message
|
python
|
def variant_dir_target_climb(self, orig, dir, tail):
"""Create targets in corresponding variant directories
Climb the directory tree, and look up path names
relative to any linked variant directories we find.
Even though this loops and walks up the tree, we don't memoize
the return value because this is really only used to process
the command-line targets.
"""
targets = []
message = None
fmt = "building associated VariantDir targets: %s"
start_dir = dir
while dir:
for bd in dir.variant_dirs:
if start_dir.is_under(bd):
# If already in the build-dir location, don't reflect
return [orig], fmt % str(orig)
p = os.path.join(bd._path, *tail)
targets.append(self.Entry(p))
tail = [dir.name] + tail
dir = dir.up()
if targets:
message = fmt % ' '.join(map(str, targets))
return targets, message
|
[
"def",
"variant_dir_target_climb",
"(",
"self",
",",
"orig",
",",
"dir",
",",
"tail",
")",
":",
"targets",
"=",
"[",
"]",
"message",
"=",
"None",
"fmt",
"=",
"\"building associated VariantDir targets: %s\"",
"start_dir",
"=",
"dir",
"while",
"dir",
":",
"for",
"bd",
"in",
"dir",
".",
"variant_dirs",
":",
"if",
"start_dir",
".",
"is_under",
"(",
"bd",
")",
":",
"# If already in the build-dir location, don't reflect",
"return",
"[",
"orig",
"]",
",",
"fmt",
"%",
"str",
"(",
"orig",
")",
"p",
"=",
"os",
".",
"path",
".",
"join",
"(",
"bd",
".",
"_path",
",",
"*",
"tail",
")",
"targets",
".",
"append",
"(",
"self",
".",
"Entry",
"(",
"p",
")",
")",
"tail",
"=",
"[",
"dir",
".",
"name",
"]",
"+",
"tail",
"dir",
"=",
"dir",
".",
"up",
"(",
")",
"if",
"targets",
":",
"message",
"=",
"fmt",
"%",
"' '",
".",
"join",
"(",
"map",
"(",
"str",
",",
"targets",
")",
")",
"return",
"targets",
",",
"message"
] |
Create targets in corresponding variant directories
Climb the directory tree, and look up path names
relative to any linked variant directories we find.
Even though this loops and walks up the tree, we don't memoize
the return value because this is really only used to process
the command-line targets.
|
[
"Create",
"targets",
"in",
"corresponding",
"variant",
"directories"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1421-L1446
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.Dir
|
def Dir(self, name, create=True):
"""
Looks up or creates a directory node named 'name' relative to
this directory.
"""
return self.fs.Dir(name, self, create)
|
python
|
def Dir(self, name, create=True):
"""
Looks up or creates a directory node named 'name' relative to
this directory.
"""
return self.fs.Dir(name, self, create)
|
[
"def",
"Dir",
"(",
"self",
",",
"name",
",",
"create",
"=",
"True",
")",
":",
"return",
"self",
".",
"fs",
".",
"Dir",
"(",
"name",
",",
"self",
",",
"create",
")"
] |
Looks up or creates a directory node named 'name' relative to
this directory.
|
[
"Looks",
"up",
"or",
"creates",
"a",
"directory",
"node",
"named",
"name",
"relative",
"to",
"this",
"directory",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1611-L1616
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.link
|
def link(self, srcdir, duplicate):
"""Set this directory as the variant directory for the
supplied source directory."""
self.srcdir = srcdir
self.duplicate = duplicate
self.__clearRepositoryCache(duplicate)
srcdir.variant_dirs.append(self)
|
python
|
def link(self, srcdir, duplicate):
"""Set this directory as the variant directory for the
supplied source directory."""
self.srcdir = srcdir
self.duplicate = duplicate
self.__clearRepositoryCache(duplicate)
srcdir.variant_dirs.append(self)
|
[
"def",
"link",
"(",
"self",
",",
"srcdir",
",",
"duplicate",
")",
":",
"self",
".",
"srcdir",
"=",
"srcdir",
"self",
".",
"duplicate",
"=",
"duplicate",
"self",
".",
"__clearRepositoryCache",
"(",
"duplicate",
")",
"srcdir",
".",
"variant_dirs",
".",
"append",
"(",
"self",
")"
] |
Set this directory as the variant directory for the
supplied source directory.
|
[
"Set",
"this",
"directory",
"as",
"the",
"variant",
"directory",
"for",
"the",
"supplied",
"source",
"directory",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1625-L1631
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.getRepositories
|
def getRepositories(self):
"""Returns a list of repositories for this directory.
"""
if self.srcdir and not self.duplicate:
return self.srcdir.get_all_rdirs() + self.repositories
return self.repositories
|
python
|
def getRepositories(self):
"""Returns a list of repositories for this directory.
"""
if self.srcdir and not self.duplicate:
return self.srcdir.get_all_rdirs() + self.repositories
return self.repositories
|
[
"def",
"getRepositories",
"(",
"self",
")",
":",
"if",
"self",
".",
"srcdir",
"and",
"not",
"self",
".",
"duplicate",
":",
"return",
"self",
".",
"srcdir",
".",
"get_all_rdirs",
"(",
")",
"+",
"self",
".",
"repositories",
"return",
"self",
".",
"repositories"
] |
Returns a list of repositories for this directory.
|
[
"Returns",
"a",
"list",
"of",
"repositories",
"for",
"this",
"directory",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1633-L1638
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.rel_path
|
def rel_path(self, other):
"""Return a path to "other" relative to this directory.
"""
# This complicated and expensive method, which constructs relative
# paths between arbitrary Node.FS objects, is no longer used
# by SCons itself. It was introduced to store dependency paths
# in .sconsign files relative to the target, but that ended up
# being significantly inefficient.
#
# We're continuing to support the method because some SConstruct
# files out there started using it when it was available, and
# we're all about backwards compatibility..
try:
memo_dict = self._memo['rel_path']
except KeyError:
memo_dict = {}
self._memo['rel_path'] = memo_dict
else:
try:
return memo_dict[other]
except KeyError:
pass
if self is other:
result = '.'
elif not other in self._path_elements:
try:
other_dir = other.get_dir()
except AttributeError:
result = str(other)
else:
if other_dir is None:
result = other.name
else:
dir_rel_path = self.rel_path(other_dir)
if dir_rel_path == '.':
result = other.name
else:
result = dir_rel_path + OS_SEP + other.name
else:
i = self._path_elements.index(other) + 1
path_elems = ['..'] * (len(self._path_elements) - i) \
+ [n.name for n in other._path_elements[i:]]
result = OS_SEP.join(path_elems)
memo_dict[other] = result
return result
|
python
|
def rel_path(self, other):
"""Return a path to "other" relative to this directory.
"""
# This complicated and expensive method, which constructs relative
# paths between arbitrary Node.FS objects, is no longer used
# by SCons itself. It was introduced to store dependency paths
# in .sconsign files relative to the target, but that ended up
# being significantly inefficient.
#
# We're continuing to support the method because some SConstruct
# files out there started using it when it was available, and
# we're all about backwards compatibility..
try:
memo_dict = self._memo['rel_path']
except KeyError:
memo_dict = {}
self._memo['rel_path'] = memo_dict
else:
try:
return memo_dict[other]
except KeyError:
pass
if self is other:
result = '.'
elif not other in self._path_elements:
try:
other_dir = other.get_dir()
except AttributeError:
result = str(other)
else:
if other_dir is None:
result = other.name
else:
dir_rel_path = self.rel_path(other_dir)
if dir_rel_path == '.':
result = other.name
else:
result = dir_rel_path + OS_SEP + other.name
else:
i = self._path_elements.index(other) + 1
path_elems = ['..'] * (len(self._path_elements) - i) \
+ [n.name for n in other._path_elements[i:]]
result = OS_SEP.join(path_elems)
memo_dict[other] = result
return result
|
[
"def",
"rel_path",
"(",
"self",
",",
"other",
")",
":",
"# This complicated and expensive method, which constructs relative",
"# paths between arbitrary Node.FS objects, is no longer used",
"# by SCons itself. It was introduced to store dependency paths",
"# in .sconsign files relative to the target, but that ended up",
"# being significantly inefficient.",
"#",
"# We're continuing to support the method because some SConstruct",
"# files out there started using it when it was available, and",
"# we're all about backwards compatibility..",
"try",
":",
"memo_dict",
"=",
"self",
".",
"_memo",
"[",
"'rel_path'",
"]",
"except",
"KeyError",
":",
"memo_dict",
"=",
"{",
"}",
"self",
".",
"_memo",
"[",
"'rel_path'",
"]",
"=",
"memo_dict",
"else",
":",
"try",
":",
"return",
"memo_dict",
"[",
"other",
"]",
"except",
"KeyError",
":",
"pass",
"if",
"self",
"is",
"other",
":",
"result",
"=",
"'.'",
"elif",
"not",
"other",
"in",
"self",
".",
"_path_elements",
":",
"try",
":",
"other_dir",
"=",
"other",
".",
"get_dir",
"(",
")",
"except",
"AttributeError",
":",
"result",
"=",
"str",
"(",
"other",
")",
"else",
":",
"if",
"other_dir",
"is",
"None",
":",
"result",
"=",
"other",
".",
"name",
"else",
":",
"dir_rel_path",
"=",
"self",
".",
"rel_path",
"(",
"other_dir",
")",
"if",
"dir_rel_path",
"==",
"'.'",
":",
"result",
"=",
"other",
".",
"name",
"else",
":",
"result",
"=",
"dir_rel_path",
"+",
"OS_SEP",
"+",
"other",
".",
"name",
"else",
":",
"i",
"=",
"self",
".",
"_path_elements",
".",
"index",
"(",
"other",
")",
"+",
"1",
"path_elems",
"=",
"[",
"'..'",
"]",
"*",
"(",
"len",
"(",
"self",
".",
"_path_elements",
")",
"-",
"i",
")",
"+",
"[",
"n",
".",
"name",
"for",
"n",
"in",
"other",
".",
"_path_elements",
"[",
"i",
":",
"]",
"]",
"result",
"=",
"OS_SEP",
".",
"join",
"(",
"path_elems",
")",
"memo_dict",
"[",
"other",
"]",
"=",
"result",
"return",
"result"
] |
Return a path to "other" relative to this directory.
|
[
"Return",
"a",
"path",
"to",
"other",
"relative",
"to",
"this",
"directory",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1676-L1728
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.get_found_includes
|
def get_found_includes(self, env, scanner, path):
"""Return this directory's implicit dependencies.
We don't bother caching the results because the scan typically
shouldn't be requested more than once (as opposed to scanning
.h file contents, which can be requested as many times as the
files is #included by other files).
"""
if not scanner:
return []
# Clear cached info for this Dir. If we already visited this
# directory on our walk down the tree (because we didn't know at
# that point it was being used as the source for another Node)
# then we may have calculated build signature before realizing
# we had to scan the disk. Now that we have to, though, we need
# to invalidate the old calculated signature so that any node
# dependent on our directory structure gets one that includes
# info about everything on disk.
self.clear()
return scanner(self, env, path)
|
python
|
def get_found_includes(self, env, scanner, path):
"""Return this directory's implicit dependencies.
We don't bother caching the results because the scan typically
shouldn't be requested more than once (as opposed to scanning
.h file contents, which can be requested as many times as the
files is #included by other files).
"""
if not scanner:
return []
# Clear cached info for this Dir. If we already visited this
# directory on our walk down the tree (because we didn't know at
# that point it was being used as the source for another Node)
# then we may have calculated build signature before realizing
# we had to scan the disk. Now that we have to, though, we need
# to invalidate the old calculated signature so that any node
# dependent on our directory structure gets one that includes
# info about everything on disk.
self.clear()
return scanner(self, env, path)
|
[
"def",
"get_found_includes",
"(",
"self",
",",
"env",
",",
"scanner",
",",
"path",
")",
":",
"if",
"not",
"scanner",
":",
"return",
"[",
"]",
"# Clear cached info for this Dir. If we already visited this",
"# directory on our walk down the tree (because we didn't know at",
"# that point it was being used as the source for another Node)",
"# then we may have calculated build signature before realizing",
"# we had to scan the disk. Now that we have to, though, we need",
"# to invalidate the old calculated signature so that any node",
"# dependent on our directory structure gets one that includes",
"# info about everything on disk.",
"self",
".",
"clear",
"(",
")",
"return",
"scanner",
"(",
"self",
",",
"env",
",",
"path",
")"
] |
Return this directory's implicit dependencies.
We don't bother caching the results because the scan typically
shouldn't be requested more than once (as opposed to scanning
.h file contents, which can be requested as many times as the
files is #included by other files).
|
[
"Return",
"this",
"directory",
"s",
"implicit",
"dependencies",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1738-L1757
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.build
|
def build(self, **kw):
"""A null "builder" for directories."""
global MkdirBuilder
if self.builder is not MkdirBuilder:
SCons.Node.Node.build(self, **kw)
|
python
|
def build(self, **kw):
"""A null "builder" for directories."""
global MkdirBuilder
if self.builder is not MkdirBuilder:
SCons.Node.Node.build(self, **kw)
|
[
"def",
"build",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"global",
"MkdirBuilder",
"if",
"self",
".",
"builder",
"is",
"not",
"MkdirBuilder",
":",
"SCons",
".",
"Node",
".",
"Node",
".",
"build",
"(",
"self",
",",
"*",
"*",
"kw",
")"
] |
A null "builder" for directories.
|
[
"A",
"null",
"builder",
"for",
"directories",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1766-L1770
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir._create
|
def _create(self):
"""Create this directory, silently and without worrying about
whether the builder is the default or not."""
listDirs = []
parent = self
while parent:
if parent.exists():
break
listDirs.append(parent)
p = parent.up()
if p is None:
# Don't use while: - else: for this condition because
# if so, then parent is None and has no .path attribute.
raise SCons.Errors.StopError(parent._path)
parent = p
listDirs.reverse()
for dirnode in listDirs:
try:
# Don't call dirnode.build(), call the base Node method
# directly because we definitely *must* create this
# directory. The dirnode.build() method will suppress
# the build if it's the default builder.
SCons.Node.Node.build(dirnode)
dirnode.get_executor().nullify()
# The build() action may or may not have actually
# created the directory, depending on whether the -n
# option was used or not. Delete the _exists and
# _rexists attributes so they can be reevaluated.
dirnode.clear()
except OSError:
pass
|
python
|
def _create(self):
"""Create this directory, silently and without worrying about
whether the builder is the default or not."""
listDirs = []
parent = self
while parent:
if parent.exists():
break
listDirs.append(parent)
p = parent.up()
if p is None:
# Don't use while: - else: for this condition because
# if so, then parent is None and has no .path attribute.
raise SCons.Errors.StopError(parent._path)
parent = p
listDirs.reverse()
for dirnode in listDirs:
try:
# Don't call dirnode.build(), call the base Node method
# directly because we definitely *must* create this
# directory. The dirnode.build() method will suppress
# the build if it's the default builder.
SCons.Node.Node.build(dirnode)
dirnode.get_executor().nullify()
# The build() action may or may not have actually
# created the directory, depending on whether the -n
# option was used or not. Delete the _exists and
# _rexists attributes so they can be reevaluated.
dirnode.clear()
except OSError:
pass
|
[
"def",
"_create",
"(",
"self",
")",
":",
"listDirs",
"=",
"[",
"]",
"parent",
"=",
"self",
"while",
"parent",
":",
"if",
"parent",
".",
"exists",
"(",
")",
":",
"break",
"listDirs",
".",
"append",
"(",
"parent",
")",
"p",
"=",
"parent",
".",
"up",
"(",
")",
"if",
"p",
"is",
"None",
":",
"# Don't use while: - else: for this condition because",
"# if so, then parent is None and has no .path attribute.",
"raise",
"SCons",
".",
"Errors",
".",
"StopError",
"(",
"parent",
".",
"_path",
")",
"parent",
"=",
"p",
"listDirs",
".",
"reverse",
"(",
")",
"for",
"dirnode",
"in",
"listDirs",
":",
"try",
":",
"# Don't call dirnode.build(), call the base Node method",
"# directly because we definitely *must* create this",
"# directory. The dirnode.build() method will suppress",
"# the build if it's the default builder.",
"SCons",
".",
"Node",
".",
"Node",
".",
"build",
"(",
"dirnode",
")",
"dirnode",
".",
"get_executor",
"(",
")",
".",
"nullify",
"(",
")",
"# The build() action may or may not have actually",
"# created the directory, depending on whether the -n",
"# option was used or not. Delete the _exists and",
"# _rexists attributes so they can be reevaluated.",
"dirnode",
".",
"clear",
"(",
")",
"except",
"OSError",
":",
"pass"
] |
Create this directory, silently and without worrying about
whether the builder is the default or not.
|
[
"Create",
"this",
"directory",
"silently",
"and",
"without",
"worrying",
"about",
"whether",
"the",
"builder",
"is",
"the",
"default",
"or",
"not",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1776-L1806
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.is_up_to_date
|
def is_up_to_date(self):
"""If any child is not up-to-date, then this directory isn't,
either."""
if self.builder is not MkdirBuilder and not self.exists():
return 0
up_to_date = SCons.Node.up_to_date
for kid in self.children():
if kid.get_state() > up_to_date:
return 0
return 1
|
python
|
def is_up_to_date(self):
"""If any child is not up-to-date, then this directory isn't,
either."""
if self.builder is not MkdirBuilder and not self.exists():
return 0
up_to_date = SCons.Node.up_to_date
for kid in self.children():
if kid.get_state() > up_to_date:
return 0
return 1
|
[
"def",
"is_up_to_date",
"(",
"self",
")",
":",
"if",
"self",
".",
"builder",
"is",
"not",
"MkdirBuilder",
"and",
"not",
"self",
".",
"exists",
"(",
")",
":",
"return",
"0",
"up_to_date",
"=",
"SCons",
".",
"Node",
".",
"up_to_date",
"for",
"kid",
"in",
"self",
".",
"children",
"(",
")",
":",
"if",
"kid",
".",
"get_state",
"(",
")",
">",
"up_to_date",
":",
"return",
"0",
"return",
"1"
] |
If any child is not up-to-date, then this directory isn't,
either.
|
[
"If",
"any",
"child",
"is",
"not",
"up",
"-",
"to",
"-",
"date",
"then",
"this",
"directory",
"isn",
"t",
"either",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1843-L1852
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.get_timestamp
|
def get_timestamp(self):
"""Return the latest timestamp from among our children"""
stamp = 0
for kid in self.children():
if kid.get_timestamp() > stamp:
stamp = kid.get_timestamp()
return stamp
|
python
|
def get_timestamp(self):
"""Return the latest timestamp from among our children"""
stamp = 0
for kid in self.children():
if kid.get_timestamp() > stamp:
stamp = kid.get_timestamp()
return stamp
|
[
"def",
"get_timestamp",
"(",
"self",
")",
":",
"stamp",
"=",
"0",
"for",
"kid",
"in",
"self",
".",
"children",
"(",
")",
":",
"if",
"kid",
".",
"get_timestamp",
"(",
")",
">",
"stamp",
":",
"stamp",
"=",
"kid",
".",
"get_timestamp",
"(",
")",
"return",
"stamp"
] |
Return the latest timestamp from among our children
|
[
"Return",
"the",
"latest",
"timestamp",
"from",
"among",
"our",
"children"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L1876-L1882
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir.walk
|
def walk(self, func, arg):
"""
Walk this directory tree by calling the specified function
for each directory in the tree.
This behaves like the os.path.walk() function, but for in-memory
Node.FS.Dir objects. The function takes the same arguments as
the functions passed to os.path.walk():
func(arg, dirname, fnames)
Except that "dirname" will actually be the directory *Node*,
not the string. The '.' and '..' entries are excluded from
fnames. The fnames list may be modified in-place to filter the
subdirectories visited or otherwise impose a specific order.
The "arg" argument is always passed to func() and may be used
in any way (or ignored, passing None is common).
"""
entries = self.entries
names = list(entries.keys())
names.remove('.')
names.remove('..')
func(arg, self, names)
for dirname in [n for n in names if isinstance(entries[n], Dir)]:
entries[dirname].walk(func, arg)
|
python
|
def walk(self, func, arg):
"""
Walk this directory tree by calling the specified function
for each directory in the tree.
This behaves like the os.path.walk() function, but for in-memory
Node.FS.Dir objects. The function takes the same arguments as
the functions passed to os.path.walk():
func(arg, dirname, fnames)
Except that "dirname" will actually be the directory *Node*,
not the string. The '.' and '..' entries are excluded from
fnames. The fnames list may be modified in-place to filter the
subdirectories visited or otherwise impose a specific order.
The "arg" argument is always passed to func() and may be used
in any way (or ignored, passing None is common).
"""
entries = self.entries
names = list(entries.keys())
names.remove('.')
names.remove('..')
func(arg, self, names)
for dirname in [n for n in names if isinstance(entries[n], Dir)]:
entries[dirname].walk(func, arg)
|
[
"def",
"walk",
"(",
"self",
",",
"func",
",",
"arg",
")",
":",
"entries",
"=",
"self",
".",
"entries",
"names",
"=",
"list",
"(",
"entries",
".",
"keys",
"(",
")",
")",
"names",
".",
"remove",
"(",
"'.'",
")",
"names",
".",
"remove",
"(",
"'..'",
")",
"func",
"(",
"arg",
",",
"self",
",",
"names",
")",
"for",
"dirname",
"in",
"[",
"n",
"for",
"n",
"in",
"names",
"if",
"isinstance",
"(",
"entries",
"[",
"n",
"]",
",",
"Dir",
")",
"]",
":",
"entries",
"[",
"dirname",
"]",
".",
"walk",
"(",
"func",
",",
"arg",
")"
] |
Walk this directory tree by calling the specified function
for each directory in the tree.
This behaves like the os.path.walk() function, but for in-memory
Node.FS.Dir objects. The function takes the same arguments as
the functions passed to os.path.walk():
func(arg, dirname, fnames)
Except that "dirname" will actually be the directory *Node*,
not the string. The '.' and '..' entries are excluded from
fnames. The fnames list may be modified in-place to filter the
subdirectories visited or otherwise impose a specific order.
The "arg" argument is always passed to func() and may be used
in any way (or ignored, passing None is common).
|
[
"Walk",
"this",
"directory",
"tree",
"by",
"calling",
"the",
"specified",
"function",
"for",
"each",
"directory",
"in",
"the",
"tree",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2074-L2098
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
Dir._glob1
|
def _glob1(self, pattern, ondisk=True, source=False, strings=False):
"""
Globs for and returns a list of entry names matching a single
pattern in this directory.
This searches any repositories and source directories for
corresponding entries and returns a Node (or string) relative
to the current directory if an entry is found anywhere.
TODO: handle pattern with no wildcard
"""
search_dir_list = self.get_all_rdirs()
for srcdir in self.srcdir_list():
search_dir_list.extend(srcdir.get_all_rdirs())
selfEntry = self.Entry
names = []
for dir in search_dir_list:
# We use the .name attribute from the Node because the keys of
# the dir.entries dictionary are normalized (that is, all upper
# case) on case-insensitive systems like Windows.
node_names = [ v.name for k, v in dir.entries.items()
if k not in ('.', '..') ]
names.extend(node_names)
if not strings:
# Make sure the working directory (self) actually has
# entries for all Nodes in repositories or variant dirs.
for name in node_names: selfEntry(name)
if ondisk:
try:
disk_names = os.listdir(dir._abspath)
except os.error:
continue
names.extend(disk_names)
if not strings:
# We're going to return corresponding Nodes in
# the local directory, so we need to make sure
# those Nodes exist. We only want to create
# Nodes for the entries that will match the
# specified pattern, though, which means we
# need to filter the list here, even though
# the overall list will also be filtered later,
# after we exit this loop.
if pattern[0] != '.':
disk_names = [x for x in disk_names if x[0] != '.']
disk_names = fnmatch.filter(disk_names, pattern)
dirEntry = dir.Entry
for name in disk_names:
# Add './' before disk filename so that '#' at
# beginning of filename isn't interpreted.
name = './' + name
node = dirEntry(name).disambiguate()
n = selfEntry(name)
if n.__class__ != node.__class__:
n.__class__ = node.__class__
n._morph()
names = set(names)
if pattern[0] != '.':
names = [x for x in names if x[0] != '.']
names = fnmatch.filter(names, pattern)
if strings:
return names
return [self.entries[_my_normcase(n)] for n in names]
|
python
|
def _glob1(self, pattern, ondisk=True, source=False, strings=False):
"""
Globs for and returns a list of entry names matching a single
pattern in this directory.
This searches any repositories and source directories for
corresponding entries and returns a Node (or string) relative
to the current directory if an entry is found anywhere.
TODO: handle pattern with no wildcard
"""
search_dir_list = self.get_all_rdirs()
for srcdir in self.srcdir_list():
search_dir_list.extend(srcdir.get_all_rdirs())
selfEntry = self.Entry
names = []
for dir in search_dir_list:
# We use the .name attribute from the Node because the keys of
# the dir.entries dictionary are normalized (that is, all upper
# case) on case-insensitive systems like Windows.
node_names = [ v.name for k, v in dir.entries.items()
if k not in ('.', '..') ]
names.extend(node_names)
if not strings:
# Make sure the working directory (self) actually has
# entries for all Nodes in repositories or variant dirs.
for name in node_names: selfEntry(name)
if ondisk:
try:
disk_names = os.listdir(dir._abspath)
except os.error:
continue
names.extend(disk_names)
if not strings:
# We're going to return corresponding Nodes in
# the local directory, so we need to make sure
# those Nodes exist. We only want to create
# Nodes for the entries that will match the
# specified pattern, though, which means we
# need to filter the list here, even though
# the overall list will also be filtered later,
# after we exit this loop.
if pattern[0] != '.':
disk_names = [x for x in disk_names if x[0] != '.']
disk_names = fnmatch.filter(disk_names, pattern)
dirEntry = dir.Entry
for name in disk_names:
# Add './' before disk filename so that '#' at
# beginning of filename isn't interpreted.
name = './' + name
node = dirEntry(name).disambiguate()
n = selfEntry(name)
if n.__class__ != node.__class__:
n.__class__ = node.__class__
n._morph()
names = set(names)
if pattern[0] != '.':
names = [x for x in names if x[0] != '.']
names = fnmatch.filter(names, pattern)
if strings:
return names
return [self.entries[_my_normcase(n)] for n in names]
|
[
"def",
"_glob1",
"(",
"self",
",",
"pattern",
",",
"ondisk",
"=",
"True",
",",
"source",
"=",
"False",
",",
"strings",
"=",
"False",
")",
":",
"search_dir_list",
"=",
"self",
".",
"get_all_rdirs",
"(",
")",
"for",
"srcdir",
"in",
"self",
".",
"srcdir_list",
"(",
")",
":",
"search_dir_list",
".",
"extend",
"(",
"srcdir",
".",
"get_all_rdirs",
"(",
")",
")",
"selfEntry",
"=",
"self",
".",
"Entry",
"names",
"=",
"[",
"]",
"for",
"dir",
"in",
"search_dir_list",
":",
"# We use the .name attribute from the Node because the keys of",
"# the dir.entries dictionary are normalized (that is, all upper",
"# case) on case-insensitive systems like Windows.",
"node_names",
"=",
"[",
"v",
".",
"name",
"for",
"k",
",",
"v",
"in",
"dir",
".",
"entries",
".",
"items",
"(",
")",
"if",
"k",
"not",
"in",
"(",
"'.'",
",",
"'..'",
")",
"]",
"names",
".",
"extend",
"(",
"node_names",
")",
"if",
"not",
"strings",
":",
"# Make sure the working directory (self) actually has",
"# entries for all Nodes in repositories or variant dirs.",
"for",
"name",
"in",
"node_names",
":",
"selfEntry",
"(",
"name",
")",
"if",
"ondisk",
":",
"try",
":",
"disk_names",
"=",
"os",
".",
"listdir",
"(",
"dir",
".",
"_abspath",
")",
"except",
"os",
".",
"error",
":",
"continue",
"names",
".",
"extend",
"(",
"disk_names",
")",
"if",
"not",
"strings",
":",
"# We're going to return corresponding Nodes in",
"# the local directory, so we need to make sure",
"# those Nodes exist. We only want to create",
"# Nodes for the entries that will match the",
"# specified pattern, though, which means we",
"# need to filter the list here, even though",
"# the overall list will also be filtered later,",
"# after we exit this loop.",
"if",
"pattern",
"[",
"0",
"]",
"!=",
"'.'",
":",
"disk_names",
"=",
"[",
"x",
"for",
"x",
"in",
"disk_names",
"if",
"x",
"[",
"0",
"]",
"!=",
"'.'",
"]",
"disk_names",
"=",
"fnmatch",
".",
"filter",
"(",
"disk_names",
",",
"pattern",
")",
"dirEntry",
"=",
"dir",
".",
"Entry",
"for",
"name",
"in",
"disk_names",
":",
"# Add './' before disk filename so that '#' at",
"# beginning of filename isn't interpreted.",
"name",
"=",
"'./'",
"+",
"name",
"node",
"=",
"dirEntry",
"(",
"name",
")",
".",
"disambiguate",
"(",
")",
"n",
"=",
"selfEntry",
"(",
"name",
")",
"if",
"n",
".",
"__class__",
"!=",
"node",
".",
"__class__",
":",
"n",
".",
"__class__",
"=",
"node",
".",
"__class__",
"n",
".",
"_morph",
"(",
")",
"names",
"=",
"set",
"(",
"names",
")",
"if",
"pattern",
"[",
"0",
"]",
"!=",
"'.'",
":",
"names",
"=",
"[",
"x",
"for",
"x",
"in",
"names",
"if",
"x",
"[",
"0",
"]",
"!=",
"'.'",
"]",
"names",
"=",
"fnmatch",
".",
"filter",
"(",
"names",
",",
"pattern",
")",
"if",
"strings",
":",
"return",
"names",
"return",
"[",
"self",
".",
"entries",
"[",
"_my_normcase",
"(",
"n",
")",
"]",
"for",
"n",
"in",
"names",
"]"
] |
Globs for and returns a list of entry names matching a single
pattern in this directory.
This searches any repositories and source directories for
corresponding entries and returns a Node (or string) relative
to the current directory if an entry is found anywhere.
TODO: handle pattern with no wildcard
|
[
"Globs",
"for",
"and",
"returns",
"a",
"list",
"of",
"entry",
"names",
"matching",
"a",
"single",
"pattern",
"in",
"this",
"directory",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2160-L2225
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FileBuildInfo.convert_to_sconsign
|
def convert_to_sconsign(self):
"""
Converts this FileBuildInfo object for writing to a .sconsign file
This replaces each Node in our various dependency lists with its
usual string representation: relative to the top-level SConstruct
directory, or an absolute path if it's outside.
"""
if os_sep_is_slash:
node_to_str = str
else:
def node_to_str(n):
try:
s = n.get_internal_path()
except AttributeError:
s = str(n)
else:
s = s.replace(OS_SEP, '/')
return s
for attr in ['bsources', 'bdepends', 'bimplicit']:
try:
val = getattr(self, attr)
except AttributeError:
pass
else:
setattr(self, attr, list(map(node_to_str, val)))
|
python
|
def convert_to_sconsign(self):
"""
Converts this FileBuildInfo object for writing to a .sconsign file
This replaces each Node in our various dependency lists with its
usual string representation: relative to the top-level SConstruct
directory, or an absolute path if it's outside.
"""
if os_sep_is_slash:
node_to_str = str
else:
def node_to_str(n):
try:
s = n.get_internal_path()
except AttributeError:
s = str(n)
else:
s = s.replace(OS_SEP, '/')
return s
for attr in ['bsources', 'bdepends', 'bimplicit']:
try:
val = getattr(self, attr)
except AttributeError:
pass
else:
setattr(self, attr, list(map(node_to_str, val)))
|
[
"def",
"convert_to_sconsign",
"(",
"self",
")",
":",
"if",
"os_sep_is_slash",
":",
"node_to_str",
"=",
"str",
"else",
":",
"def",
"node_to_str",
"(",
"n",
")",
":",
"try",
":",
"s",
"=",
"n",
".",
"get_internal_path",
"(",
")",
"except",
"AttributeError",
":",
"s",
"=",
"str",
"(",
"n",
")",
"else",
":",
"s",
"=",
"s",
".",
"replace",
"(",
"OS_SEP",
",",
"'/'",
")",
"return",
"s",
"for",
"attr",
"in",
"[",
"'bsources'",
",",
"'bdepends'",
",",
"'bimplicit'",
"]",
":",
"try",
":",
"val",
"=",
"getattr",
"(",
"self",
",",
"attr",
")",
"except",
"AttributeError",
":",
"pass",
"else",
":",
"setattr",
"(",
"self",
",",
"attr",
",",
"list",
"(",
"map",
"(",
"node_to_str",
",",
"val",
")",
")",
")"
] |
Converts this FileBuildInfo object for writing to a .sconsign file
This replaces each Node in our various dependency lists with its
usual string representation: relative to the top-level SConstruct
directory, or an absolute path if it's outside.
|
[
"Converts",
"this",
"FileBuildInfo",
"object",
"for",
"writing",
"to",
"a",
".",
"sconsign",
"file"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2469-L2494
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FileBuildInfo.prepare_dependencies
|
def prepare_dependencies(self):
"""
Prepares a FileBuildInfo object for explaining what changed
The bsources, bdepends and bimplicit lists have all been
stored on disk as paths relative to the top-level SConstruct
directory. Convert the strings to actual Nodes (for use by the
--debug=explain code and --implicit-cache).
"""
attrs = [
('bsources', 'bsourcesigs'),
('bdepends', 'bdependsigs'),
('bimplicit', 'bimplicitsigs'),
]
for (nattr, sattr) in attrs:
try:
strings = getattr(self, nattr)
nodeinfos = getattr(self, sattr)
except AttributeError:
continue
if strings is None or nodeinfos is None:
continue
nodes = []
for s, ni in zip(strings, nodeinfos):
if not isinstance(s, SCons.Node.Node):
s = ni.str_to_node(s)
nodes.append(s)
setattr(self, nattr, nodes)
|
python
|
def prepare_dependencies(self):
"""
Prepares a FileBuildInfo object for explaining what changed
The bsources, bdepends and bimplicit lists have all been
stored on disk as paths relative to the top-level SConstruct
directory. Convert the strings to actual Nodes (for use by the
--debug=explain code and --implicit-cache).
"""
attrs = [
('bsources', 'bsourcesigs'),
('bdepends', 'bdependsigs'),
('bimplicit', 'bimplicitsigs'),
]
for (nattr, sattr) in attrs:
try:
strings = getattr(self, nattr)
nodeinfos = getattr(self, sattr)
except AttributeError:
continue
if strings is None or nodeinfos is None:
continue
nodes = []
for s, ni in zip(strings, nodeinfos):
if not isinstance(s, SCons.Node.Node):
s = ni.str_to_node(s)
nodes.append(s)
setattr(self, nattr, nodes)
|
[
"def",
"prepare_dependencies",
"(",
"self",
")",
":",
"attrs",
"=",
"[",
"(",
"'bsources'",
",",
"'bsourcesigs'",
")",
",",
"(",
"'bdepends'",
",",
"'bdependsigs'",
")",
",",
"(",
"'bimplicit'",
",",
"'bimplicitsigs'",
")",
",",
"]",
"for",
"(",
"nattr",
",",
"sattr",
")",
"in",
"attrs",
":",
"try",
":",
"strings",
"=",
"getattr",
"(",
"self",
",",
"nattr",
")",
"nodeinfos",
"=",
"getattr",
"(",
"self",
",",
"sattr",
")",
"except",
"AttributeError",
":",
"continue",
"if",
"strings",
"is",
"None",
"or",
"nodeinfos",
"is",
"None",
":",
"continue",
"nodes",
"=",
"[",
"]",
"for",
"s",
",",
"ni",
"in",
"zip",
"(",
"strings",
",",
"nodeinfos",
")",
":",
"if",
"not",
"isinstance",
"(",
"s",
",",
"SCons",
".",
"Node",
".",
"Node",
")",
":",
"s",
"=",
"ni",
".",
"str_to_node",
"(",
"s",
")",
"nodes",
".",
"append",
"(",
"s",
")",
"setattr",
"(",
"self",
",",
"nattr",
",",
"nodes",
")"
] |
Prepares a FileBuildInfo object for explaining what changed
The bsources, bdepends and bimplicit lists have all been
stored on disk as paths relative to the top-level SConstruct
directory. Convert the strings to actual Nodes (for use by the
--debug=explain code and --implicit-cache).
|
[
"Prepares",
"a",
"FileBuildInfo",
"object",
"for",
"explaining",
"what",
"changed"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2505-L2532
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.Dir
|
def Dir(self, name, create=True):
"""Create a directory node named 'name' relative to
the directory of this file."""
return self.dir.Dir(name, create=create)
|
python
|
def Dir(self, name, create=True):
"""Create a directory node named 'name' relative to
the directory of this file."""
return self.dir.Dir(name, create=create)
|
[
"def",
"Dir",
"(",
"self",
",",
"name",
",",
"create",
"=",
"True",
")",
":",
"return",
"self",
".",
"dir",
".",
"Dir",
"(",
"name",
",",
"create",
"=",
"create",
")"
] |
Create a directory node named 'name' relative to
the directory of this file.
|
[
"Create",
"a",
"directory",
"node",
"named",
"name",
"relative",
"to",
"the",
"directory",
"of",
"this",
"file",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2585-L2588
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File._morph
|
def _morph(self):
"""Turn a file system node into a File object."""
self.scanner_paths = {}
if not hasattr(self, '_local'):
self._local = 0
if not hasattr(self, 'released_target_info'):
self.released_target_info = False
self.store_info = 1
self._func_exists = 4
self._func_get_contents = 3
# Initialize this Node's decider function to decide_source() because
# every file is a source file until it has a Builder attached...
self.changed_since_last_build = 4
# If there was already a Builder set on this entry, then
# we need to make sure we call the target-decider function,
# not the source-decider. Reaching in and doing this by hand
# is a little bogus. We'd prefer to handle this by adding
# an Entry.builder_set() method that disambiguates like the
# other methods, but that starts running into problems with the
# fragile way we initialize Dir Nodes with their Mkdir builders,
# yet still allow them to be overridden by the user. Since it's
# not clear right now how to fix that, stick with what works
# until it becomes clear...
if self.has_builder():
self.changed_since_last_build = 5
|
python
|
def _morph(self):
"""Turn a file system node into a File object."""
self.scanner_paths = {}
if not hasattr(self, '_local'):
self._local = 0
if not hasattr(self, 'released_target_info'):
self.released_target_info = False
self.store_info = 1
self._func_exists = 4
self._func_get_contents = 3
# Initialize this Node's decider function to decide_source() because
# every file is a source file until it has a Builder attached...
self.changed_since_last_build = 4
# If there was already a Builder set on this entry, then
# we need to make sure we call the target-decider function,
# not the source-decider. Reaching in and doing this by hand
# is a little bogus. We'd prefer to handle this by adding
# an Entry.builder_set() method that disambiguates like the
# other methods, but that starts running into problems with the
# fragile way we initialize Dir Nodes with their Mkdir builders,
# yet still allow them to be overridden by the user. Since it's
# not clear right now how to fix that, stick with what works
# until it becomes clear...
if self.has_builder():
self.changed_since_last_build = 5
|
[
"def",
"_morph",
"(",
"self",
")",
":",
"self",
".",
"scanner_paths",
"=",
"{",
"}",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_local'",
")",
":",
"self",
".",
"_local",
"=",
"0",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'released_target_info'",
")",
":",
"self",
".",
"released_target_info",
"=",
"False",
"self",
".",
"store_info",
"=",
"1",
"self",
".",
"_func_exists",
"=",
"4",
"self",
".",
"_func_get_contents",
"=",
"3",
"# Initialize this Node's decider function to decide_source() because",
"# every file is a source file until it has a Builder attached...",
"self",
".",
"changed_since_last_build",
"=",
"4",
"# If there was already a Builder set on this entry, then",
"# we need to make sure we call the target-decider function,",
"# not the source-decider. Reaching in and doing this by hand",
"# is a little bogus. We'd prefer to handle this by adding",
"# an Entry.builder_set() method that disambiguates like the",
"# other methods, but that starts running into problems with the",
"# fragile way we initialize Dir Nodes with their Mkdir builders,",
"# yet still allow them to be overridden by the user. Since it's",
"# not clear right now how to fix that, stick with what works",
"# until it becomes clear...",
"if",
"self",
".",
"has_builder",
"(",
")",
":",
"self",
".",
"changed_since_last_build",
"=",
"5"
] |
Turn a file system node into a File object.
|
[
"Turn",
"a",
"file",
"system",
"node",
"into",
"a",
"File",
"object",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2600-L2627
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.get_text_contents
|
def get_text_contents(self):
"""
This attempts to figure out what the encoding of the text is
based upon the BOM bytes, and then decodes the contents so that
it's a valid python string.
"""
contents = self.get_contents()
# The behavior of various decode() methods and functions
# w.r.t. the initial BOM bytes is different for different
# encodings and/or Python versions. ('utf-8' does not strip
# them, but has a 'utf-8-sig' which does; 'utf-16' seems to
# strip them; etc.) Just sidestep all the complication by
# explicitly stripping the BOM before we decode().
if contents[:len(codecs.BOM_UTF8)] == codecs.BOM_UTF8:
return contents[len(codecs.BOM_UTF8):].decode('utf-8')
if contents[:len(codecs.BOM_UTF16_LE)] == codecs.BOM_UTF16_LE:
return contents[len(codecs.BOM_UTF16_LE):].decode('utf-16-le')
if contents[:len(codecs.BOM_UTF16_BE)] == codecs.BOM_UTF16_BE:
return contents[len(codecs.BOM_UTF16_BE):].decode('utf-16-be')
try:
return contents.decode('utf-8')
except UnicodeDecodeError as e:
try:
return contents.decode('latin-1')
except UnicodeDecodeError as e:
return contents.decode('utf-8', error='backslashreplace')
|
python
|
def get_text_contents(self):
"""
This attempts to figure out what the encoding of the text is
based upon the BOM bytes, and then decodes the contents so that
it's a valid python string.
"""
contents = self.get_contents()
# The behavior of various decode() methods and functions
# w.r.t. the initial BOM bytes is different for different
# encodings and/or Python versions. ('utf-8' does not strip
# them, but has a 'utf-8-sig' which does; 'utf-16' seems to
# strip them; etc.) Just sidestep all the complication by
# explicitly stripping the BOM before we decode().
if contents[:len(codecs.BOM_UTF8)] == codecs.BOM_UTF8:
return contents[len(codecs.BOM_UTF8):].decode('utf-8')
if contents[:len(codecs.BOM_UTF16_LE)] == codecs.BOM_UTF16_LE:
return contents[len(codecs.BOM_UTF16_LE):].decode('utf-16-le')
if contents[:len(codecs.BOM_UTF16_BE)] == codecs.BOM_UTF16_BE:
return contents[len(codecs.BOM_UTF16_BE):].decode('utf-16-be')
try:
return contents.decode('utf-8')
except UnicodeDecodeError as e:
try:
return contents.decode('latin-1')
except UnicodeDecodeError as e:
return contents.decode('utf-8', error='backslashreplace')
|
[
"def",
"get_text_contents",
"(",
"self",
")",
":",
"contents",
"=",
"self",
".",
"get_contents",
"(",
")",
"# The behavior of various decode() methods and functions",
"# w.r.t. the initial BOM bytes is different for different",
"# encodings and/or Python versions. ('utf-8' does not strip",
"# them, but has a 'utf-8-sig' which does; 'utf-16' seems to",
"# strip them; etc.) Just sidestep all the complication by",
"# explicitly stripping the BOM before we decode().",
"if",
"contents",
"[",
":",
"len",
"(",
"codecs",
".",
"BOM_UTF8",
")",
"]",
"==",
"codecs",
".",
"BOM_UTF8",
":",
"return",
"contents",
"[",
"len",
"(",
"codecs",
".",
"BOM_UTF8",
")",
":",
"]",
".",
"decode",
"(",
"'utf-8'",
")",
"if",
"contents",
"[",
":",
"len",
"(",
"codecs",
".",
"BOM_UTF16_LE",
")",
"]",
"==",
"codecs",
".",
"BOM_UTF16_LE",
":",
"return",
"contents",
"[",
"len",
"(",
"codecs",
".",
"BOM_UTF16_LE",
")",
":",
"]",
".",
"decode",
"(",
"'utf-16-le'",
")",
"if",
"contents",
"[",
":",
"len",
"(",
"codecs",
".",
"BOM_UTF16_BE",
")",
"]",
"==",
"codecs",
".",
"BOM_UTF16_BE",
":",
"return",
"contents",
"[",
"len",
"(",
"codecs",
".",
"BOM_UTF16_BE",
")",
":",
"]",
".",
"decode",
"(",
"'utf-16-be'",
")",
"try",
":",
"return",
"contents",
".",
"decode",
"(",
"'utf-8'",
")",
"except",
"UnicodeDecodeError",
"as",
"e",
":",
"try",
":",
"return",
"contents",
".",
"decode",
"(",
"'latin-1'",
")",
"except",
"UnicodeDecodeError",
"as",
"e",
":",
"return",
"contents",
".",
"decode",
"(",
"'utf-8'",
",",
"error",
"=",
"'backslashreplace'",
")"
] |
This attempts to figure out what the encoding of the text is
based upon the BOM bytes, and then decodes the contents so that
it's a valid python string.
|
[
"This",
"attempts",
"to",
"figure",
"out",
"what",
"the",
"encoding",
"of",
"the",
"text",
"is",
"based",
"upon",
"the",
"BOM",
"bytes",
"and",
"then",
"decodes",
"the",
"contents",
"so",
"that",
"it",
"s",
"a",
"valid",
"python",
"string",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2635-L2660
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.get_content_hash
|
def get_content_hash(self):
"""
Compute and return the MD5 hash for this file.
"""
if not self.rexists():
return SCons.Util.MD5signature('')
fname = self.rfile().get_abspath()
try:
cs = SCons.Util.MD5filesignature(fname,
chunksize=SCons.Node.FS.File.md5_chunksize*1024)
except EnvironmentError as e:
if not e.filename:
e.filename = fname
raise
return cs
|
python
|
def get_content_hash(self):
"""
Compute and return the MD5 hash for this file.
"""
if not self.rexists():
return SCons.Util.MD5signature('')
fname = self.rfile().get_abspath()
try:
cs = SCons.Util.MD5filesignature(fname,
chunksize=SCons.Node.FS.File.md5_chunksize*1024)
except EnvironmentError as e:
if not e.filename:
e.filename = fname
raise
return cs
|
[
"def",
"get_content_hash",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"rexists",
"(",
")",
":",
"return",
"SCons",
".",
"Util",
".",
"MD5signature",
"(",
"''",
")",
"fname",
"=",
"self",
".",
"rfile",
"(",
")",
".",
"get_abspath",
"(",
")",
"try",
":",
"cs",
"=",
"SCons",
".",
"Util",
".",
"MD5filesignature",
"(",
"fname",
",",
"chunksize",
"=",
"SCons",
".",
"Node",
".",
"FS",
".",
"File",
".",
"md5_chunksize",
"*",
"1024",
")",
"except",
"EnvironmentError",
"as",
"e",
":",
"if",
"not",
"e",
".",
"filename",
":",
"e",
".",
"filename",
"=",
"fname",
"raise",
"return",
"cs"
] |
Compute and return the MD5 hash for this file.
|
[
"Compute",
"and",
"return",
"the",
"MD5",
"hash",
"for",
"this",
"file",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2663-L2677
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.get_found_includes
|
def get_found_includes(self, env, scanner, path):
"""Return the included implicit dependencies in this file.
Cache results so we only scan the file once per path
regardless of how many times this information is requested.
"""
memo_key = (id(env), id(scanner), path)
try:
memo_dict = self._memo['get_found_includes']
except KeyError:
memo_dict = {}
self._memo['get_found_includes'] = memo_dict
else:
try:
return memo_dict[memo_key]
except KeyError:
pass
if scanner:
result = [n.disambiguate() for n in scanner(self, env, path)]
else:
result = []
memo_dict[memo_key] = result
return result
|
python
|
def get_found_includes(self, env, scanner, path):
"""Return the included implicit dependencies in this file.
Cache results so we only scan the file once per path
regardless of how many times this information is requested.
"""
memo_key = (id(env), id(scanner), path)
try:
memo_dict = self._memo['get_found_includes']
except KeyError:
memo_dict = {}
self._memo['get_found_includes'] = memo_dict
else:
try:
return memo_dict[memo_key]
except KeyError:
pass
if scanner:
result = [n.disambiguate() for n in scanner(self, env, path)]
else:
result = []
memo_dict[memo_key] = result
return result
|
[
"def",
"get_found_includes",
"(",
"self",
",",
"env",
",",
"scanner",
",",
"path",
")",
":",
"memo_key",
"=",
"(",
"id",
"(",
"env",
")",
",",
"id",
"(",
"scanner",
")",
",",
"path",
")",
"try",
":",
"memo_dict",
"=",
"self",
".",
"_memo",
"[",
"'get_found_includes'",
"]",
"except",
"KeyError",
":",
"memo_dict",
"=",
"{",
"}",
"self",
".",
"_memo",
"[",
"'get_found_includes'",
"]",
"=",
"memo_dict",
"else",
":",
"try",
":",
"return",
"memo_dict",
"[",
"memo_key",
"]",
"except",
"KeyError",
":",
"pass",
"if",
"scanner",
":",
"result",
"=",
"[",
"n",
".",
"disambiguate",
"(",
")",
"for",
"n",
"in",
"scanner",
"(",
"self",
",",
"env",
",",
"path",
")",
"]",
"else",
":",
"result",
"=",
"[",
"]",
"memo_dict",
"[",
"memo_key",
"]",
"=",
"result",
"return",
"result"
] |
Return the included implicit dependencies in this file.
Cache results so we only scan the file once per path
regardless of how many times this information is requested.
|
[
"Return",
"the",
"included",
"implicit",
"dependencies",
"in",
"this",
"file",
".",
"Cache",
"results",
"so",
"we",
"only",
"scan",
"the",
"file",
"once",
"per",
"path",
"regardless",
"of",
"how",
"many",
"times",
"this",
"information",
"is",
"requested",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2864-L2888
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.push_to_cache
|
def push_to_cache(self):
"""Try to push the node into a cache
"""
# This should get called before the Nodes' .built() method is
# called, which would clear the build signature if the file has
# a source scanner.
#
# We have to clear the local memoized values *before* we push
# the node to cache so that the memoization of the self.exists()
# return value doesn't interfere.
if self.nocache:
return
self.clear_memoized_values()
if self.exists():
self.get_build_env().get_CacheDir().push(self)
|
python
|
def push_to_cache(self):
"""Try to push the node into a cache
"""
# This should get called before the Nodes' .built() method is
# called, which would clear the build signature if the file has
# a source scanner.
#
# We have to clear the local memoized values *before* we push
# the node to cache so that the memoization of the self.exists()
# return value doesn't interfere.
if self.nocache:
return
self.clear_memoized_values()
if self.exists():
self.get_build_env().get_CacheDir().push(self)
|
[
"def",
"push_to_cache",
"(",
"self",
")",
":",
"# This should get called before the Nodes' .built() method is",
"# called, which would clear the build signature if the file has",
"# a source scanner.",
"#",
"# We have to clear the local memoized values *before* we push",
"# the node to cache so that the memoization of the self.exists()",
"# return value doesn't interfere.",
"if",
"self",
".",
"nocache",
":",
"return",
"self",
".",
"clear_memoized_values",
"(",
")",
"if",
"self",
".",
"exists",
"(",
")",
":",
"self",
".",
"get_build_env",
"(",
")",
".",
"get_CacheDir",
"(",
")",
".",
"push",
"(",
"self",
")"
] |
Try to push the node into a cache
|
[
"Try",
"to",
"push",
"the",
"node",
"into",
"a",
"cache"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2895-L2909
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.retrieve_from_cache
|
def retrieve_from_cache(self):
"""Try to retrieve the node's content from a cache
This method is called from multiple threads in a parallel build,
so only do thread safe stuff here. Do thread unsafe stuff in
built().
Returns true if the node was successfully retrieved.
"""
if self.nocache:
return None
if not self.is_derived():
return None
return self.get_build_env().get_CacheDir().retrieve(self)
|
python
|
def retrieve_from_cache(self):
"""Try to retrieve the node's content from a cache
This method is called from multiple threads in a parallel build,
so only do thread safe stuff here. Do thread unsafe stuff in
built().
Returns true if the node was successfully retrieved.
"""
if self.nocache:
return None
if not self.is_derived():
return None
return self.get_build_env().get_CacheDir().retrieve(self)
|
[
"def",
"retrieve_from_cache",
"(",
"self",
")",
":",
"if",
"self",
".",
"nocache",
":",
"return",
"None",
"if",
"not",
"self",
".",
"is_derived",
"(",
")",
":",
"return",
"None",
"return",
"self",
".",
"get_build_env",
"(",
")",
".",
"get_CacheDir",
"(",
")",
".",
"retrieve",
"(",
"self",
")"
] |
Try to retrieve the node's content from a cache
This method is called from multiple threads in a parallel build,
so only do thread safe stuff here. Do thread unsafe stuff in
built().
Returns true if the node was successfully retrieved.
|
[
"Try",
"to",
"retrieve",
"the",
"node",
"s",
"content",
"from",
"a",
"cache"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2911-L2924
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.release_target_info
|
def release_target_info(self):
"""Called just after this node has been marked
up-to-date or was built completely.
This is where we try to release as many target node infos
as possible for clean builds and update runs, in order
to minimize the overall memory consumption.
We'd like to remove a lot more attributes like self.sources
and self.sources_set, but they might get used
in a next build step. For example, during configuration
the source files for a built E{*}.o file are used to figure out
which linker to use for the resulting Program (gcc vs. g++)!
That's why we check for the 'keep_targetinfo' attribute,
config Nodes and the Interactive mode just don't allow
an early release of most variables.
In the same manner, we can't simply remove the self.attributes
here. The smart linking relies on the shared flag, and some
parts of the java Tool use it to transport information
about nodes...
@see: built() and Node.release_target_info()
"""
if (self.released_target_info or SCons.Node.interactive):
return
if not hasattr(self.attributes, 'keep_targetinfo'):
# Cache some required values, before releasing
# stuff like env, executor and builder...
self.changed(allowcache=True)
self.get_contents_sig()
self.get_build_env()
# Now purge unneeded stuff to free memory...
self.executor = None
self._memo.pop('rfile', None)
self.prerequisites = None
# Cleanup lists, but only if they're empty
if not len(self.ignore_set):
self.ignore_set = None
if not len(self.implicit_set):
self.implicit_set = None
if not len(self.depends_set):
self.depends_set = None
if not len(self.ignore):
self.ignore = None
if not len(self.depends):
self.depends = None
# Mark this node as done, we only have to release
# the memory once...
self.released_target_info = True
|
python
|
def release_target_info(self):
"""Called just after this node has been marked
up-to-date or was built completely.
This is where we try to release as many target node infos
as possible for clean builds and update runs, in order
to minimize the overall memory consumption.
We'd like to remove a lot more attributes like self.sources
and self.sources_set, but they might get used
in a next build step. For example, during configuration
the source files for a built E{*}.o file are used to figure out
which linker to use for the resulting Program (gcc vs. g++)!
That's why we check for the 'keep_targetinfo' attribute,
config Nodes and the Interactive mode just don't allow
an early release of most variables.
In the same manner, we can't simply remove the self.attributes
here. The smart linking relies on the shared flag, and some
parts of the java Tool use it to transport information
about nodes...
@see: built() and Node.release_target_info()
"""
if (self.released_target_info or SCons.Node.interactive):
return
if not hasattr(self.attributes, 'keep_targetinfo'):
# Cache some required values, before releasing
# stuff like env, executor and builder...
self.changed(allowcache=True)
self.get_contents_sig()
self.get_build_env()
# Now purge unneeded stuff to free memory...
self.executor = None
self._memo.pop('rfile', None)
self.prerequisites = None
# Cleanup lists, but only if they're empty
if not len(self.ignore_set):
self.ignore_set = None
if not len(self.implicit_set):
self.implicit_set = None
if not len(self.depends_set):
self.depends_set = None
if not len(self.ignore):
self.ignore = None
if not len(self.depends):
self.depends = None
# Mark this node as done, we only have to release
# the memory once...
self.released_target_info = True
|
[
"def",
"release_target_info",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"released_target_info",
"or",
"SCons",
".",
"Node",
".",
"interactive",
")",
":",
"return",
"if",
"not",
"hasattr",
"(",
"self",
".",
"attributes",
",",
"'keep_targetinfo'",
")",
":",
"# Cache some required values, before releasing",
"# stuff like env, executor and builder...",
"self",
".",
"changed",
"(",
"allowcache",
"=",
"True",
")",
"self",
".",
"get_contents_sig",
"(",
")",
"self",
".",
"get_build_env",
"(",
")",
"# Now purge unneeded stuff to free memory...",
"self",
".",
"executor",
"=",
"None",
"self",
".",
"_memo",
".",
"pop",
"(",
"'rfile'",
",",
"None",
")",
"self",
".",
"prerequisites",
"=",
"None",
"# Cleanup lists, but only if they're empty",
"if",
"not",
"len",
"(",
"self",
".",
"ignore_set",
")",
":",
"self",
".",
"ignore_set",
"=",
"None",
"if",
"not",
"len",
"(",
"self",
".",
"implicit_set",
")",
":",
"self",
".",
"implicit_set",
"=",
"None",
"if",
"not",
"len",
"(",
"self",
".",
"depends_set",
")",
":",
"self",
".",
"depends_set",
"=",
"None",
"if",
"not",
"len",
"(",
"self",
".",
"ignore",
")",
":",
"self",
".",
"ignore",
"=",
"None",
"if",
"not",
"len",
"(",
"self",
".",
"depends",
")",
":",
"self",
".",
"depends",
"=",
"None",
"# Mark this node as done, we only have to release",
"# the memory once...",
"self",
".",
"released_target_info",
"=",
"True"
] |
Called just after this node has been marked
up-to-date or was built completely.
This is where we try to release as many target node infos
as possible for clean builds and update runs, in order
to minimize the overall memory consumption.
We'd like to remove a lot more attributes like self.sources
and self.sources_set, but they might get used
in a next build step. For example, during configuration
the source files for a built E{*}.o file are used to figure out
which linker to use for the resulting Program (gcc vs. g++)!
That's why we check for the 'keep_targetinfo' attribute,
config Nodes and the Interactive mode just don't allow
an early release of most variables.
In the same manner, we can't simply remove the self.attributes
here. The smart linking relies on the shared flag, and some
parts of the java Tool use it to transport information
about nodes...
@see: built() and Node.release_target_info()
|
[
"Called",
"just",
"after",
"this",
"node",
"has",
"been",
"marked",
"up",
"-",
"to",
"-",
"date",
"or",
"was",
"built",
"completely",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L2949-L2999
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.has_src_builder
|
def has_src_builder(self):
"""Return whether this Node has a source builder or not.
If this Node doesn't have an explicit source code builder, this
is where we figure out, on the fly, if there's a transparent
source code builder for it.
Note that if we found a source builder, we also set the
self.builder attribute, so that all of the methods that actually
*build* this file don't have to do anything different.
"""
try:
scb = self.sbuilder
except AttributeError:
scb = self.sbuilder = self.find_src_builder()
return scb is not None
|
python
|
def has_src_builder(self):
"""Return whether this Node has a source builder or not.
If this Node doesn't have an explicit source code builder, this
is where we figure out, on the fly, if there's a transparent
source code builder for it.
Note that if we found a source builder, we also set the
self.builder attribute, so that all of the methods that actually
*build* this file don't have to do anything different.
"""
try:
scb = self.sbuilder
except AttributeError:
scb = self.sbuilder = self.find_src_builder()
return scb is not None
|
[
"def",
"has_src_builder",
"(",
"self",
")",
":",
"try",
":",
"scb",
"=",
"self",
".",
"sbuilder",
"except",
"AttributeError",
":",
"scb",
"=",
"self",
".",
"sbuilder",
"=",
"self",
".",
"find_src_builder",
"(",
")",
"return",
"scb",
"is",
"not",
"None"
] |
Return whether this Node has a source builder or not.
If this Node doesn't have an explicit source code builder, this
is where we figure out, on the fly, if there's a transparent
source code builder for it.
Note that if we found a source builder, we also set the
self.builder attribute, so that all of the methods that actually
*build* this file don't have to do anything different.
|
[
"Return",
"whether",
"this",
"Node",
"has",
"a",
"source",
"builder",
"or",
"not",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3016-L3031
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.alter_targets
|
def alter_targets(self):
"""Return any corresponding targets in a variant directory.
"""
if self.is_derived():
return [], None
return self.fs.variant_dir_target_climb(self, self.dir, [self.name])
|
python
|
def alter_targets(self):
"""Return any corresponding targets in a variant directory.
"""
if self.is_derived():
return [], None
return self.fs.variant_dir_target_climb(self, self.dir, [self.name])
|
[
"def",
"alter_targets",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_derived",
"(",
")",
":",
"return",
"[",
"]",
",",
"None",
"return",
"self",
".",
"fs",
".",
"variant_dir_target_climb",
"(",
"self",
",",
"self",
".",
"dir",
",",
"[",
"self",
".",
"name",
"]",
")"
] |
Return any corresponding targets in a variant directory.
|
[
"Return",
"any",
"corresponding",
"targets",
"in",
"a",
"variant",
"directory",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3033-L3038
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.prepare
|
def prepare(self):
"""Prepare for this file to be created."""
SCons.Node.Node.prepare(self)
if self.get_state() != SCons.Node.up_to_date:
if self.exists():
if self.is_derived() and not self.precious:
self._rmv_existing()
else:
try:
self._createDir()
except SCons.Errors.StopError as drive:
raise SCons.Errors.StopError("No drive `{}' for target `{}'.".format(drive, self))
|
python
|
def prepare(self):
"""Prepare for this file to be created."""
SCons.Node.Node.prepare(self)
if self.get_state() != SCons.Node.up_to_date:
if self.exists():
if self.is_derived() and not self.precious:
self._rmv_existing()
else:
try:
self._createDir()
except SCons.Errors.StopError as drive:
raise SCons.Errors.StopError("No drive `{}' for target `{}'.".format(drive, self))
|
[
"def",
"prepare",
"(",
"self",
")",
":",
"SCons",
".",
"Node",
".",
"Node",
".",
"prepare",
"(",
"self",
")",
"if",
"self",
".",
"get_state",
"(",
")",
"!=",
"SCons",
".",
"Node",
".",
"up_to_date",
":",
"if",
"self",
".",
"exists",
"(",
")",
":",
"if",
"self",
".",
"is_derived",
"(",
")",
"and",
"not",
"self",
".",
"precious",
":",
"self",
".",
"_rmv_existing",
"(",
")",
"else",
":",
"try",
":",
"self",
".",
"_createDir",
"(",
")",
"except",
"SCons",
".",
"Errors",
".",
"StopError",
"as",
"drive",
":",
"raise",
"SCons",
".",
"Errors",
".",
"StopError",
"(",
"\"No drive `{}' for target `{}'.\"",
".",
"format",
"(",
"drive",
",",
"self",
")",
")"
] |
Prepare for this file to be created.
|
[
"Prepare",
"for",
"this",
"file",
"to",
"be",
"created",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3056-L3068
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.remove
|
def remove(self):
"""Remove this file."""
if self.exists() or self.islink():
self.fs.unlink(self.get_internal_path())
return 1
return None
|
python
|
def remove(self):
"""Remove this file."""
if self.exists() or self.islink():
self.fs.unlink(self.get_internal_path())
return 1
return None
|
[
"def",
"remove",
"(",
"self",
")",
":",
"if",
"self",
".",
"exists",
"(",
")",
"or",
"self",
".",
"islink",
"(",
")",
":",
"self",
".",
"fs",
".",
"unlink",
"(",
"self",
".",
"get_internal_path",
"(",
")",
")",
"return",
"1",
"return",
"None"
] |
Remove this file.
|
[
"Remove",
"this",
"file",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3074-L3079
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.get_max_drift_csig
|
def get_max_drift_csig(self):
"""
Returns the content signature currently stored for this node
if it's been unmodified longer than the max_drift value, or the
max_drift value is 0. Returns None otherwise.
"""
old = self.get_stored_info()
mtime = self.get_timestamp()
max_drift = self.fs.max_drift
if max_drift > 0:
if (time.time() - mtime) > max_drift:
try:
n = old.ninfo
if n.timestamp and n.csig and n.timestamp == mtime:
return n.csig
except AttributeError:
pass
elif max_drift == 0:
try:
return old.ninfo.csig
except AttributeError:
pass
return None
|
python
|
def get_max_drift_csig(self):
"""
Returns the content signature currently stored for this node
if it's been unmodified longer than the max_drift value, or the
max_drift value is 0. Returns None otherwise.
"""
old = self.get_stored_info()
mtime = self.get_timestamp()
max_drift = self.fs.max_drift
if max_drift > 0:
if (time.time() - mtime) > max_drift:
try:
n = old.ninfo
if n.timestamp and n.csig and n.timestamp == mtime:
return n.csig
except AttributeError:
pass
elif max_drift == 0:
try:
return old.ninfo.csig
except AttributeError:
pass
return None
|
[
"def",
"get_max_drift_csig",
"(",
"self",
")",
":",
"old",
"=",
"self",
".",
"get_stored_info",
"(",
")",
"mtime",
"=",
"self",
".",
"get_timestamp",
"(",
")",
"max_drift",
"=",
"self",
".",
"fs",
".",
"max_drift",
"if",
"max_drift",
">",
"0",
":",
"if",
"(",
"time",
".",
"time",
"(",
")",
"-",
"mtime",
")",
">",
"max_drift",
":",
"try",
":",
"n",
"=",
"old",
".",
"ninfo",
"if",
"n",
".",
"timestamp",
"and",
"n",
".",
"csig",
"and",
"n",
".",
"timestamp",
"==",
"mtime",
":",
"return",
"n",
".",
"csig",
"except",
"AttributeError",
":",
"pass",
"elif",
"max_drift",
"==",
"0",
":",
"try",
":",
"return",
"old",
".",
"ninfo",
".",
"csig",
"except",
"AttributeError",
":",
"pass",
"return",
"None"
] |
Returns the content signature currently stored for this node
if it's been unmodified longer than the max_drift value, or the
max_drift value is 0. Returns None otherwise.
|
[
"Returns",
"the",
"content",
"signature",
"currently",
"stored",
"for",
"this",
"node",
"if",
"it",
"s",
"been",
"unmodified",
"longer",
"than",
"the",
"max_drift",
"value",
"or",
"the",
"max_drift",
"value",
"is",
"0",
".",
"Returns",
"None",
"otherwise",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3110-L3134
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.built
|
def built(self):
"""Called just after this File node is successfully built.
Just like for 'release_target_info' we try to release
some more target node attributes in order to minimize the
overall memory consumption.
@see: release_target_info
"""
SCons.Node.Node.built(self)
if (not SCons.Node.interactive and
not hasattr(self.attributes, 'keep_targetinfo')):
# Ensure that the build infos get computed and cached...
SCons.Node.store_info_map[self.store_info](self)
# ... then release some more variables.
self._specific_sources = False
self._labspath = None
self._save_str()
self.cwd = None
self.scanner_paths = None
|
python
|
def built(self):
"""Called just after this File node is successfully built.
Just like for 'release_target_info' we try to release
some more target node attributes in order to minimize the
overall memory consumption.
@see: release_target_info
"""
SCons.Node.Node.built(self)
if (not SCons.Node.interactive and
not hasattr(self.attributes, 'keep_targetinfo')):
# Ensure that the build infos get computed and cached...
SCons.Node.store_info_map[self.store_info](self)
# ... then release some more variables.
self._specific_sources = False
self._labspath = None
self._save_str()
self.cwd = None
self.scanner_paths = None
|
[
"def",
"built",
"(",
"self",
")",
":",
"SCons",
".",
"Node",
".",
"Node",
".",
"built",
"(",
"self",
")",
"if",
"(",
"not",
"SCons",
".",
"Node",
".",
"interactive",
"and",
"not",
"hasattr",
"(",
"self",
".",
"attributes",
",",
"'keep_targetinfo'",
")",
")",
":",
"# Ensure that the build infos get computed and cached...",
"SCons",
".",
"Node",
".",
"store_info_map",
"[",
"self",
".",
"store_info",
"]",
"(",
"self",
")",
"# ... then release some more variables.",
"self",
".",
"_specific_sources",
"=",
"False",
"self",
".",
"_labspath",
"=",
"None",
"self",
".",
"_save_str",
"(",
")",
"self",
".",
"cwd",
"=",
"None",
"self",
".",
"scanner_paths",
"=",
"None"
] |
Called just after this File node is successfully built.
Just like for 'release_target_info' we try to release
some more target node attributes in order to minimize the
overall memory consumption.
@see: release_target_info
|
[
"Called",
"just",
"after",
"this",
"File",
"node",
"is",
"successfully",
"built",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3181-L3203
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.changed
|
def changed(self, node=None, allowcache=False):
"""
Returns if the node is up-to-date with respect to the BuildInfo
stored last time it was built.
For File nodes this is basically a wrapper around Node.changed(),
but we allow the return value to get cached after the reference
to the Executor got released in release_target_info().
@see: Node.changed()
"""
if node is None:
try:
return self._memo['changed']
except KeyError:
pass
has_changed = SCons.Node.Node.changed(self, node)
if allowcache:
self._memo['changed'] = has_changed
return has_changed
|
python
|
def changed(self, node=None, allowcache=False):
"""
Returns if the node is up-to-date with respect to the BuildInfo
stored last time it was built.
For File nodes this is basically a wrapper around Node.changed(),
but we allow the return value to get cached after the reference
to the Executor got released in release_target_info().
@see: Node.changed()
"""
if node is None:
try:
return self._memo['changed']
except KeyError:
pass
has_changed = SCons.Node.Node.changed(self, node)
if allowcache:
self._memo['changed'] = has_changed
return has_changed
|
[
"def",
"changed",
"(",
"self",
",",
"node",
"=",
"None",
",",
"allowcache",
"=",
"False",
")",
":",
"if",
"node",
"is",
"None",
":",
"try",
":",
"return",
"self",
".",
"_memo",
"[",
"'changed'",
"]",
"except",
"KeyError",
":",
"pass",
"has_changed",
"=",
"SCons",
".",
"Node",
".",
"Node",
".",
"changed",
"(",
"self",
",",
"node",
")",
"if",
"allowcache",
":",
"self",
".",
"_memo",
"[",
"'changed'",
"]",
"=",
"has_changed",
"return",
"has_changed"
] |
Returns if the node is up-to-date with respect to the BuildInfo
stored last time it was built.
For File nodes this is basically a wrapper around Node.changed(),
but we allow the return value to get cached after the reference
to the Executor got released in release_target_info().
@see: Node.changed()
|
[
"Returns",
"if",
"the",
"node",
"is",
"up",
"-",
"to",
"-",
"date",
"with",
"respect",
"to",
"the",
"BuildInfo",
"stored",
"last",
"time",
"it",
"was",
"built",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3205-L3225
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.get_cachedir_csig
|
def get_cachedir_csig(self):
"""
Fetch a Node's content signature for purposes of computing
another Node's cachesig.
This is a wrapper around the normal get_csig() method that handles
the somewhat obscure case of using CacheDir with the -n option.
Any files that don't exist would normally be "built" by fetching
them from the cache, but the normal get_csig() method will try
to open up the local file, which doesn't exist because the -n
option meant we didn't actually pull the file from cachedir.
But since the file *does* actually exist in the cachedir, we
can use its contents for the csig.
"""
try:
return self.cachedir_csig
except AttributeError:
pass
cachedir, cachefile = self.get_build_env().get_CacheDir().cachepath(self)
if not self.exists() and cachefile and os.path.exists(cachefile):
self.cachedir_csig = SCons.Util.MD5filesignature(cachefile, \
SCons.Node.FS.File.md5_chunksize * 1024)
else:
self.cachedir_csig = self.get_csig()
return self.cachedir_csig
|
python
|
def get_cachedir_csig(self):
"""
Fetch a Node's content signature for purposes of computing
another Node's cachesig.
This is a wrapper around the normal get_csig() method that handles
the somewhat obscure case of using CacheDir with the -n option.
Any files that don't exist would normally be "built" by fetching
them from the cache, but the normal get_csig() method will try
to open up the local file, which doesn't exist because the -n
option meant we didn't actually pull the file from cachedir.
But since the file *does* actually exist in the cachedir, we
can use its contents for the csig.
"""
try:
return self.cachedir_csig
except AttributeError:
pass
cachedir, cachefile = self.get_build_env().get_CacheDir().cachepath(self)
if not self.exists() and cachefile and os.path.exists(cachefile):
self.cachedir_csig = SCons.Util.MD5filesignature(cachefile, \
SCons.Node.FS.File.md5_chunksize * 1024)
else:
self.cachedir_csig = self.get_csig()
return self.cachedir_csig
|
[
"def",
"get_cachedir_csig",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"cachedir_csig",
"except",
"AttributeError",
":",
"pass",
"cachedir",
",",
"cachefile",
"=",
"self",
".",
"get_build_env",
"(",
")",
".",
"get_CacheDir",
"(",
")",
".",
"cachepath",
"(",
"self",
")",
"if",
"not",
"self",
".",
"exists",
"(",
")",
"and",
"cachefile",
"and",
"os",
".",
"path",
".",
"exists",
"(",
"cachefile",
")",
":",
"self",
".",
"cachedir_csig",
"=",
"SCons",
".",
"Util",
".",
"MD5filesignature",
"(",
"cachefile",
",",
"SCons",
".",
"Node",
".",
"FS",
".",
"File",
".",
"md5_chunksize",
"*",
"1024",
")",
"else",
":",
"self",
".",
"cachedir_csig",
"=",
"self",
".",
"get_csig",
"(",
")",
"return",
"self",
".",
"cachedir_csig"
] |
Fetch a Node's content signature for purposes of computing
another Node's cachesig.
This is a wrapper around the normal get_csig() method that handles
the somewhat obscure case of using CacheDir with the -n option.
Any files that don't exist would normally be "built" by fetching
them from the cache, but the normal get_csig() method will try
to open up the local file, which doesn't exist because the -n
option meant we didn't actually pull the file from cachedir.
But since the file *does* actually exist in the cachedir, we
can use its contents for the csig.
|
[
"Fetch",
"a",
"Node",
"s",
"content",
"signature",
"for",
"purposes",
"of",
"computing",
"another",
"Node",
"s",
"cachesig",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3322-L3347
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.get_contents_sig
|
def get_contents_sig(self):
"""
A helper method for get_cachedir_bsig.
It computes and returns the signature for this
node's contents.
"""
try:
return self.contentsig
except AttributeError:
pass
executor = self.get_executor()
result = self.contentsig = SCons.Util.MD5signature(executor.get_contents())
return result
|
python
|
def get_contents_sig(self):
"""
A helper method for get_cachedir_bsig.
It computes and returns the signature for this
node's contents.
"""
try:
return self.contentsig
except AttributeError:
pass
executor = self.get_executor()
result = self.contentsig = SCons.Util.MD5signature(executor.get_contents())
return result
|
[
"def",
"get_contents_sig",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"contentsig",
"except",
"AttributeError",
":",
"pass",
"executor",
"=",
"self",
".",
"get_executor",
"(",
")",
"result",
"=",
"self",
".",
"contentsig",
"=",
"SCons",
".",
"Util",
".",
"MD5signature",
"(",
"executor",
".",
"get_contents",
"(",
")",
")",
"return",
"result"
] |
A helper method for get_cachedir_bsig.
It computes and returns the signature for this
node's contents.
|
[
"A",
"helper",
"method",
"for",
"get_cachedir_bsig",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3349-L3365
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
File.get_cachedir_bsig
|
def get_cachedir_bsig(self):
"""
Return the signature for a cached file, including
its children.
It adds the path of the cached file to the cache signature,
because multiple targets built by the same action will all
have the same build signature, and we have to differentiate
them somehow.
"""
try:
return self.cachesig
except AttributeError:
pass
# Collect signatures for all children
children = self.children()
sigs = [n.get_cachedir_csig() for n in children]
# Append this node's signature...
sigs.append(self.get_contents_sig())
# ...and it's path
sigs.append(self.get_internal_path())
# Merge this all into a single signature
result = self.cachesig = SCons.Util.MD5collect(sigs)
return result
|
python
|
def get_cachedir_bsig(self):
"""
Return the signature for a cached file, including
its children.
It adds the path of the cached file to the cache signature,
because multiple targets built by the same action will all
have the same build signature, and we have to differentiate
them somehow.
"""
try:
return self.cachesig
except AttributeError:
pass
# Collect signatures for all children
children = self.children()
sigs = [n.get_cachedir_csig() for n in children]
# Append this node's signature...
sigs.append(self.get_contents_sig())
# ...and it's path
sigs.append(self.get_internal_path())
# Merge this all into a single signature
result = self.cachesig = SCons.Util.MD5collect(sigs)
return result
|
[
"def",
"get_cachedir_bsig",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"cachesig",
"except",
"AttributeError",
":",
"pass",
"# Collect signatures for all children",
"children",
"=",
"self",
".",
"children",
"(",
")",
"sigs",
"=",
"[",
"n",
".",
"get_cachedir_csig",
"(",
")",
"for",
"n",
"in",
"children",
"]",
"# Append this node's signature...",
"sigs",
".",
"append",
"(",
"self",
".",
"get_contents_sig",
"(",
")",
")",
"# ...and it's path",
"sigs",
".",
"append",
"(",
"self",
".",
"get_internal_path",
"(",
")",
")",
"# Merge this all into a single signature",
"result",
"=",
"self",
".",
"cachesig",
"=",
"SCons",
".",
"Util",
".",
"MD5collect",
"(",
"sigs",
")",
"return",
"result"
] |
Return the signature for a cached file, including
its children.
It adds the path of the cached file to the cache signature,
because multiple targets built by the same action will all
have the same build signature, and we have to differentiate
them somehow.
|
[
"Return",
"the",
"signature",
"for",
"a",
"cached",
"file",
"including",
"its",
"children",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3367-L3391
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py
|
FileFinder.find_file
|
def find_file(self, filename, paths, verbose=None):
"""
Find a node corresponding to either a derived file or a file that exists already.
Only the first file found is returned, and none is returned if no file is found.
filename: A filename to find
paths: A list of directory path *nodes* to search in. Can be represented as a list, a tuple, or a callable that is called with no arguments and returns the list or tuple.
returns The node created from the found file.
"""
memo_key = self._find_file_key(filename, paths)
try:
memo_dict = self._memo['find_file']
except KeyError:
memo_dict = {}
self._memo['find_file'] = memo_dict
else:
try:
return memo_dict[memo_key]
except KeyError:
pass
if verbose and not callable(verbose):
if not SCons.Util.is_String(verbose):
verbose = "find_file"
_verbose = u' %s: ' % verbose
verbose = lambda s: sys.stdout.write(_verbose + s)
filedir, filename = os.path.split(filename)
if filedir:
self.default_filedir = filedir
paths = [_f for _f in map(self.filedir_lookup, paths) if _f]
result = None
for dir in paths:
if verbose:
verbose("looking for '%s' in '%s' ...\n" % (filename, dir))
node, d = dir.srcdir_find_file(filename)
if node:
if verbose:
verbose("... FOUND '%s' in '%s'\n" % (filename, d))
result = node
break
memo_dict[memo_key] = result
return result
|
python
|
def find_file(self, filename, paths, verbose=None):
"""
Find a node corresponding to either a derived file or a file that exists already.
Only the first file found is returned, and none is returned if no file is found.
filename: A filename to find
paths: A list of directory path *nodes* to search in. Can be represented as a list, a tuple, or a callable that is called with no arguments and returns the list or tuple.
returns The node created from the found file.
"""
memo_key = self._find_file_key(filename, paths)
try:
memo_dict = self._memo['find_file']
except KeyError:
memo_dict = {}
self._memo['find_file'] = memo_dict
else:
try:
return memo_dict[memo_key]
except KeyError:
pass
if verbose and not callable(verbose):
if not SCons.Util.is_String(verbose):
verbose = "find_file"
_verbose = u' %s: ' % verbose
verbose = lambda s: sys.stdout.write(_verbose + s)
filedir, filename = os.path.split(filename)
if filedir:
self.default_filedir = filedir
paths = [_f for _f in map(self.filedir_lookup, paths) if _f]
result = None
for dir in paths:
if verbose:
verbose("looking for '%s' in '%s' ...\n" % (filename, dir))
node, d = dir.srcdir_find_file(filename)
if node:
if verbose:
verbose("... FOUND '%s' in '%s'\n" % (filename, d))
result = node
break
memo_dict[memo_key] = result
return result
|
[
"def",
"find_file",
"(",
"self",
",",
"filename",
",",
"paths",
",",
"verbose",
"=",
"None",
")",
":",
"memo_key",
"=",
"self",
".",
"_find_file_key",
"(",
"filename",
",",
"paths",
")",
"try",
":",
"memo_dict",
"=",
"self",
".",
"_memo",
"[",
"'find_file'",
"]",
"except",
"KeyError",
":",
"memo_dict",
"=",
"{",
"}",
"self",
".",
"_memo",
"[",
"'find_file'",
"]",
"=",
"memo_dict",
"else",
":",
"try",
":",
"return",
"memo_dict",
"[",
"memo_key",
"]",
"except",
"KeyError",
":",
"pass",
"if",
"verbose",
"and",
"not",
"callable",
"(",
"verbose",
")",
":",
"if",
"not",
"SCons",
".",
"Util",
".",
"is_String",
"(",
"verbose",
")",
":",
"verbose",
"=",
"\"find_file\"",
"_verbose",
"=",
"u' %s: '",
"%",
"verbose",
"verbose",
"=",
"lambda",
"s",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"_verbose",
"+",
"s",
")",
"filedir",
",",
"filename",
"=",
"os",
".",
"path",
".",
"split",
"(",
"filename",
")",
"if",
"filedir",
":",
"self",
".",
"default_filedir",
"=",
"filedir",
"paths",
"=",
"[",
"_f",
"for",
"_f",
"in",
"map",
"(",
"self",
".",
"filedir_lookup",
",",
"paths",
")",
"if",
"_f",
"]",
"result",
"=",
"None",
"for",
"dir",
"in",
"paths",
":",
"if",
"verbose",
":",
"verbose",
"(",
"\"looking for '%s' in '%s' ...\\n\"",
"%",
"(",
"filename",
",",
"dir",
")",
")",
"node",
",",
"d",
"=",
"dir",
".",
"srcdir_find_file",
"(",
"filename",
")",
"if",
"node",
":",
"if",
"verbose",
":",
"verbose",
"(",
"\"... FOUND '%s' in '%s'\\n\"",
"%",
"(",
"filename",
",",
"d",
")",
")",
"result",
"=",
"node",
"break",
"memo_dict",
"[",
"memo_key",
"]",
"=",
"result",
"return",
"result"
] |
Find a node corresponding to either a derived file or a file that exists already.
Only the first file found is returned, and none is returned if no file is found.
filename: A filename to find
paths: A list of directory path *nodes* to search in. Can be represented as a list, a tuple, or a callable that is called with no arguments and returns the list or tuple.
returns The node created from the found file.
|
[
"Find",
"a",
"node",
"corresponding",
"to",
"either",
"a",
"derived",
"file",
"or",
"a",
"file",
"that",
"exists",
"already",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Node/FS.py#L3447-L3495
|
train
|
iotile/coretools
|
iotileship/iotile/ship/actions/send_ota_script_step.py
|
SendOTAScriptStep.run
|
def run(self, resources):
"""Actually send the trub script.
Args:
resources (dict): A dictionary containing the required resources that
we needed access to in order to perform this step.
"""
hwman = resources['connection']
updater = hwman.hwman.app(name='device_updater')
updater.run_script(self._script, no_reboot=self._no_reboot)
|
python
|
def run(self, resources):
"""Actually send the trub script.
Args:
resources (dict): A dictionary containing the required resources that
we needed access to in order to perform this step.
"""
hwman = resources['connection']
updater = hwman.hwman.app(name='device_updater')
updater.run_script(self._script, no_reboot=self._no_reboot)
|
[
"def",
"run",
"(",
"self",
",",
"resources",
")",
":",
"hwman",
"=",
"resources",
"[",
"'connection'",
"]",
"updater",
"=",
"hwman",
".",
"hwman",
".",
"app",
"(",
"name",
"=",
"'device_updater'",
")",
"updater",
".",
"run_script",
"(",
"self",
".",
"_script",
",",
"no_reboot",
"=",
"self",
".",
"_no_reboot",
")"
] |
Actually send the trub script.
Args:
resources (dict): A dictionary containing the required resources that
we needed access to in order to perform this step.
|
[
"Actually",
"send",
"the",
"trub",
"script",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotileship/iotile/ship/actions/send_ota_script_step.py#L38-L49
|
train
|
iotile/coretools
|
transport_plugins/bled112/iotile_transport_bled112/bgapi_structures.py
|
process_gatt_service
|
def process_gatt_service(services, event):
"""Process a BGAPI event containing a GATT service description and add it to a dictionary
Args:
services (dict): A dictionary of discovered services that is updated with this event
event (BGAPIPacket): An event containing a GATT service
"""
length = len(event.payload) - 5
handle, start, end, uuid = unpack('<BHH%ds' % length, event.payload)
uuid = process_uuid(uuid)
services[uuid] = {'uuid_raw': uuid, 'start_handle': start, 'end_handle': end}
|
python
|
def process_gatt_service(services, event):
"""Process a BGAPI event containing a GATT service description and add it to a dictionary
Args:
services (dict): A dictionary of discovered services that is updated with this event
event (BGAPIPacket): An event containing a GATT service
"""
length = len(event.payload) - 5
handle, start, end, uuid = unpack('<BHH%ds' % length, event.payload)
uuid = process_uuid(uuid)
services[uuid] = {'uuid_raw': uuid, 'start_handle': start, 'end_handle': end}
|
[
"def",
"process_gatt_service",
"(",
"services",
",",
"event",
")",
":",
"length",
"=",
"len",
"(",
"event",
".",
"payload",
")",
"-",
"5",
"handle",
",",
"start",
",",
"end",
",",
"uuid",
"=",
"unpack",
"(",
"'<BHH%ds'",
"%",
"length",
",",
"event",
".",
"payload",
")",
"uuid",
"=",
"process_uuid",
"(",
"uuid",
")",
"services",
"[",
"uuid",
"]",
"=",
"{",
"'uuid_raw'",
":",
"uuid",
",",
"'start_handle'",
":",
"start",
",",
"'end_handle'",
":",
"end",
"}"
] |
Process a BGAPI event containing a GATT service description and add it to a dictionary
Args:
services (dict): A dictionary of discovered services that is updated with this event
event (BGAPIPacket): An event containing a GATT service
|
[
"Process",
"a",
"BGAPI",
"event",
"containing",
"a",
"GATT",
"service",
"description",
"and",
"add",
"it",
"to",
"a",
"dictionary"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/bled112/iotile_transport_bled112/bgapi_structures.py#L27-L41
|
train
|
iotile/coretools
|
transport_plugins/bled112/iotile_transport_bled112/bgapi_structures.py
|
handle_to_uuid
|
def handle_to_uuid(handle, services):
"""Find the corresponding UUID for an attribute handle"""
for service in services.values():
for char_uuid, char_def in service['characteristics'].items():
if char_def['handle'] == handle:
return char_uuid
raise ValueError("Handle not found in GATT table")
|
python
|
def handle_to_uuid(handle, services):
"""Find the corresponding UUID for an attribute handle"""
for service in services.values():
for char_uuid, char_def in service['characteristics'].items():
if char_def['handle'] == handle:
return char_uuid
raise ValueError("Handle not found in GATT table")
|
[
"def",
"handle_to_uuid",
"(",
"handle",
",",
"services",
")",
":",
"for",
"service",
"in",
"services",
".",
"values",
"(",
")",
":",
"for",
"char_uuid",
",",
"char_def",
"in",
"service",
"[",
"'characteristics'",
"]",
".",
"items",
"(",
")",
":",
"if",
"char_def",
"[",
"'handle'",
"]",
"==",
"handle",
":",
"return",
"char_uuid",
"raise",
"ValueError",
"(",
"\"Handle not found in GATT table\"",
")"
] |
Find the corresponding UUID for an attribute handle
|
[
"Find",
"the",
"corresponding",
"UUID",
"for",
"an",
"attribute",
"handle"
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/transport_plugins/bled112/iotile_transport_bled112/bgapi_structures.py#L87-L95
|
train
|
iotile/coretools
|
iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Variables/BoolVariable.py
|
_validator
|
def _validator(key, val, env):
"""
Validates the given value to be either '0' or '1'.
This is usable as 'validator' for SCons' Variables.
"""
if not env[key] in (True, False):
raise SCons.Errors.UserError(
'Invalid value for boolean option %s: %s' % (key, env[key]))
|
python
|
def _validator(key, val, env):
"""
Validates the given value to be either '0' or '1'.
This is usable as 'validator' for SCons' Variables.
"""
if not env[key] in (True, False):
raise SCons.Errors.UserError(
'Invalid value for boolean option %s: %s' % (key, env[key]))
|
[
"def",
"_validator",
"(",
"key",
",",
"val",
",",
"env",
")",
":",
"if",
"not",
"env",
"[",
"key",
"]",
"in",
"(",
"True",
",",
"False",
")",
":",
"raise",
"SCons",
".",
"Errors",
".",
"UserError",
"(",
"'Invalid value for boolean option %s: %s'",
"%",
"(",
"key",
",",
"env",
"[",
"key",
"]",
")",
")"
] |
Validates the given value to be either '0' or '1'.
This is usable as 'validator' for SCons' Variables.
|
[
"Validates",
"the",
"given",
"value",
"to",
"be",
"either",
"0",
"or",
"1",
".",
"This",
"is",
"usable",
"as",
"validator",
"for",
"SCons",
"Variables",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilebuild/iotile/build/config/scons-local-3.0.1/SCons/Variables/BoolVariable.py#L64-L72
|
train
|
iotile/coretools
|
iotilegateway/iotilegateway/supervisor/states.py
|
ServiceMessage.FromDictionary
|
def FromDictionary(cls, msg_dict):
"""Create from a dictionary with kv pairs.
Args:
msg_dict (dict): A dictionary with information as created by to_dict()
Returns:
ServiceMessage: the converted message
"""
level = msg_dict.get('level')
msg = msg_dict.get('message')
now = msg_dict.get('now_time')
created = msg_dict.get('created_time')
count = msg_dict.get('count', 1)
msg_id = msg_dict.get('id', 0)
new_msg = ServiceMessage(level, msg, msg_id, created, now)
if count > 1:
new_msg.count = count
return new_msg
|
python
|
def FromDictionary(cls, msg_dict):
"""Create from a dictionary with kv pairs.
Args:
msg_dict (dict): A dictionary with information as created by to_dict()
Returns:
ServiceMessage: the converted message
"""
level = msg_dict.get('level')
msg = msg_dict.get('message')
now = msg_dict.get('now_time')
created = msg_dict.get('created_time')
count = msg_dict.get('count', 1)
msg_id = msg_dict.get('id', 0)
new_msg = ServiceMessage(level, msg, msg_id, created, now)
if count > 1:
new_msg.count = count
return new_msg
|
[
"def",
"FromDictionary",
"(",
"cls",
",",
"msg_dict",
")",
":",
"level",
"=",
"msg_dict",
".",
"get",
"(",
"'level'",
")",
"msg",
"=",
"msg_dict",
".",
"get",
"(",
"'message'",
")",
"now",
"=",
"msg_dict",
".",
"get",
"(",
"'now_time'",
")",
"created",
"=",
"msg_dict",
".",
"get",
"(",
"'created_time'",
")",
"count",
"=",
"msg_dict",
".",
"get",
"(",
"'count'",
",",
"1",
")",
"msg_id",
"=",
"msg_dict",
".",
"get",
"(",
"'id'",
",",
"0",
")",
"new_msg",
"=",
"ServiceMessage",
"(",
"level",
",",
"msg",
",",
"msg_id",
",",
"created",
",",
"now",
")",
"if",
"count",
">",
"1",
":",
"new_msg",
".",
"count",
"=",
"count",
"return",
"new_msg"
] |
Create from a dictionary with kv pairs.
Args:
msg_dict (dict): A dictionary with information as created by to_dict()
Returns:
ServiceMessage: the converted message
|
[
"Create",
"from",
"a",
"dictionary",
"with",
"kv",
"pairs",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilegateway/iotilegateway/supervisor/states.py#L65-L86
|
train
|
iotile/coretools
|
iotilegateway/iotilegateway/supervisor/states.py
|
ServiceMessage.to_dict
|
def to_dict(self):
"""Create a dictionary with the information in this message.
Returns:
dict: The dictionary with information
"""
msg_dict = {}
msg_dict['level'] = self.level
msg_dict['message'] = self.message
msg_dict['now_time'] = monotonic()
msg_dict['created_time'] = self.created
msg_dict['id'] = self.id
msg_dict['count'] = self.count
return msg_dict
|
python
|
def to_dict(self):
"""Create a dictionary with the information in this message.
Returns:
dict: The dictionary with information
"""
msg_dict = {}
msg_dict['level'] = self.level
msg_dict['message'] = self.message
msg_dict['now_time'] = monotonic()
msg_dict['created_time'] = self.created
msg_dict['id'] = self.id
msg_dict['count'] = self.count
return msg_dict
|
[
"def",
"to_dict",
"(",
"self",
")",
":",
"msg_dict",
"=",
"{",
"}",
"msg_dict",
"[",
"'level'",
"]",
"=",
"self",
".",
"level",
"msg_dict",
"[",
"'message'",
"]",
"=",
"self",
".",
"message",
"msg_dict",
"[",
"'now_time'",
"]",
"=",
"monotonic",
"(",
")",
"msg_dict",
"[",
"'created_time'",
"]",
"=",
"self",
".",
"created",
"msg_dict",
"[",
"'id'",
"]",
"=",
"self",
".",
"id",
"msg_dict",
"[",
"'count'",
"]",
"=",
"self",
".",
"count",
"return",
"msg_dict"
] |
Create a dictionary with the information in this message.
Returns:
dict: The dictionary with information
|
[
"Create",
"a",
"dictionary",
"with",
"the",
"information",
"in",
"this",
"message",
"."
] |
2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec
|
https://github.com/iotile/coretools/blob/2d794f5f1346b841b0dcd16c9d284e9bf2f3c6ec/iotilegateway/iotilegateway/supervisor/states.py#L88-L103
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.