kepconfig.utils
utils provides general utilities to help manage
various objects for Kepware's configuration
1# ------------------------------------------------------------------------- 2# Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved. 3# See License.txt in the project root for 4# license information. 5# -------------------------------------------------------------------------- 6 7r"""`utils` provides general utilities to help manage 8various objects for Kepware's configuration 9""" 10 11from urllib import parse 12 13def path_split(path: str): 14 '''Used to split the standard Kepware address decimal notation into a dict that contains the 15 *channel*, *device* and *tag_path* keys. 16 17 :param path: standard Kepware address in decimal notation ("ch1.dev1.tg1.tg2.tg3") 18 :return: dict that contains the "channel", "device" and "tag_path" 19 :rtype: dict 20 21 Ex: path = "ch1.dev1.tg1.tg2.tg3" 22 23 return = {'channel': 'ch1', 'device': 'dev1', 'tag_path': ['tg1','tg2','tg3']} 24 25 Ex: path = "ch1.dev1" 26 27 return = {'channel': 'ch1', 'device': 'dev1'} 28 ''' 29 path_list = path.split('.', 2) 30 path_obj = {} 31 for x in range(0, len(path_list)): 32 if x == 0: 33 path_obj['channel'] = path_list[0] 34 elif x == 1: 35 path_obj['device'] = path_list[1] 36 else: 37 path_obj['tag_path'] = path_list[2].split('.') 38 return path_obj 39 40def _address_dedecimal(tag_address): 41 '''Used to handle URL references where decimal notation isn't supported in object names, i.e. IoT Gateway items. 42 43 Replaces `.` with `_` and removes leading `_` for system tag references''' 44 if tag_address[0] == '_': 45 tag_address = tag_address[1::] 46 updated = tag_address.replace('.','_') 47 return updated 48 49def _url_parse_object(object): 50 '''Common url parse to handle reserved characters. Used to convert object 51 names when building URLs. 52 53 Reserved character list that Kepware allows in object names: :/?#[]@!$&'()*+,;=''' 54 return parse.quote(object, safe='')
def
path_split(path: str):
14def path_split(path: str): 15 '''Used to split the standard Kepware address decimal notation into a dict that contains the 16 *channel*, *device* and *tag_path* keys. 17 18 :param path: standard Kepware address in decimal notation ("ch1.dev1.tg1.tg2.tg3") 19 :return: dict that contains the "channel", "device" and "tag_path" 20 :rtype: dict 21 22 Ex: path = "ch1.dev1.tg1.tg2.tg3" 23 24 return = {'channel': 'ch1', 'device': 'dev1', 'tag_path': ['tg1','tg2','tg3']} 25 26 Ex: path = "ch1.dev1" 27 28 return = {'channel': 'ch1', 'device': 'dev1'} 29 ''' 30 path_list = path.split('.', 2) 31 path_obj = {} 32 for x in range(0, len(path_list)): 33 if x == 0: 34 path_obj['channel'] = path_list[0] 35 elif x == 1: 36 path_obj['device'] = path_list[1] 37 else: 38 path_obj['tag_path'] = path_list[2].split('.') 39 return path_obj
Used to split the standard Kepware address decimal notation into a dict that contains the channel, device and tag_path keys.
Parameters
- path: standard Kepware address in decimal notation ("ch1.dev1.tg1.tg2.tg3")
Returns
dict that contains the "channel", "device" and "tag_path"
Ex: path = "ch1.dev1.tg1.tg2.tg3"
return = {'channel': 'ch1', 'device': 'dev1', 'tag_path': ['tg1','tg2','tg3']}
Ex: path = "ch1.dev1"
return = {'channel': 'ch1', 'device': 'dev1'}