Esempio n. 1
0
def _pc_dm_url(elem, **kwargs):
    for e in elem.findall(utils.ns_escape("accessDevice")):
        if e.find(utils.ns_escape("deviceType")).text == \
                kwargs.get("deviceType", "Business Communicator - PC"):
            return [
                e.find(utils.ns_escape(x)).text for x in [
                    "deviceTypeUrl", "deviceUserNamePassword/userName",
                    "deviceUserNamePassword/password"
                ]
            ]
    assert False, "Unable to find device URL and credentials in profile XML"
Esempio n. 2
0
def get_dm_config_value(user, key, prop="dm_config"):
    """Get specified value in user's DM config.

    *Note*: The value is returned from the in-memory configuration
    tree. This is *not* equal to the configuration on target if
    there is pending changes that has not been deployed using
    \`Deploy dm changes\`."""

    tree = utils.account_for_user(user)[prop]
    items = key.split("/")
    if items[-1].startswith("@"):
        pval = items[-1][1:]
        return tree.find(utils.ns_escape("/".join(items[:-1]))).attrib[pval]
    else:
        return tree.find(utils.ns_escape(key)).text
Esempio n. 3
0
def _update_simultaneous_ring(tree_, state):
    tree = copy.deepcopy(tree_)
    if 'active' in state:
        tree.xpath("//*[local-name() = 'active']")[0].text = utils.bool_to_str(
            state['active'])
    if 'incomingCalls' in state:
        text = "Ring for all Incoming Calls"
        if state['incomingCalls']:
            text = "Do not Ring if on a Call"
        tree.xpath("//*[local-name() = 'incomingCalls']")[0].text = text
    if 'simRingLocations' not in state:  # Do not modify locations
        return tree
    e = tree.find(utils.ns_escape('simRingLocations'))
    if e is None and state['simRingLocations'] == []:
        return tree
    if e is None:
        e = utils.element('simRingLocations')
        tree.getroot().insert(2, e)
    e.clear()
    if state['simRingLocations'] == []:  # Delete locations
        e.attrib["{http://www.w3.org/2001/XMLSchema-instance}nil"] = "true"
        return tree
    for loc in state['simRingLocations']:
        e.append(_location(loc))
    return tree
Esempio n. 4
0
 def remove_broadworks_anywhere(self):
     """Set Click-To-Dial flag to False and delete all locations.
     """
     tree = copy.deepcopy(self.xsi_get("services/broadworksanywhere"))
     e = tree.find(utils.ns_escape("locations"))
     if e is not None:
         for phone in tree.findall(
                 utils.ns_escape("locations/location"
                                 "/phoneNumber")):
             self.delete_broadworks_anywhere_location(phone.text)
         # Remove locations to be able to set click-to-dial flag to false.
         # Xsi PUT requirement "phoneNumber element must include the
         # country code element."
         e.getparent().remove(e)
     tree.xpath("//*[local-name() = 'alertAllLocationsForClickToDialCalls']"
                )[0].text = 'false'
     self.xsi_put("services/broadworksanywhere", utils.xml_string(tree))
Esempio n. 5
0
 def get_pn_registrations(self):
     tree = self.xsi_get("profile/PushNotificationRegistrations")
     res = []
     for e in tree.findall(utils.ns_escape("pushNotificationRegistration")):
         item = utils.node_list(e)
         item["token"] = utils.node_value(
             e, "deviceTokenList"
             "/deviceToken/token")
         res.append(item)
     return res
Esempio n. 6
0
def _apply_dm_change(tree, key, value):
    """Apply given change to XML tree

    Our syntax is not actual XPath or compatible with etree's limited
    XPath support. We support:

    1. setting node value with name
       e.g. "a/b/c", "val" (changes text of node 'c')
    2. setting attribute value
       e.g. "a/b/c/@p" "val" (changes param 'p' value of node 'c')
    """
    import lxml.etree as et
    ret = copy.deepcopy(tree)
    items = key.split("/")
    attrib_key = ""
    if items[-1][0] == "@":
        attrib_key = items[-1][1:]
        items.pop(-1)

    node = ret
    while items:
        tmp = node.find(utils.ns_escape(items[0]))
        if tmp is None:
            tmp = et.Element(items[0])
            if isinstance(node, et._ElementTree):
                node.getroot().append(tmp)
            else:
                node.append(tmp)
        node = tmp
        items.pop(0)

    if attrib_key:
        node.attrib[attrib_key] = value
    else:
        ret.find(utils.ns_escape(key)).text = value
    return ret
Esempio n. 7
0
def _update_forward_number(tree_, number_field_name, state):
    tree = copy.deepcopy(tree_)
    tree.xpath("//*[local-name() = 'active']")[0].text = \
        utils.bool_to_str(state["active"])
    e = tree.find(utils.ns_escape(number_field_name))
    if e is None:
        e = tree.getroot().makeelement(number_field_name)
        tree.getroot().insert(1, e)
    e.text = state["number"]
    if not state["number"]:
        # Xsi server requires this twisted way of defining an
        # empty string value
        e.attrib["{http://www.w3.org/2001/XMLSchema-instance}nil"] = "true"
    if "ringSplash" in state:
        tree.xpath("//*[local-name() = 'ringSplash']")[0].text = \
            utils.bool_to_str(state["ringSplash"])
    return tree
Esempio n. 8
0
 def get_simultaneous_ring(self, **kwargs):
     """Get Simultaneous Ring call setting.
     """
     tree = self.xsi_get("services/simultaneousringpersonal")
     active, ring = [
         utils.node_value(tree, x) for x in ("active", "incomingCalls")
     ]
     return {
         "active":
         utils.str_to_bool(active),
         "incomingCalls": (ring == "Do not Ring if on a Call"),
         "simRingLocations":
         map(
             lambda elem: utils.node_list(elem),
             tree.findall(
                 utils.ns_escape("simRingLocations/simRingLocation")))
     }
Esempio n. 9
0
 def get_broadworks_anywhere(self):
     """Get BroadWorks Anywhere call setting.
     """
     tree = self.xsi_get("services/broadworksanywhere")
     dial, paging = [
         utils.node_value(tree, x)
         for x in ("alertAllLocationsForClickToDialCalls",
                   "alertAllLocationsForGroupPagingCalls")
     ]
     return {
         "alertAllLocationsForClickToDialCalls":
         utils.str_to_bool(dial),
         "alertAllLocationsForGroupPagingCalls":
         utils.str_to_bool(paging),
         "locations":
         map(lambda elem: utils.node_list(elem),
             tree.findall(utils.ns_escape("locations/location")))
     }
Esempio n. 10
0
 def delete_pn_registrations(self):
     tree = self.xsi_get("profile/PushNotificationRegistrations")
     for e in tree.findall(utils.ns_escape("pushNotificationRegistration")):
         self.delete_pn_registration(
             utils.node_value(e, "registrationId"),
             utils.node_value(e, "deviceTokenList/deviceToken/token"))