cdb = cmd(helper) if helper else cmd() data = sync_wait(cdb.execute(executer)) return data def doit(dev, page): f = create_os_file(dev) command = available_commands[page] if page in ('0x02', '0x07'): cfg_data = run_cmd(f, ses_pages.ConfigurationDiagnosticPagesCommand) data = run_cmd(f, command, cfg_data) else: data = run_cmd(f, command) f.close() return data if __name__ == "__main__": if len(sys.argv) != 3: sys.stderr.write("usage: %s device_name ses_command\n" % sys.argv[0]) sys.exit(1) try: if sys.argv[2] not in available_commands: raise ValueError("available commands: %s" % repr(available_commands.keys())) data = doit(sys.argv[1], sys.argv[2]) print(repr(data)) except: print_exc()
class OSFile(object): def __init__(self, fd): self.fd = fd def read(self, size): return os.read(self.fd, size) def write(self, buffer): return os.write(self.fd, buffer) def close(self): os.close(self.fd) f = OSFile(os.open(path, os.O_RDWR)) try: executer = create_platform_command_executer(f) possible_commands = {10: ReadCapacity10Command, 16: ReadCapacity16Command} cdb = possible_commands[cdb_size](logical_block_address=0, pmi=0) data = sync_wait(cdb.execute(executer)) print(repr(data)) f.close() except: print_exc()