예제 #1
0
파일: device.py 프로젝트: mlyko/tadek-ui
 def _responseSave(self, response, filePath):
     '''
     Expands an accessible tree item from the response recursively.
     '''
     try:
         log.debug("Saving response to file '%s'" % filePath)
         element = response.accessible.marshal()
         utils.saveXml(element, filePath)
         self._view.updateRecentFiles(filePath)
     except:
         dialogs.runError("Error occurred while saving dump to file '%s'"
                          % filePath)
예제 #2
0
 def _responseSave(self, response, filePath):
     '''
     Expands an accessible tree item from the response recursively.
     '''
     try:
         log.debug("Saving response to file '%s'" % filePath)
         element = response.accessible.marshal()
         utils.saveXml(element, filePath)
         self._view.updateRecentFiles(filePath)
     except:
         dialogs.runError("Error occurred while saving dump to file '%s'" %
                          filePath)
예제 #3
0
def performRequest(device, options):
    '''
    Performs a request on the given device using the specified options.

    :param device: A device to perform the request on
    :type device: tadek.connection.device.Device
    :param options: Options representing the request
    :type params: dictionary
    '''
    log.debug("Perform a request on '%s' device using options: %s"
               % (device, options))
    path = accessible.Path(*options.pop("path").split('/')[1:])
    device.connect()
    try:
        if "action" in options:
            status = device.doAccessible(path, options["action"])
        elif "set-text" in options:
            text = options["set-text"]
            status = device.setAccessible(path, text=text)
        elif "set-text-file" in options:
            fn = options["set-text-file"]
            if not os.path.isfile(fn):
                exitWithError("There is no such file: %s" % fn)
            fd = None
            try:
                fd = open(fn)
                text = fd.read()
            finally:
                if fd:
                    fd.close()
            status = device.setAccessible(path, text=text)
        elif "set-value" in options:
            value = float(options["set-value"])
            status = device.setAccessible(path, value=value)
        elif "mouse-click" in options:
            x, y = options["mouse-click"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "CLICK")
        elif "mouse-double-click" in options:
            x, y = options["mouse-double-click"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y),
                                       button, "DOUBLE_CLICK")
        elif "mouse-press" in options:
            x, y = options["mouse-press"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "PRESS")
        elif "mouse-release" in options:
            x, y = options["mouse-release"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "RELEASE")
        elif "mouse-absolute-motion" in options:
            x, y = options["mouse-absolute-motion"]
            status = device.mouseEvent(path, int(x), int(y),
                                       '', "ABSOLUTE_MOTION")
        elif "mouse-relative-motion" in options:
            x, y = options["mouse-relative-motion"]
            status = device.mouseEvent(path, int(x), int(y),
                                       '', "RELATIVE_MOTION")
        elif "key" in options:
            key = options["key"].upper()
            if key in constants.KEY_SYMS:
                key = constants.KEY_SYMS[key]
            elif len(key) == 1:
                key = ord(key)
            elif key.startswith("0X"):
                key = int(key, 16)
            else:
                key = int(key)
            if "modifiers" in options:
                modifiers = [constants.KEY_CODES[mod]
                                    for mod in options["modifiers"]]
            else:
                modifiers = []
            status = device.keyboardEvent(path, key, modifiers)
        elif "dump" in options or "dump-all" in options:
            all = False
            if "dump" in options:
                depth = int(options["dump"])
            else:
                depth = -1
            if "output" in options:
                fn = options["output"]
                all = True
            obj = device.getAccessible(path, depth, all=all)
            if obj is None:
                exitWithStatus("There is no such path: %s" % path, 1)
            if all:
                printSeparator()
                utils.saveXml(obj.marshal(), fn)
                exitWithStatus("Dump saved to file: %s" % fn)
            else:
                printAccessibleTree(obj)
                exitWithStatus()
        else:
            for name in (["all"] + [attr[0] for attr in _ATTRS_EXTRA]):
                if name in options:
                    break
            else:
                exitWithError("Invalid request options: %s" % options)
            obj = device.getAccessible(path, 0, **{name: True})
            if obj is None:
                exitWithStatus("There is no such path: %s" % path, 1)
            printAccessibleDetails(obj, name)
            exitWithStatus()
    finally:
        if device.isConnected():
            device.disconnect()
    printSeparator()
    if status:
        exitWithStatus("SUCCESS")
    else:
        exitWithStatus("FAILURE", 1)
예제 #4
0
def performRequest(device, options):
    '''
    Performs a request on the given device using the specified options.

    :param device: A device to perform the request on
    :type device: tadek.connection.device.Device
    :param options: Options representing the request
    :type params: dictionary
    '''
    log.debug("Perform a request on '%s' device using options: %s" %
              (device, options))
    path = accessible.Path(*options.pop("path").split('/')[1:])
    device.connect()
    try:
        if "action" in options:
            status = device.doAccessible(path, options["action"])
        elif "set-text" in options:
            text = options["set-text"]
            status = device.setAccessible(path, text=text)
        elif "set-text-file" in options:
            fn = options["set-text-file"]
            if not os.path.isfile(fn):
                exitWithError("There is no such file: %s" % fn)
            fd = None
            try:
                fd = open(fn)
                text = fd.read()
            finally:
                if fd:
                    fd.close()
            status = device.setAccessible(path, text=text)
        elif "set-value" in options:
            value = float(options["set-value"])
            status = device.setAccessible(path, value=value)
        elif "mouse-click" in options:
            x, y = options["mouse-click"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "CLICK")
        elif "mouse-double-click" in options:
            x, y = options["mouse-double-click"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button,
                                       "DOUBLE_CLICK")
        elif "mouse-press" in options:
            x, y = options["mouse-press"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "PRESS")
        elif "mouse-release" in options:
            x, y = options["mouse-release"]
            button = options["button"]
            status = device.mouseEvent(path, int(x), int(y), button, "RELEASE")
        elif "mouse-absolute-motion" in options:
            x, y = options["mouse-absolute-motion"]
            status = device.mouseEvent(path, int(x), int(y), '',
                                       "ABSOLUTE_MOTION")
        elif "mouse-relative-motion" in options:
            x, y = options["mouse-relative-motion"]
            status = device.mouseEvent(path, int(x), int(y), '',
                                       "RELATIVE_MOTION")
        elif "key" in options:
            key = options["key"].upper()
            if key in constants.KEY_SYMS:
                key = constants.KEY_SYMS[key]
            elif len(key) == 1:
                key = ord(key)
            elif key.startswith("0X"):
                key = int(key, 16)
            else:
                key = int(key)
            if "modifiers" in options:
                modifiers = [
                    constants.KEY_CODES[mod] for mod in options["modifiers"]
                ]
            else:
                modifiers = []
            status = device.keyboardEvent(path, key, modifiers)
        elif "dump" in options or "dump-all" in options:
            all = False
            if "dump" in options:
                depth = int(options["dump"])
            else:
                depth = -1
            if "output" in options:
                fn = options["output"]
                all = True
            obj = device.getAccessible(path, depth, all=all)
            if obj is None:
                exitWithStatus("There is no such path: %s" % path, 1)
            if all:
                printSeparator()
                utils.saveXml(obj.marshal(), fn)
                exitWithStatus("Dump saved to file: %s" % fn)
            else:
                printAccessibleTree(obj)
                exitWithStatus()
        else:
            for name in (["all"] + [attr[0] for attr in _ATTRS_EXTRA]):
                if name in options:
                    break
            else:
                exitWithError("Invalid request options: %s" % options)
            obj = device.getAccessible(path, 0, **{name: True})
            if obj is None:
                exitWithStatus("There is no such path: %s" % path, 1)
            printAccessibleDetails(obj, name)
            exitWithStatus()
    finally:
        if device.isConnected():
            device.disconnect()
    printSeparator()
    if status:
        exitWithStatus("SUCCESS")
    else:
        exitWithStatus("FAILURE", 1)
예제 #5
0
 def write(self):
     '''
     Writes the XML element tree to a related file.
     '''
     utils.saveXml(self._root, self.filePath(), xslt=self._xslt)