Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _snmp_set(host, oid, value):
try:
processwrapper.check_output(
"snmpset -v1 -c private {} {} {}".format(host, oid, value).split()
)
except Exception as e:
raise ExecutionError("failed to set SNMP value") from e
def _snmp_get(host, oid):
out = processwrapper.check_output(
"snmpget -v1 -c private -O qn {} {}".format(host, oid).split()
).decode('ascii')
out_oid, value = out.strip().split(' ', 1)
assert oid == out_oid
if value == "3" or value == "5":
return True
if value == "4":
return False
def cycle(self):
if self.cmd_cycle is not None:
cmd = shlex.split(self.cmd_cycle)
processwrapper.check_output(cmd)
else:
self.off()
time.sleep(self.delay)
self.on()
def get_size(self):
args = ["cat", "/sys/class/block/{}/size".format(self.storage.path[5:])]
size = processwrapper.check_output(self.storage.command_prefix + args)
return int(size)
def __call__(self, *args):
arg_list = list(args)
arg_list.append('-p')
arg_list.append('{}'.format(self.flashrom_resource.programmer))
self.logger.debug('Call: %s with args: %s', self.tool, arg_list)
processwrapper.check_output(self._get_flashrom_prefix() + arg_list)
def flash(self, filename=None, address=0x0):
if filename is None and self.image is not None:
filename = self.target.env.config.get_image_path(self.image)
mf = ManagedFile(filename, self.interface)
mf.sync_to_resource()
assert isinstance(address, int)
cable_number = self._get_cable_number()
cmd = self.interface.command_prefix + [self.tool]
cmd += [
"--cable={}".format(cable_number),
"--addr=0x{:X}".format(address),
"--operation=P {}".format(mf.get_remote_path()),
]
processwrapper.check_output(cmd)
def oem_getenv(self, var):
"""Return barebox environment variable value via 'fastboot oem getenv <var>'."""
cmd = ['oem', 'getenv', var]
output = processwrapper.check_output(self._get_fastboot_prefix() + cmd)
values = AndroidFastbootDriver._filter_fastboot_output(output)
assert len(values) == 1, 'fastboot did not return exactly one line'
return values[0]
</var>
def set_mode(self, mode):
if not mode.lower() in ['dut', 'host', 'off', 'client']:
raise ExecutionError("Setting mode '%s' not supported by USBSDMuxDriver" % mode)
cmd = self.mux.command_prefix + [
self.tool,
"-c",
self.mux.control_path,
mode.lower()
]
processwrapper.check_output(cmd)
managed_configs = []
for config in self.config:
mconfig = ManagedFile(config, self.interface)
mconfig.sync_to_resource()
managed_configs.append(mconfig)
cmd = self.interface.command_prefix+[self.tool]
cmd += chain.from_iterable(("--search", path) for path in self.search)
cmd += self._get_usb_path_cmd()
for mconfig in managed_configs:
cmd.append("--file")
cmd.append(mconfig.get_remote_path())
cmd += chain.from_iterable(("--command", "'{}'".format(command)) for command in commands)
processwrapper.check_output(cmd)
def __call__(self, *args):
processwrapper.check_output(self._get_fastboot_prefix() + list(args))